Przeglądaj źródła

Fixes using the -i argument in the DAE encoder. -i lets users encode a specific node hierarchy instead of the entire scene.

Darryl Gough 14 lat temu
rodzic
commit
416145dd18

+ 14 - 6
gameplay-encoder/src/DAESceneEncoder.cpp

@@ -272,23 +272,31 @@ void DAESceneEncoder::write(const std::string& filepath, const EncoderArguments&
         {
             if (nodeId == NULL)
             {
-                // If the -n <node_id> parameter was not passed then write out the entire scene.
+                // If the -i <node_id> parameter was not passed then write out the entire scene.
                 begin();
                 loadScene((domVisual_scene*)scene);
                 end("load scene");
             }
             else
             {
-                // Resolve/Search for the node the user specified with the -n <node_id> parameter.
+                // Resolve/Search for the node the user specified with the -i <node_id> parameter.
                 daeSIDResolver resolver(scene, nodeId);
-                const domNode* node = daeSafeCast<domNode>(resolver.getElement());
-                if (node)
+                domNode* nodeElement = daeSafeCast<domNode>(resolver.getElement());
+                if (nodeElement)
                 {
-                    //createNode(node, NULL);
+                    Node* node = loadNode(nodeElement, NULL);
+                    if (node)
+                    {
+                        _gamePlayFile.addScenelessNode(node);
+                    }
+                    else
+                    {
+                        fprintf(stderr,"COLLADA File loaded to the dom, but failed to load node %s.\n", nodeId);
+                    }
                 }
                 else
                 {
-                    fprintf(stderr,"COLLADA File loaded to the dom, but node was not found with -n%s.\n", nodeId);
+                    fprintf(stderr,"COLLADA File loaded to the dom, but node was not found with node ID %s.\n", nodeId);
                 }
             }
         }

+ 1 - 1
gameplay-encoder/src/EncoderArguments.cpp

@@ -141,7 +141,7 @@ void EncoderArguments::printUsage() const
     fprintf(stderr,"  .ttf\t(TrueType Font)\n");
     fprintf(stderr,"\n");
     fprintf(stderr,"COLLADA and FBX file options:\n");
-    fprintf(stderr,"  -i<id>\t\tFilter by node ID.\n");
+    fprintf(stderr,"  -i <id>\t\tFilter by node ID.\n");
     fprintf(stderr,"  -t\t\t\tWrite text/xml.\n");
     fprintf(stderr,"  -groupAnimations <node id> <animation id>\n" \
         "\t\t\tGroup all animation channels targetting the nodes into a new animation.\n");

+ 10 - 0
gameplay-encoder/src/GPBFile.cpp

@@ -115,6 +115,16 @@ void GPBFile::addNode(Node* node)
     _nodes.push_back(node);
 }
 
+void GPBFile::addScenelessNode(Node* node)
+{
+    addToRefTable(node);
+    _nodes.push_back(node);
+    // Nodes are normally written to file as part of a scene. 
+    // Nodes that don't belong to a scene need to be written on their own (outside a scene).
+    // That is why node is added to the list of objects here.
+    _objects.push_back(node);
+}
+
 void GPBFile::addAnimation(Animation* animation)
 {
     _animations.add(animation);

+ 4 - 0
gameplay-encoder/src/GPBFile.h

@@ -65,6 +65,10 @@ public:
     void addLight(Light* light);
     void addMesh(Mesh* mesh);
     void addNode(Node* node);
+    /**
+     * Adds a node that does not belong to a scene.
+     */
+    void addScenelessNode(Node* node);
     void addAnimation(Animation* animation);
 
     /**