Draw Primitive From Script
by William Gooding · in Torque 3D Professional · 11/19/2009 (10:43 pm) · 18 replies
Hello Everyone:
I am trying to draw a line or a cube from script. For that, I am trying to use the following line in my function:
located in EditTsCtrl.cpp.
However when I execute it, I get the following message:
If I am missing the handle for the EditTsCtrl object, how can I get it?
I am trying to draw a line or a cube from script. For that, I am trying to use the following line in my function:
EditTSCtrl.renderLine(%start, %end, 8);
located in EditTsCtrl.cpp.
However when I execute it, I get the following message:
tools/XEditor/XEditorGui.cs (267): Unable to find object: 'EditTSCtrl' attempting to call function 'renderLine'
If I am missing the handle for the EditTsCtrl object, how can I get it?
#2
11/19/2009 (11:50 pm)
Edited. NA.
#3
Thank you for your help. I can enter now into the function. However, when I try to call the method from the console or my function while on World Editor, nothing happens.
Inside editTSCtrl, the system exits at the first test:
Does that means I need to call the function only at certain points of the code or certain call-backs?
11/20/2009 (9:16 pm)
Hello Ryan:Thank you for your help. I can enter now into the function. However, when I try to call the method from the console or my function while on World Editor, nothing happens.
Inside editTSCtrl, the system exits at the first test:
if(!object->mConsoleRendering)
return;Does that means I need to call the function only at certain points of the code or certain call-backs?
#4
I'll try to take a look at it next time I've visual studio open.
11/21/2009 (12:31 am)
I didn't really look at the code... looks like it won't draw the line if the console is open. So instead of typing the command into the console, you could just create a script function that calls your "EWorldEditor.renderLine(...)" and bind that function to a keyboard key. That way you can execute it without the console open.I'll try to take a look at it next time I've visual studio open.
#5
I am trying to call it from a function as well. The problem is that the variable mConsoleRendering in EWorldEditor is False. If I comment out that piece of code, the line is still not drawn
Edit: I don`t understand when that variable becomes true
11/21/2009 (12:37 am)
Hello Ryan:I am trying to call it from a function as well. The problem is that the variable mConsoleRendering in EWorldEditor is False. If I comment out that piece of code, the line is still not drawn
Edit: I don`t understand when that variable becomes true
#6
I found that the only time it gets called is when the function EditTSCtrl::renderWorld is called (in code). That function iterates through all the Simsets that belongs to "MissionGroup" and from there it calls all objects "onEditorRender" function (in scripts).
Now I have to figure out if I can create a Simset from script and add my primitives from that function......
11/21/2009 (1:13 am)
Hello:I found that the only time it gets called is when the function EditTSCtrl::renderWorld is called (in code). That function iterates through all the Simsets that belongs to "MissionGroup" and from there it calls all objects "onEditorRender" function (in scripts).
Now I have to figure out if I can create a Simset from script and add my primitives from that function......
#7
The "renderLine()" consolemethod isn't real useful since you can't set the linewidth from script. What exactly are you trying to do? I don't want to send you down a dead end road here.
11/21/2009 (11:45 am)
Yeah, you're right. The EditTSCtrl rendering consolemethods will only work in an object's "onEditorRender()" function. If you want to see how it works, you can create a SimObject like this and it will render a 1x1x1 red box at the origin:new SimObject(myTestCube)
{
parentGroup = "MissionGroup";
};
function myTestCube::onEditorRender( %this, %editor, %selected, %expanded )
{
%editor.consoleFillColor = "255 0 0 255";
%editor.renderBox( "0 0 0", "1 1 1" );
}The "renderLine()" consolemethod isn't real useful since you can't set the linewidth from script. What exactly are you trying to do? I don't want to send you down a dead end road here.
#8
Thank you again for your help. At this point, I am looking in doing some quick prototyping some ideas before starting to develop C++ classes. I am interested in drawing grid planes that can be re-sized, relocated and reoriented across all axis. Also, I am interested in using this as a quick debugging access point to visualize such things as collisions, intersections, and visibilities between objects
11/21/2009 (7:15 pm)
Hello Ryan:Thank you again for your help. At this point, I am looking in doing some quick prototyping some ideas before starting to develop C++ classes. I am interested in drawing grid planes that can be re-sized, relocated and reoriented across all axis. Also, I am interested in using this as a quick debugging access point to visualize such things as collisions, intersections, and visibilities between objects
#9
11/21/2009 (11:23 pm)
Take a look at DrawUtil.h, it has some goodies for you to play with. Also the DebugDraw class was useful for this sortof thing but is, uh, depreciated / broken in T3D. You might look at it as another reference though.
#10
The console functions from EditTSCtrl rely on gfxDrawUtil methods. My problem now is when I implement Ryan snippet, myTestCube SimSet is not linked to "MissionGroup", parentGroup stays in "RootGroup" and no matter what I do, I can't seem to change it (I even created a new SimGroup without success). When I go to the world editor, this SimObject is not shown in the tree.
Is there a way to link a script created SimObject to the mission tree (MissionGroup)? or is there another point in code where I can call the primitive render image besides "onEditorRender"?
11/21/2009 (11:52 pm)
Hello James:The console functions from EditTSCtrl rely on gfxDrawUtil methods. My problem now is when I implement Ryan snippet, myTestCube SimSet is not linked to "MissionGroup", parentGroup stays in "RootGroup" and no matter what I do, I can't seem to change it (I even created a new SimGroup without success). When I go to the world editor, this SimObject is not shown in the tree.
Is there a way to link a script created SimObject to the mission tree (MissionGroup)? or is there another point in code where I can call the primitive render image besides "onEditorRender"?
#11
If you mean another place in script, not that I am aware off, but maybe. If you mean in code ( c++ ) you could do it in the EditTSCtrl where it performs the onEditorRender callback, or well, many places depending on who needs to make use of it.
11/22/2009 (4:15 pm)
You can create a SimGroup from the WorldEditor via the "new group" button above the scene tree then save your level.If you mean another place in script, not that I am aware off, but maybe. If you mean in code ( c++ ) you could do it in the EditTSCtrl where it performs the onEditorRender callback, or well, many places depending on who needs to make use of it.
#12
That's odd... are you not seeing the red cube? When I exec() the above code snippet, I see the red cube in the world editor and if I do a "myTestCube.dump()" in the console I can see that it's parentGroup is MissionGroup. For some reason it doesn't show up in the Inspector scene tree immediately, but if I click somewhere in the scene tree it updates and the new simobject appears in the list. You can add it to the MissionGroup after it has been created with "MissionGroup.add(myTestCube)".
11/22/2009 (11:36 pm)
William,That's odd... are you not seeing the red cube? When I exec() the above code snippet, I see the red cube in the world editor and if I do a "myTestCube.dump()" in the console I can see that it's parentGroup is MissionGroup. For some reason it doesn't show up in the Inspector scene tree immediately, but if I click somewhere in the scene tree it updates and the new simobject appears in the list. You can add it to the MissionGroup after it has been created with "MissionGroup.add(myTestCube)".
#13
No, I am not able to force parenGroup to be "MissionGroup" in the test cube. It stays at "RootGroup" no matter what I do. I moved my code from version 1.0.1 to 1.1.a and I still have the same issue. I am going to study how the code in the object editor adds a new SIMGroup to MissionGroup and see if something else is missing from my side...
I was able to visualize the cube duplicating the block of code that looks for "MissionGroup" to "RootGroup" in EditTSCtrl::renderWorld, which concerns me, because I am looking at creating a few categories and attaching them to the Mission (like spawnsphere SimGroup...)
11/23/2009 (12:33 pm)
Hello Ryan:No, I am not able to force parenGroup to be "MissionGroup" in the test cube. It stays at "RootGroup" no matter what I do. I moved my code from version 1.0.1 to 1.1.a and I still have the same issue. I am going to study how the code in the object editor adds a new SIMGroup to MissionGroup and see if something else is missing from my side...
I was able to visualize the cube duplicating the block of code that looks for "MissionGroup" to "RootGroup" in EditTSCtrl::renderWorld, which concerns me, because I am looking at creating a few categories and attaching them to the Mission (like spawnsphere SimGroup...)
#14
11/23/2009 (12:44 pm)
At what point are you creating the object? Are you creating it before a level is loaded? Because MissionGroup does not exist until that point. Also if you are testing this in multiplayer I assume it won't work because the editor rendering callbacks assume a localhost situation for editing.
#15
I am creating that code provisionally on "editorRender.ed.cs" (just where all the other of "onEditorRender" functions are implemented). When I trace the program, I can see the object being created (with the "RootGroup")and I can make a dump() and see its fields and values. Since this file is inside the World Editor folder, I am assuming is executed only when I hit F11.....
11/23/2009 (1:16 pm)
Hello James:I am creating that code provisionally on "editorRender.ed.cs" (just where all the other of "onEditorRender" functions are implemented). When I trace the program, I can see the object being created (with the "RootGroup")and I can make a dump() and see its fields and values. Since this file is inside the World Editor folder, I am assuming is executed only when I hit F11.....
#16
11/23/2009 (1:40 pm)
It is fine to define the callback there but don't create the object there. Please try what I suggested earlier, add a SimGroup to your level from the WorldEditor, give it the name myTestCube or whatever namespace you defined your callback within, and save your level. I cannot think of any way this would not work.
#18
By the way, it also works when I go to the world editor and create the group manually from there...
11/25/2009 (12:12 am)
I finally managed to create the object from script. I had to basically call the script creating the SImObject after the mission was loaded (after stage 2), since before that, "MisssionGroup" still doesn't exist.....By the way, it also works when I go to the world editor and create the group manually from there...
Torque Owner Ryan Mounts
CornerstoneViz