Finding and texturing "parts" of a mesh?

Blitz3D Forums/Blitz3D Beginners Area/Finding and texturing "parts" of a mesh?

Cubed Inc.(Posted 2010) [#1]
I already posted a topic kind of like this, but I stated it completely wrong.

I'm working on this game, and I'm trying to add character costumization into it. It's a lego game(the lego brand is in copyright of the Lego Company) so there won't be any seperate clothing meshes added to the already naked mesh.

Instead, i'm trying to make it so that you can change the texture of the lego person's head, torso, arms, legs and hands. In order to do this, I need to learn how to pick out the parts of the one whole naked mesh, such as the head or the torso, so you can change the texture of each part of the mesh indivisualy.

Can someone teach me how to do this?


GNS(Posted 2010) [#2]
Load your mesh with LoadAnimMesh(). You can then use FindChild() and GetChild() to grab specific parts of the mesh. You can then apply different textures/brushes to the specific parts via whatever command is appropriate for you (PaintMesh, PaintSurface, EntityTexture, etc. etc.).

As an example, let's say I had a player model. In my modelling program I name each section of the body (i.e. the verts/faces that make up the head will be named "Head", the verts/faces that make up the torso are named "Torso" and so on). In Blitz, I can then load this mesh via something like:
myMesh = LoadAnimMesh("myPlayerMesh.b3d")


Now let's say I wanted to grab the torso section, I could do:
meshTorso = FindChild(myMesh, "Torso")


And to texture just the torso, I might do something like:
PaintMesh(meshTorso, torsoTexture)


I'm not exactly in 'Blitz' mode right now (I'm kneck deep in TGE's ridiculous C++ codebase) but hopefully that'll give you a headstart.


Cubed Inc.(Posted 2010) [#3]
GNS
I tried doing that but it doesn't work. Whenever I try, it says that the entity doesn't exist.


dawlane(Posted 2010) [#4]
Is the model constructed by using multiple mesh's or is it just a single mesh? If it's the latter then I would look at the commands that deal with surfaces.


Cubed Inc.(Posted 2010) [#5]
dawlane
The model is constructed of multiple mesh's. I forgot to mention that -_-

Can someone teach me more of surfaces and how to use them to achieve my goal?


GNS(Posted 2010) [#6]
What's printed to the debuglog if you use this:

For i = 1 To CountChildren(YOUR_MESH)
   DebugLog(EntityName$(GetChild(YOUR_MESH, i))
Next


Be sure to change YOUR_MESH to the entity handle of the mesh you loaded via LoadAnimMesh().

The above code should print the names of all of the submeshes in your mesh to the debug log.


_PJ_(Posted 2010) [#7]
It might be REALLY helpful if TAGames posted his attempted code here too, so we could better see whereabouts it's going wrong. For example:


I tried doing that but it doesn't work. Whenever I try, it says that the entity doesn't exist.


Sounds like you possibly didn't change the example handle names given by GNS.
__________________________________________________________________

If your character model is indeed separate Meshes, then I think it may be likely each has its own surface, in which case, you ought to be able to texture each individually.


________________________________________________________


GNS' debuglog code (PROVIDED YOU REMEMBER TO CHANGE THE HANDLE) should identify the child mesh names perfectly for you.


Cubed Inc.(Posted 2010) [#8]
Malice
I did what GNS said and then I checked the debuglog and it said it only showed the root_joint bone of the animated mesh(which was animated with pacemaker)

I then tried it using a mesh that had no bones or animations, and after checking, none of the submeshes were shown.

I created the 3d model in Milkshape 3d 1.8.5

Does the 3d modeller or animation program have anything to do with it?


_PJ_(Posted 2010) [#9]
Then that sounds like it's all one mesh, then - Which I think means you ought to consider a multi-surface approach. This would involve knowing the specific triangles & verts for each part of the mesh and how to orient the UV values... Not something I am at all competent with I'm afraid.

Presumably Milkshape will dfefault its own 'names' for the bones etc. But also, the format will make a difference to waht data is actually exported, and then, I think there's some issue of what information is actually retained by B3D on Loading a mesh of particular formats.

I don't know enough of these details, but I'm confident someone on these forums can give you more advice.


Matty(Posted 2010) [#10]
You may need to use recursion as the root bone you are finding probably has children of its own, as does the one beneath that...


GNS(Posted 2010) [#11]
Yep, Matty may be right about that one. It comes down to how you have your model setup in the 3D package and how the exporter handles it.

There's some code in the Code Archives to recursively find children in anim meshes. I can't remember exactly where it is, though.


_PJ_(Posted 2010) [#12]
Function DebugNameChildren(Ent)
DebugLog(EntityName$(Ent))
n=CountChildren(Ent)
If (n)
For i = 1 To n
   DebugNameChildren(GetChild(Ent,i))
Next
End If



Cubed Inc.(Posted 2010) [#13]
Matty
Could you tell me more of "using recursion". I've never heard of it, and from what other users say abdout your idea, it just might be the solution.


Matty(Posted 2010) [#14]
Malice's example demonstrates it (post above yours).


Ross C(Posted 2010) [#15]
Welcome back, rez. It sounds like you only have a single mesh. You tried to export in another format?


Cubed Inc.(Posted 2010) [#16]
Ross C
whos rez? I modelled the single mesh in milkshape, and have never really tried exporting meshes using anything other than b3d.


Ross C(Posted 2010) [#17]
Ah , apologies then. You reminded me of a former member of the community a little :)


K(Posted 2010) [#18]
I would recommend "PaintSurface(GetSurface())" to grab different surfaces or materials of a mesh, but only works when the mesh is UV Mapped,otherwise it might just go snow-white.


jhocking(Posted 2010) [#19]
You can put different materials on different parts of the model in Milkshape, but I don't know how Pacemaker handles the materials.

I'm not sure I would recommend separate materials for each part of the model though, since you describe customizing pretty much every body part. Having that many separate surfaces would be pretty inefficient for rendering, where you want to minimize how many separate materials are being pushed to the videocard (ie. share materials on as many polygons in the scene as possible.)

I think a better approach in this situation would be to actually modify the texture images on the fly. Yes modifying the texture could be expensive, but that hit only happens once (if it's a character creation section, who cares if it takes half a second to update) and after that it's considerably more efficient than a bunch of separate materials because, well, it's just one material.

Basically use commands like ImageBuffer and DrawImageRect to mix and match pieces of different textures into a single image. Like, you could grab the hand from one texture and the head from another and draw them into a new image that's applied to the model. If you do that, then the main tricky bit is making sure you lay out the UVs so that each body part is in a separate rectangular section for easy copying.

Last edited 2010


Yue(Posted 2010) [#20]
The problem is that MilkShape export the model without its hierarchy of groups, for that reason gives the error to find the feature with the command FindChild, if you want to recover those parts change their model was for this reason that I go to 3d max to export to b3d and retrieve parts findchild ...


jhocking(Posted 2010) [#21]
Now I'm thinking of whipping up a demo of what I described. I've never actually done that before, I just came up with that method.