Game Development Community

[Resolved] getMeshName not returning real mesh name?

by Ted Southard · in Torque 3D Professional · 11/16/2009 (2:01 am) · 3 replies

So the below is what I have in testing all the potential goodness of the TSShapeConstructor functions and what they can do for me in automating adding LODs after the fact. After reading through the docs, I decided to try my hand at some hand-rolled dump functions (never mind the fact that it's inside the namespace of an object- I'll be happy to correct that once this is resolved):

function BountyAgencyDAE::blah(%this)
{
   for(%i = 0; %i < %this.getNodeCount(); %i++)
   {
      %node = %this.getNodeName(%i);
      echo("node:" SPC %node SPC %this.getNodeChildCount(%node) SPC "children" SPC %this.getObjectCount() SPC "objects");
      for(%j = 0; %j < %this.getNodeChildCount(%node); %j++)
      {
         %this.dNodes(%node, %indent @ "   ");
      }
      for(%k = 0; %k < %this.getObjectCount(); %k++)
      {
         %this.dObjects(%node, %indent @ "   ");
      }
   }
}

function BountyAgencyDAE::dNodes(%this, %node, %indent)
{
   for(%i = 0; %i < %this.getNodeChildCount(%node); %i++)
   {
      %cnode = %this.getNodeChildName(%node, %i);
      echo(%indent @ "node:" SPC %cnode SPC %this.getNodeObjectCount(%node) SPC "objects");
      %this.dObjects(%cnode, %indent @ "   ");
   }
}

function BountyAgencyDAE::dObjects(%this, %node, %indent)
{
   for(%i = 0; %i < %this.getNodeObjectCount(%node); %i++)
   {
      %obj = %this.getObjectName(%i);
      echo(%indent @ "object:" SPC %obj SPC %this.getMeshCount(%obj) SPC "meshes");
      %this.dMeshes(%obj, %indent @ "   ");
   }
}

function BountyAgencyDAE::dMeshes(%this, %obj, %indent)
{
   for(%i = 0; %i < %this.getMeshCount(%obj); %i++)
   {
      %mesh = %this.getMeshName(%obj, %i);
      echo(%indent @ "mesh:" SPC %mesh);
      %mat = %this.getMeshMaterial(%mesh);
      echo(%indent @ "material:" SPC %mat);
      %type = %this.getMeshType(%mesh);
      echo(%indent @ "type:" SPC %type);
   }
}

Now, that works just like it should. The problem is that the data that it's getting for the mesh is jacked up:

node: Cylinder04 0 children 1 objects
   object: Cylinder04 1 meshes
      mesh: Cylinder042 //This is the name returned by %this.getMeshName(%obj, %i) and should be correct
      getMeshMaterial: Could not find mesh 'Cylinder042' //But it's not
      material: 
      getMeshType: Could not find mesh 'Cylinder042' //Still not... but returns a type anyway?
      type: normal

Some observations I made are that while you can call setMeshSize(), you don't have the ability to call getMeshSize(), which would allow you to get around this by stripping the number from the end of the name automatically. But it doesn't end there... I get the same output if hardcoding "Cylinder", "Cylinder0", "Cylinder2", and "Cylinder4" as the mesh name. So, something is fouled up here...

#1
11/16/2009 (5:35 am)
Hi Ted,

A mesh name consists of the object name (Cylinder04) followed by a number (the detail size), 2 in this case. The problem here is that the object name also ends in a number, so when you pass Cylinder042 to getMeshMaterial, it interprets that as the object 'Cylinder' with size '042'.

The bug is that getMeshName should insert a space between the two values to give 'Cylinder04 2', which should be correctly parsed by getMeshMaterial and getMeshType. You can fix this in script (use the object name to find where to put the space), or even easier by modifying the TSShapeConstructor getMeshName ConsoleMethod in tsShapeConstruct.cpp.
#2
11/16/2009 (7:23 am)
This is one of the reasons why delimited strings should be avoided where possible. Is there a reason why the detail size and the mesh name have to be in the same string?
#3
11/16/2009 (11:43 am)
@Chris: Yep, that was it. Thanks!

I changed the dMeshes() function (if anyone is interested):

function BountyAgencyDAE::dMeshes(%this, %obj, %indent)
{
   for(%i = 0; %i < %this.getMeshCount(%obj); %i++)
   {
      %mesh = %this.getMeshName(%obj, %i);
      %mn = strreplace(%mesh, %obj, %obj @ " "); //Actual name
      echo(%indent @ "mesh:" SPC %mn);
      %mat = %this.getMeshMaterial(%mn);
      echo(%indent @ "material:" SPC %mat);
      %type = %this.getMeshType(%mn);
      echo(%indent @ "type:" SPC %type);
   }
}

Which results in:

node: Cylinder04 0 children 1 objects
   object: Cylinder04 1 meshes
      mesh: Cylinder04 128
      material: orig_orig_03___Default
      type: normal

And as a bonus, here's a getMeshDetail() in script that simply rips the object name out of the mesh name and returns the trailing detail number:

function getMeshDetail (%obj, %mesh)
{
   return strreplace(%mesh, %obj, "");  
}

I'm changing the subject to [Resolved]