Bart De Lathouwer pisze:
Hi all,

Howdy Bart.
 
I have some questions while using lib3ds.
 
1) i'm successfull loading a 3ds model and rendering it. But the scene contains calibration meshes, that do not need to be rendered in the final image. I use 
int index = lib3ds_file_mesh_by_name(m_pModel3dsFile, sMeshName);
if (index >= 0)
  
lib3ds_file_remove_mesh(m_pModel3dsFile, index);
to remove the mesh, but i believe this corrupts the model. What is the correct way of removing a mesh (and the nodes - see my question #2)?

Never heard about "calibration meshes" but maybe you are talking about "Dummies". "Dummy" is a node with attached empty mesh, it is used as camera target or part of nodes hierarchy (bone in skeleton) used in animation. If so, then you may easily detect dummy (from "player.c"):

if (node->type==LIB3DS_OBJECT_NODE) {
    if (strcmp(node->name,"$$$DUMMY")==0) {
/* do something */
    }
Then just skip it and don't render. I greatly discourage you to delete such meshes, they may be necessary to proper animation of other objects.

 
2) what is the relation between the mesh and the node? Which is part or relates to what? Can you recommend literature that makes me better understand? (i bought some 3ds max books, but they dont even mention these words). Appologies for this 101 question

Node is base for transformation in 3DS. There is always at least a "Root" node in the scene. Other nodes are attached to Root. Each node may have children nodes, so we can build hierarchy of nodes.

Node_Base -> Node_Middle -> Node_Top

 Most important thing in node is it's transformation matrix, such matrix describes node's transformations relative to it's parent node:
"node->matrix" is actually it's "local_to_parent" transformation, when we want to get "local_to_world" we should do something like this:

/// this is pseudo-code, it may not compile, just explaining concept!

void CalculateNodesLocalToWorldMatrix( Lib3dsNode* node, Lib3dsMatrix& result )
{
    if( !node->parent )
    {
       memcpy( result, node->matrix, sizeof( Lib3dsMatrix ) );
    }
    else
    {
       Lib3dsMatrix parentToWorldMatrix;
        CalculateNodesLocalToWorldMatrix( node->parent, parentToWorldMatrix );
       MultiplyMatrices( node->matrix, parentToWorldMatrix, result );
    }
}

So if we have following hierarchy:

Node_Base -> Node_Middle -> Node_Top

when we move Node_Base's position X by 5 units "Node_Base->matrix[3][0] += 5;", then we will see that all nodes are moved by 5 units in X.
but when we translate Node_Middle by 5 "Node_Middle->matrix[3][0] += 5", then only Node_Middle and Node_Top will be affected but Node_Base will stay in position.

Each node may have an object attached. Such object may be light, mesh, dummy or camera. So in short: nodes give transformation to objects to let the objects keep interface clean and care only about lighting or being a mesh or camera or dummy.

That's very sketchy and brief description. Look at "3DSMax SDK" for further details.

 
3) how to i order the mesh/node/face so i can correctly render transparent textures (textures with alpha channel) - do i order the mesh or the nodes. (kinda like question #2).
 
Rendering transparent objects is always a pain. There is no simple and at the same time correct method. For start you may take two pass method:
-first draw all your opaque objects with depth writing enabled;
-then disable depth write and render transparent objects sorted from farest to nearest to camera;
this method may fail with not convex meshes or with special cases of obstructions and intersections, but many games use such approach with success.


For example of loading and drawing a 3ds file see "player.c"

http://www.lib3ds.org/lib3ds-1.2.0/examples/player.c

Greetings
Rafal






------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
lib3ds-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lib3ds-devel

Reply via email to