unable to mount a weapon properly with a new model [resolved]
by Jeff Yaskus · in Artist Corner · 11/26/2011 (1:00 am) · 15 replies
[edit] resolved - issue was due to badly exported model missing LODs. luckily, a collada version was included in the source. And was able manually import/export to a new DTS model.
I'm trying to get some art working that I purchased online (ninja girl, dexsoft) ... and having some difficulty, as its beyond my artistic skills.
To start, the model didn't have a mount0 node - so I tried to get the engine model editor to add one. I mount the image of the katana using the editor and rotated it to look properly seated in the models hands.
It added this code to the datablock ninja.cs file;
problem is, when I mount up the Katana weapon ... its rotated differently and not as when I mounted it directly (as an image I guess).
So I guess I need to know how to tweak the weapon itself, so it mounts in proper position / rotation.
How would I do that ? what values control it ?
EDIT: Got the Katana mounting properly, by tweaking it using the model editor in engine. However, anything else mounted in mount0 is reversed ... pointing backwards towards player not away.
Do i need to make another mount point in same location and tweak as well ? or can it be setup on the gun model (image) somehow?
been going at this all day now ...
- - - - -
Also, having trouble trying to HIDE some its meshes that are built in.
Tried using this approach, but not its not working ... not sure it can be done on datablock level.
That doesn't work -- but can it be added on server side somehow ?
Like in scripts/server/player.cs ... its didn't seem to work as above.
I'm trying to get some art working that I purchased online (ninja girl, dexsoft) ... and having some difficulty, as its beyond my artistic skills.
To start, the model didn't have a mount0 node - so I tried to get the engine model editor to add one. I mount the image of the katana using the editor and rotated it to look properly seated in the models hands.
It added this code to the datablock ninja.cs file;
function NinjaDts::onLoad(%this)
{
%this.addNode("mount0", "Bip_R_Hand", "0.104227 0.0191064 1.17136 -0.0018384 0.265279 0.96417 3.67292", "1");
%this.addNode("eye", "Bip_Spine", "0.028035 -0.030355 1.93852 0.0684762 -0.991649 -0.109284 1.66383", "1");
%this.setNodeTransform("Bip_R_Forearm", "0.195591 -0.264311 1.28536 0.722524 -0.678736 0.131442 2.53117", "1")problem is, when I mount up the Katana weapon ... its rotated differently and not as when I mounted it directly (as an image I guess).
So I guess I need to know how to tweak the weapon itself, so it mounts in proper position / rotation.
How would I do that ? what values control it ?
EDIT: Got the Katana mounting properly, by tweaking it using the model editor in engine. However, anything else mounted in mount0 is reversed ... pointing backwards towards player not away.
Do i need to make another mount point in same location and tweak as well ? or can it be setup on the gun model (image) somehow?
been going at this all day now ...
- - - - -
Also, having trouble trying to HIDE some its meshes that are built in.
Tried using this approach, but not its not working ... not sure it can be done on datablock level.
function ninjaPlayerData::onAdd(%this, %obj)
{
%obj.setMeshHidden("Accessories", true); // will hide this
%obj.setMeshHidden("Katana_back", true); // will hide this
%obj.setMeshHidden("Mask", true); // will hide this
}That doesn't work -- but can it be added on server side somehow ?
Like in scripts/server/player.cs ... its didn't seem to work as above.
About the author
Long time gamer, hacker and programmer. With dreams of making video games -
#2
player.cs
after line 44, I inserted this as line 45:
When I enter the mission, and look in 3rd Person!!! I see this:

In this image; you can NOT see the body mesh of the soldier, but do see the gun he is holding and the 'dazzle' geometry just inside the tire...kinda glowy.
There are 2 functions: onLoad in TSShapeConstructor that assembles the shapes for memory loading, and then the onAdd associated with the nameSpace.
Hope this helps demonstrate that the functionality is indeed in stock T3D!!
NB: you may not be getting the 'correct' mesh name[especially if using DAE] or your onAdd function is in the wrong nameSpace.
...you can do some truely amazing things with the new functionality written into the codeBase!! addMesh, etc....
11/28/2011 (3:20 pm)
Okay, I just tried this with vanilla T3D Pro 1.2...it works.player.cs
after line 44, I inserted this as line 45:
%obj.setMeshHidden("soldier_LOD", true);When I enter the mission, and look in 3rd Person!!! I see this:

In this image; you can NOT see the body mesh of the soldier, but do see the gun he is holding and the 'dazzle' geometry just inside the tire...kinda glowy.
There are 2 functions: onLoad in TSShapeConstructor that assembles the shapes for memory loading, and then the onAdd associated with the nameSpace.
Hope this helps demonstrate that the functionality is indeed in stock T3D!!
NB: you may not be getting the 'correct' mesh name[especially if using DAE] or your onAdd function is in the wrong nameSpace.
...you can do some truely amazing things with the new functionality written into the codeBase!! addMesh, etc....
#3
First, I re-opened the model in Meshloop (dtsviewer) and checked the meshes the engine sees the following;
Accessories
Clothes
Eyes
Gun_Holster
Hair
Katana_back
Mask
Skin

... and I run the following, in the player.cs exactly as mentioned above.
no errors, but models appearance doesnt change.

Is it possibly a problem with the model itself, as its custom art - that I'm trying to get working -- do the materials need to be setup in certain way or such ??
11/30/2011 (2:24 pm)
hmm ... I'm doing exactly that and no dice.First, I re-opened the model in Meshloop (dtsviewer) and checked the meshes the engine sees the following;
Accessories
Clothes
Eyes
Gun_Holster
Hair
Katana_back
Mask
Skin

... and I run the following, in the player.cs exactly as mentioned above.
%obj.setMeshHidden("Accessories",true);
%obj.setMeshHidden("Gun_Holster",true);
%obj.setMeshHidden("Katana_back",true);
%obj.setMeshHidden("Mask",true);no errors, but models appearance doesnt change.

Is it possibly a problem with the model itself, as its custom art - that I'm trying to get working -- do the materials need to be setup in certain way or such ??
#4
Can you show more of the datablock? And this is being placed as a 'player' object and not just a MESH item from the Library, IE TSStatic shape..
Nothing special with material setup for setMeshHidden();
11/30/2011 (2:36 pm)
Namespace issue, perhaps? I did my editing to the Armor namespace's onAdd. I see you have a different one, with 'data' on the end?!? If it's a T3D final or 1.2 codebase, mesh hiding should work.Can you show more of the datablock? And this is being placed as a 'player' object and not just a MESH item from the Library, IE TSStatic shape..
Nothing special with material setup for setMeshHidden();
#5
11/30/2011 (2:47 pm)
I added an echo statement, so I know its being "executed" in the Armor:onAdd() ... ==>doAI(); --- Armor::onNewDataBlock() --- Armor::onAdd - hidding meshes --------------------------------------------- spawned AIPlayer #5648 of type ninjaPlayerData
#6
Try writing the scripting in the Armor namespace's onAdd. // well that didn't work did it? wrong nameSpace then, lol
I get all confused when I see the word 'Data' tacked onto the end of a datablock name and the 'class' assignment and the 'className' assignment in the same code block.
....that is the only scripting I saw for onAdd...and nothing about setMeshHidden??
...the takeaway; I think this is in the scripting, not the art. It[setMeshHidden();] does work out of box....when called correctly,;)??!
Try adding it in the ninjaPlayerData's onAdd...??? The function needs to be called as the instance of the object is added to the Scene; where ever that occurs in your codeBase. Looks like your scaling is working on that object in the image...this is where to put the mesh hiding then, for the girl ninja asset?!?
11/30/2011 (2:53 pm)
class = "armor"; - - className = Armor;... can you do that? Use same name?
Try writing the scripting in the Armor namespace's onAdd. // well that didn't work did it? wrong nameSpace then, lol
I get all confused when I see the word 'Data' tacked onto the end of a datablock name and the 'class' assignment and the 'className' assignment in the same code block.
function ninjaPlayerData::onAdd(%this, %obj)
{
%obj.scale = %obj.getDatablock().scale;
}....that is the only scripting I saw for onAdd...and nothing about setMeshHidden??
...the takeaway; I think this is in the scripting, not the art. It[setMeshHidden();] does work out of box....when called correctly,;)??!
Try adding it in the ninjaPlayerData's onAdd...??? The function needs to be called as the instance of the object is added to the Scene; where ever that occurs in your codeBase. Looks like your scaling is working on that object in the image...this is where to put the mesh hiding then, for the girl ninja asset?!?
#7
Yep, works, just need to call it on the correct object....doing it from onAdd was my first guess; sorry if I led you to think the function was only executable inside onAdd in the Armor nameSpace...
11/30/2011 (3:26 pm)
Try grabbing the ID of the ninja girl object and try the calling from the console, that should also work. The function setMeshHidden is a shapeBase function...could be called anywhere, anytime, me thinks.Yep, works, just need to call it on the correct object....doing it from onAdd was my first guess; sorry if I led you to think the function was only executable inside onAdd in the Armor nameSpace...
#8
At this point - im sure the command is running. I just created a new test using FPS Example files - without UAISK installed.
Spawned the ninja directly and echo'd the ID ... then went into the console ingame and typed the command directly. It "ran" but again, no visual change.

