p.vaz Posted August 5, 2015 Share Posted August 5, 2015 Hi, I would like to create a node hierarchy in a script and add it to the editor. I've made a simple project to test that, with a simple body, a static graphic mesh (child of the body) and a convex shape from the mesh. But when I create the nodes in the script, the mesh appears in the editor's view before i had it to the editor. Here is my code from unigine_project.cpp (the zip of the project is in the attached file also). #include <core/unigine.h> int init() { // load editor if (!engine.editor.isLoaded()) { engine.console.run("editor_load"); } PlayerSpectator camera = new PlayerSpectator(); camera.setPosition(Vec3(2.0f,0.0f,1.5f)); camera.setDirection(Vec3(-1.0f,0.0f,-0.5f)); engine.game.setPlayer(camera); ///////////////////////////////////////// // create node hierarchy in the script ///////////////////////////////////////// ObjectDummy m_rootNode = class_remove(new ObjectDummy()); m_rootNode.setName("ROOT"); //m_rootNode.setEnabled(0); // create body and convex shape Body body = class_remove(new BodyRigid()); m_rootNode.setBody(body); ObjectMeshStatic objMesh = class_remove(new ObjectMeshStatic("chassis.mesh", 0)); ShapeConvex shapeConvex = class_remove(new ShapeConvex()); shapeConvex.setObject(objMesh, -1, 0.125); shapeConvex.setBody(body); shapeConvex.setName("shape convex"); // graphic mesh objMesh.setName("mesh"); objMesh.setMaterial("mesh_base","*"); objMesh.setProperty("surface_base","*"); objMesh.setCollider(0); // add child to the root node m_rootNode.addChild(objMesh); // Question : Why at this point we can see the mesh in the scene ? // Question : Why when I click on it in the editor I get the error : ObjectDummy 000000000CFE8D00 external (115:0:0) is not an editor node // add the node to editor //engine.editor.addNode(m_rootNode); return 1; } int shutdown() { return 1; } int update() { return 1; } - Why can we see the mesh in the editor's view before adding it to the editor ? - Have I made something wrong in the construction ? - I've seen in a post that if I disable the node in the script, ( cf line //m_rootNode.setEnabled(0) ) it makes the mesh disappeared. Is this the solution or only a trick ? Thanks in advance, Philippe unigine_project.zip Link to comment
maxi Posted August 5, 2015 Share Posted August 5, 2015 Hi Philippe, When you create visual object, it appears on scene, no matter who is owner. So yes, its a normal solution to call setEnable(0). Adding node to editor makes it editable in editor (click on it etc.). Link to comment
p.vaz Posted August 5, 2015 Author Share Posted August 5, 2015 Thanks for the reply ! Link to comment
Recommended Posts