@@ -288,8 +288,8 @@ namespace glsample {
288288 NodeData *baseNodeData = this ->stageNodeDataRobin .buffers [getRoundRobinIndex ()];
289289 size_t node_index = 0 ;
290290 auto copyQueue = renderQueue; // TODO: fix performance
291- for (const NodeObject *node : copyQueue) {
292- baseNodeData[node_index++].model = node->modelGlobalTransform ;
291+ for (const Node *node : copyQueue) {
292+ baseNodeData[node_index++].model = node->getGlobalMatrix (); // modelGlobalTransform;
293293 }
294294
295295 /* Update Materials. */
@@ -406,7 +406,7 @@ namespace glsample {
406406 /* */
407407 // TODO: multi thread
408408 const size_t num_threads = 6 ;
409- static std::vector<std::vector<NodeObject *>> objects (num_threads, std::vector<NodeObject *>());
409+ static std::vector<std::vector<Node *>> objects (num_threads, std::vector<Node *>());
410410 for (size_t i = 0 ; i < objects.size (); i++) {
411411 objects[i].clear ();
412412 objects[i].reserve (1024 );
@@ -415,7 +415,7 @@ namespace glsample {
415415#pragma omp parallel for collapse(1) num_threads(num_threads)
416416 for (size_t node_index = 0 ; node_index < this ->getNodes ().size (); node_index++) {
417417
418- NodeObject *node = this ->getNodes ()[node_index];
418+ Node *node = this ->getNodes ()[node_index];
419419
420420 /* Check if any of the meshes are visable. */
421421 for (size_t mesh_index = 0 ; mesh_index < node->geometryObjectIndex .size (); mesh_index++) {
@@ -458,11 +458,11 @@ namespace glsample {
458458 }
459459
460460 for (size_t i = 0 ; i < objects.size (); i++) {
461- visableNodes.insert (visableNodes.end (), objects[i].begin (), objects[i].end ());
461+ this -> visableNodes .insert (this -> visableNodes .end (), objects[i].begin (), objects[i].end ());
462462 }
463463
464464 } else {
465- visableNodes = this ->getNodes ();
465+ this -> visableNodes = this ->getNodes ();
466466 }
467467 }
468468
@@ -516,10 +516,10 @@ namespace glsample {
516516 /* */
517517 for (auto it = order.begin (); it != order.end (); it++) {
518518 // RenderQueue renderQueue = (*it).first;
519- std::deque<const NodeObject *> nodeQueue = this ->renderBucketQueue [(*it)];
519+ std::deque<const Node *> nodeQueue = this ->renderBucketQueue [(*it)];
520520 for (auto itQ = nodeQueue.begin (); itQ != nodeQueue.end (); itQ++) {
521521
522- const NodeObject *node = (*itQ);
522+ const Node *node = (*itQ);
523523 // this->debugDrawer->addAABB(node->bound.aabb, glm::vec4(0.3f, 1.0f 0.3f, 1.0f));
524524 }
525525 }
@@ -596,30 +596,30 @@ namespace glsample {
596596 /* */
597597 for (auto it = order.begin (); it != order.end (); it++) {
598598 // RenderQueue renderQueue = (*it).first;
599- std::deque<const NodeObject *> nodeQueue = this ->renderBucketQueue [(*it)];
599+ std::deque<const Node *> nodeQueue = this ->renderBucketQueue [(*it)];
600600
601601 /* */
602602 const std::string domain = fmt::format (" {}" , (int )(*it));
603603
604604 glPushDebugGroup (GL_DEBUG_SOURCE_APPLICATION, 1 , domain.size (), domain.data ());
605605 for (auto itQ = nodeQueue.begin (); itQ != nodeQueue.end (); itQ++) {
606- const NodeObject *node = (*itQ);
606+ const Node *node = (*itQ);
607607 this ->renderNode (node);
608608 }
609609 glPopDebugGroup ();
610610 }
611611
612612 for (auto it = this ->renderQueue .begin (); it != this ->renderQueue .end (); it++) {
613- const NodeObject *node = (*it);
613+ const Node *node = (*it);
614614 // this->renderNode(node);
615615 }
616616
617617 /* */
618618 if (this ->debugMode & DebugMode::Wireframe) {
619619 /* */
620- for (const NodeObject *node : this ->renderQueue ) {
620+ for (const Node *node : this ->renderQueue ) {
621621 /* */
622- // const NodeObject *node = this->renderQueue[x];
622+ // const Node *node = this->renderQueue[x];
623623 // this->renderNode(node);
624624 }
625625 }
@@ -744,7 +744,7 @@ namespace glsample {
744744 }
745745 }
746746
747- void Scene::renderNode (const NodeObject *node) {
747+ void Scene::renderNode (const Node *node) {
748748
749749 /* Update binding offset. */
750750 if ((currentNodeIndex % this ->UBOStructure .max_node_per_binding ) == 0 ) {
@@ -783,7 +783,8 @@ namespace glsample {
783783 this ->bindMaterial (&material);
784784 }
785785
786- const MeshObject &refMesh = this ->refGeometry [node->geometryObjectIndex [geo_index]];
786+ const int mesh_index = node->geometryObjectIndex [geo_index];
787+ const MeshObject &refMesh = this ->refGeometry [mesh_index];
787788 glBindVertexArray (refMesh.vao );
788789
789790 /* Material, model matrix. */
@@ -808,15 +809,15 @@ namespace glsample {
808809 for (size_t x = 0 ; x < this ->visableNodes .size (); x++) {
809810
810811 /* */
811- const NodeObject *node = this ->visableNodes [x];
812+ const Node *node = this ->visableNodes [x];
812813 if (node->materialIndex .empty ()) {
813814 continue ;
814815 }
815816
816817 /* */
817- const bool validIndex = node->materialIndex [0 ] < this ->materials .size ();
818+ const bool validMaterialIndex = node->materialIndex [0 ] < this ->materials .size ();
818819
819- if (validIndex ) {
820+ if (validMaterialIndex ) {
820821
821822 const MaterialObject *material = &this ->materials [node->materialIndex [0 ]];
822823 assert (material);
@@ -832,7 +833,7 @@ namespace glsample {
832833 }
833834
834835 } else {
835- std::cerr << " Invalid Material " << node->name << std::endl;
836+ std::cerr << " Invalid Material " << node->getName () << std::endl;
836837 }
837838 }
838839
@@ -947,49 +948,38 @@ namespace glsample {
947948
948949 for (size_t node_index = 0 ; node_index < nodes.size (); node_index++) {
949950
951+ Node *currentNode = nodes[node_index];
952+
950953 if (node_index == 0 ) {
951954 ImGui::SetNextItemOpen (true , ImGuiCond_Once);
952955 }
953956
954957 ImGui::PushID (node_index);
955958
956- if (nodes[node_index]-> parent ) {
957- ImGui::TextUnformatted (nodes[node_index]-> parent -> name .c_str ());
959+ if (currentNode-> getParent () ) {
960+ ImGui::TextUnformatted (currentNode-> getParent ()-> ptr ()-> getName () .c_str ());
958961 }
959962
960- ImGui::TextUnformatted (nodes[node_index]->name .c_str ());
961- if (ImGui::DragFloat3 (" Position" , &nodes[node_index]->localPosition [0 ])) {
962- const glm::mat4 globaMat = nodes[node_index]->parent == nullptr
963- ? glm::mat4 (1 )
964- : nodes[node_index]->parent ->modelGlobalTransform ;
965- nodes[node_index]->modelGlobalTransform =
966- glm::translate (globaMat, nodes[node_index]->localPosition );
963+ ImGui::TextUnformatted (currentNode->getName ().c_str ());
964+
965+ glm::vec3 localPosition = currentNode->getLocalPosition ();
966+ if (ImGui::DragFloat3 (" Position" , &localPosition[0 ])) {
967+ currentNode->setLocalPosition (localPosition);
967968 }
968969
969- if (ImGui::DragFloat4 (" Rotation (Quat)" , &nodes[node_index]->localRotation [0 ])) {
970- nodes[node_index]->localRotation = glm::normalize (nodes[node_index]->localRotation );
971- const glm::mat4 globaMat = nodes[node_index]->parent == nullptr
972- ? glm::mat4 (1 )
973- : nodes[node_index]->parent ->modelGlobalTransform ;
974-
975- nodes[node_index]->modelGlobalTransform =
976- glm::translate (globaMat, nodes[node_index]->localPosition ) *
977- glm::mat4_cast (nodes[node_index]->localRotation );
970+ glm::quat quat_local_rotation = currentNode->getLocalRotation ();
971+ if (ImGui::DragFloat4 (" Rotation (Quat)" , &quat_local_rotation[0 ])) {
972+ currentNode->setLocalRotation (quat_local_rotation);
978973 }
979974
980- if (ImGui::DragFloat3 (" Rotation (Eular)" , &nodes[node_index]->localRotation [0 ])) {
975+ glm::vec3 eular_rotation = currentNode->getRotationEular ();
976+ if (ImGui::DragFloat3 (" Rotation (Eular)" , &eular_rotation[0 ])) {
977+ currentNode->setRotationEular (eular_rotation);
981978 }
982979
983- if (ImGui::DragFloat3 (" Scale" , &nodes[node_index]->localScale [0 ])) {
984-
985- const glm::mat4 globaMat = nodes[node_index]->parent == nullptr
986- ? glm::mat4 (1 )
987- : nodes[node_index]->parent ->modelGlobalTransform ;
988-
989- nodes[node_index]->modelGlobalTransform =
990- glm::translate (globaMat, nodes[node_index]->localPosition ) *
991- glm::mat4_cast (nodes[node_index]->localRotation ) *
992- glm::scale (nodes[node_index]->localScale );
980+ glm::vec3 local_scale = currentNode->getLocalScale ();
981+ if (ImGui::DragFloat3 (" Scale" , &local_scale[0 ])) {
982+ currentNode->setLocalScale (local_scale);
993983 }
994984 ImGui::Separator ();
995985
0 commit comments