really makes me wonder if its the model or such.
-- is there a way to "list Mesh(es)" from within script or such - maybe its a name issue like you hinted earlier.
11/30/2011 (6:39 pm)
Rex@ I tried it manually as well as in several other places - no errors or a return code either (scripts often return 1 when you execute them).At this point - im sure the command is running. I just created a new test using FPS Example files - without UAISK installed.
Spawned the ninja directly and echo'd the ID ... then went into the console ingame and typed the command directly. It "ran" but again, no visual change.

really makes me wonder if its the model or such.
-- is there a way to "list Mesh(es)" from within script or such - maybe its a name issue like you hinted earlier.
#9
Try starting very simple, use your own player object as I did earlier. I left the body of my avatar, opened the World Editor, selected my avatar and read the properties. Took the ID number for myself and ran the line of code from the console:
Sorry I can't be of more help!
Opening the DTS in the Shape Editor of the World Editor should give you mesh/'object' names as they appear in the asset. Viewing in Show Tool Pro should give the same data, as well as Konrad's DTSviewer. Never heard of 'MeshLoop' before?
There is a TSShapeConstructor function that does list meshes[tons of functions, read up on it,;)], as well as 'dumping' the shape to the console or a text file would do the same.
Example: from the Torque Scripting Manual CHM
If you run this code in the TSShapeConstructor script for your object, it will print out a list in the log of the meshes. The Shape Editor is merely a shell for all these new functions, giving you buttons to assemble the script, you could also hand write your changes; visually is usually quicker!
12/01/2011 (2:55 am)
HHHmmm....very, very odd. And this is a T3D codeBase, not TGE? Mesh hiding does not work in TGE, out of box.Try starting very simple, use your own player object as I did earlier. I left the body of my avatar, opened the World Editor, selected my avatar and read the properties. Took the ID number for myself and ran the line of code from the console:
myID.setMeshHidden("soldier_LOD",true);. Instantly after hitting Enter, the soldier avatar geometry disappeared as in my snapshot. If you cannot do that, something may be wrong with your codeBase...!! Again, this is out of box functionality, it should work as I described.Sorry I can't be of more help!
Opening the DTS in the Shape Editor of the World Editor should give you mesh/'object' names as they appear in the asset. Viewing in Show Tool Pro should give the same data, as well as Konrad's DTSviewer. Never heard of 'MeshLoop' before?
There is a TSShapeConstructor function that does list meshes[tons of functions, read up on it,;)], as well as 'dumping' the shape to the console or a text file would do the same.
Example: from the Torque Scripting Manual CHM
// print the names of all meshes in the shape
%objCount = %this.getObjectCount();
for ( %i = 0; %i < %objCount; %i++ )
{
%objName = %this.getObjectName( %i );
%meshCount = %this.getMeshCount( %objName );
for ( %j = 0; %j < %meshCount; %j++ )
echo( %this.getMeshName( %objName, %j ) );If you run this code in the TSShapeConstructor script for your object, it will print out a list in the log of the meshes. The Shape Editor is merely a shell for all these new functions, giving you buttons to assemble the script, you could also hand write your changes; visually is usually quicker!
#10
The meshes show up in there OK and in the in-game editor as well.
Here is the output (running debug t3d1.2 exe in fps tutorial) ... for some reason, the onLoad function isn't seeing the meshes properly.
12/01/2011 (9:40 am)
Meshloop is just the new name for Konrad's DTS viewer tool www.bitgap.com/productsThe meshes show up in there OK and in the in-game editor as well.
Here is the output (running debug t3d1.2 exe in fps tutorial) ... for some reason, the onLoad function isn't seeing the meshes properly.
-- Kralmok FP Animations Loaded listing all meshes found in ninja.dts TSShapeConstructor::getMeshCount: Could not find object 'Clothes' TSShapeConstructor::getMeshCount: Could not find object 'Hair' TSShapeConstructor::getMeshCount: Could not find object 'Katana_back' TSShapeConstructor::getMeshCount: Could not find object 'Gun_Holster' TSShapeConstructor::getMeshCount: Could not find object 'Mask' TSShapeConstructor::getMeshCount: Could not find object 'Accessories' TSShapeConstructor::getMeshCount: Could not find object 'Skin' TSShapeConstructor::getMeshCount: Could not find object 'Eyes'
#11
I even tried re exporting the ninja.dts shape[many, many times this morning], got proper detail markers, looked like the solder asset in way of hierachy; it still crashed the engine...so I'm out of ideas. At least you can get your edits to load into memory! With proper detail nodes and markers, setMsshHidden MAY work, not gonna say WILL...but that was my first observation in Shape Editor; no details to the shape, even though I saw them in the Details portion of the dialog. It's why I asked how the DTS was generated. U3D is quite incomplete in it's understanding of the format....Ms3d is much more reliable, due to Chris R.'s coding of the plugin.
Hope things go better, I'm out of ideas...
12/01/2011 (12:52 pm)
Yes, I agree, no detail nodes in your sent shape....so I'm not surprised why nothing 'hid' when that calling went and why they can't be found in the shape.I even tried re exporting the ninja.dts shape[many, many times this morning], got proper detail markers, looked like the solder asset in way of hierachy; it still crashed the engine...so I'm out of ideas. At least you can get your edits to load into memory! With proper detail nodes and markers, setMsshHidden MAY work, not gonna say WILL...but that was my first observation in Shape Editor; no details to the shape, even though I saw them in the Details portion of the dialog. It's why I asked how the DTS was generated. U3D is quite incomplete in it's understanding of the format....Ms3d is much more reliable, due to Chris R.'s coding of the plugin.
Hope things go better, I'm out of ideas...
#12
Once I tried a recently exported copy of ninja.dts, I got mesh hiding to function as I expect. I couldn't get Shape Editor to setup the Detail markers correctly, but I didn't spend a lot of time at that approach, once I found it not quickly working out; I simply re exported the shape, and it processed correctly into a DTS shape. What the heck are you using to export your assets? or this one?
How I got mesh hiding test to work very quickly.
Not wanting to exec scripting to make it an AI or player, I merely replaced the 'healthPatch' art asset with my newly exported ninja.dts in the healtPatch.cs script. This made the shape a 'shapeBase' object right away, once I got it to stop spinning in the world, lol. Once an 'item'[shapeBase object], I could grab it's handle as I explained before and was able to call
All in all, the art is causing most of your recent issues with mesh hiding and saveShape.
Might be a good idea to get a 'meshHiding' DTS working inside the engine but not writing to DTS, with it crashing the engine, and send it to Chris R. or whomever is monitoring the ShapeEditor and DTS reading/writing...
12/01/2011 (1:35 pm)
Yes, went back and did a touch more testing of your original shape. And I see why mesh hiding was not working, it is because your original DTS asset has NO detail nodes at all. The mesh registers it's LOD of 300[or 32, can't figure that out], but there are no detail markers in the object!Once I tried a recently exported copy of ninja.dts, I got mesh hiding to function as I expect. I couldn't get Shape Editor to setup the Detail markers correctly, but I didn't spend a lot of time at that approach, once I found it not quickly working out; I simply re exported the shape, and it processed correctly into a DTS shape. What the heck are you using to export your assets? or this one?
How I got mesh hiding test to work very quickly.
Not wanting to exec scripting to make it an AI or player, I merely replaced the 'healthPatch' art asset with my newly exported ninja.dts in the healtPatch.cs script. This made the shape a 'shapeBase' object right away, once I got it to stop spinning in the world, lol. Once an 'item'[shapeBase object], I could grab it's handle as I explained before and was able to call
myID.setMeshHidden("",true); on it and hide various meshes on the ninja body quite well, on the fly.All in all, the art is causing most of your recent issues with mesh hiding and saveShape.
Might be a good idea to get a 'meshHiding' DTS working inside the engine but not writing to DTS, with it crashing the engine, and send it to Chris R. or whomever is monitoring the ShapeEditor and DTS reading/writing...
#13
Okay, Jeff, I got mesh hiding working on your original DTS binary thru scripting; finally.
I thought it had me beat, I even re exported the shape to 'clean' it up[still very odd binary DTS, must be U3D exported] and got it working then. But it gnawed at me all day that I could not figure this out to get it working 'out of box' with a stock SDK. Here we go.
The original is questionable. Reading some of it's parameters in the Shape Editor showed me a few things.
1. According to the DTS binary you supplied, it has over 400 bones in it!! These don't appear as 'nodes' per se, but in the dialog dealing with Detail level control, it has that value. Something bizarre in the way the binary's matters arrays are filled...
2. Absolutely no detail markers and this is what borked mesh hiding out of the box. So, to a quick and dirty end to 'meshHiding' make sure your constructor looks like this: Beware of code block ahead!
I had to rename the nodes present in the asset to have a "0" appended to their end, and at the same time, had to figgle with the detail numbers to read those nodes, or something 'CODERish'....end result, I got your original binary to mesh hide.
I used my quick and dirty[how I work, quickly...lol], 'shapeBase' checking method of pointing the healthPatch bottle datablock to my newly edited asset. I managed to hide each and every mesh object in the asset, imagine that!
Sorry it stumped me for so long...I couldn't let it rest today until I got it working...give it a go, and report back!
Whew, my fingers are tired....
12/01/2011 (4:50 pm)
AHA!!! Triumph!! HUZZAH!!Okay, Jeff, I got mesh hiding working on your original DTS binary thru scripting; finally.
I thought it had me beat, I even re exported the shape to 'clean' it up[still very odd binary DTS, must be U3D exported] and got it working then. But it gnawed at me all day that I could not figure this out to get it working 'out of box' with a stock SDK. Here we go.
The original is questionable. Reading some of it's parameters in the Shape Editor showed me a few things.
1. According to the DTS binary you supplied, it has over 400 bones in it!! These don't appear as 'nodes' per se, but in the dialog dealing with Detail level control, it has that value. Something bizarre in the way the binary's matters arrays are filled...
2. Absolutely no detail markers and this is what borked mesh hiding out of the box. So, to a quick and dirty end to 'meshHiding' make sure your constructor looks like this: Beware of code block ahead!
I had to rename the nodes present in the asset to have a "0" appended to their end, and at the same time, had to figgle with the detail numbers to read those nodes, or something 'CODERish'....end result, I got your original binary to mesh hide.
I used my quick and dirty[how I work, quickly...lol], 'shapeBase' checking method of pointing the healthPatch bottle datablock to my newly edited asset. I managed to hide each and every mesh object in the asset, imagine that!
Sorry it stumped me for so long...I couldn't let it rest today until I got it working...give it a go, and report back!
Whew, my fingers are tired....
#14
12/01/2011 (4:52 pm)
Here is the code block and how it should look:function NinjaDts::onLoad(%this)
{
%this.renameNode("Clothes", "Clothes0");
%this.renameNode("Hair", "Hair0");
%this.renameNode("Katana_back", "Katana_back0");
%this.renameNode("Gun_Holster", "Gun_Holster0");
%this.renameNode("Mask", "Mask0");
%this.renameNode("Accessories", "Accessories0");
%this.renameNode("Skin", "Skin0");
%this.renameNode("Eyes", "Eyes0");
%this.setDetailLevelSize("32", "0");
%this.addSequence("./ninja_idle.dsq", "root", "0", "-1", "1", "0");
then the rest of the addSequence() functions: edited to fit forum
#15
It then built a LOD level (2) ... and everything worked from there.
The DTS model was supplied by the vendor (dexsoft), looks like last updated in 2010 -- so likely a problem with thier export.
However, now it looks like its 100% solved !!! Yipee! Now, maybe I can sleep tonight and not think about how to fix this more.
... so in short, i learned more about the insides of these models in last 48 hours -- than I have in last (5+) years owning this engine!
12/01/2011 (9:36 pm)
Rex@ thanks so much for all that hard work! Once I realized the DTS model itself was the problem ... I started messing with the source COLLADA models and manually imported it.It then built a LOD level (2) ... and everything worked from there.
The DTS model was supplied by the vendor (dexsoft), looks like last updated in 2010 -- so likely a problem with thier export.
However, now it looks like its 100% solved !!! Yipee! Now, maybe I can sleep tonight and not think about how to fix this more.
... so in short, i learned more about the insides of these models in last 48 hours -- than I have in last (5+) years owning this engine!
Torque Owner Jeff Yaskus
jy games
However, still am unable to get the mesh hiding to work ... wondering if it requires more setup on the model, like materials.cs or such ? Or maybe I need to run the command form a different location to get it to work??
Tried adding it to Player::onNewDatablock() and didn't work either.