Results 1 to 5 of 5

Thread: D3D Mesh to COLLADA

  1. #1
    JRichards
    Guest

    D3D Mesh to COLLADA

    First let me thank those people who are taking the time to read my post as it is kind of long (with code).

    Secondly, if the formatting does not appear right then my apologies. I would appreciate it if you could tell me how to keep my formatting on this board.

    I havenít quite put all the pieces together in my mind yet, and I am having some problem understanding the COLLADA layout with a mesh. I am trying to save a D3D mesh using COLLADA DOM with C++. The two areas that I am having problems with are the EFFECTS and MATERIALS.

    When I add the TRIANGLES I am also assigning a MATERIAL for each subset. Is this correct?

    I am assigning material IDís as such:
    Code :
    		sprintf( tmp, "mtl%d", AttribId );
    		triangles->setMaterial( tmp );


    Now comes the confusing part. I add an EFFECT using the below code. Could someone tell me what is needed to finish this off, assuming that I am trying to use the Fixed-Function pipeline with a simple texture-material associated with the TRIANGLES.

    Code :
    bool CColladaParser::AddEffect( daeElement* parentNode, CXMesh* theModel )
    {
    	if( parentNode == NULL  ||  theModel == NULL )
    		return false;
     
     
    	domLibrary_effects* libEffects = daeSafeCast<domLibrary_effects>( parentNode->add( "library_effects" ) );
    	if( libEffects == NULL )
    		return false;
     
     
    	domEffect* effect = daeSafeCast<domEffect>( libEffects->add( "effect" ) );
    	if( effect == NULL )
    		return false;
     
    	effect->setId( "ModelEffect" );
     
     
    	domFx_profile_abstract* profile = daeSafeCast<domFx_profile_abstract>( effect->add( "profile_COMMON" ) );
    	if( profile == NULL )
    		return false;
     
     
    	// Add a surface - what is a surface?
    	domFx_newparam_common* newparam = daeSafeCast<domFx_newparam_common>( profile->add( "newparam" ) );
    	if( newparam == NULL )
    		return false;
     
    	newparam->setSid( "surface" );
     
    	domFx_surface_common* surface = daeSafeCast<domFx_surface_common>( newparam->add( "surface" ) );
    	if( surface == NULL )
    		return false;
     
    	surface->setType( FX_SURFACE_TYPE_ENUM_2D );
     
    	//surface->add( "init_from" )->setCharData( tmpName.c_str() );
     
     
     
    	// Add a <sampler2D>
    	return true;
    }


    And finally, the MATERIAL setup is lacking too.

    Code :
    bool CColladaParser::AddMaterial( daeElement* parentNode, CXMesh* theModel )
    {
    	if( parentNode == NULL  ||  theModel == NULL )
    		return false;
     
     
    	domLibrary_materials* libMaterials = daeSafeCast<domLibrary_materials>( parentNode->add( "library_materials" ) );
    	if( libMaterials == NULL )
    		return false;
     
    	UINT matCount = theModel->GetNumMaterials();
    	for( UINT matID = 0;  matID < matCount;  matID++ )
    	{
    		CXMaterial* theMaterial = theModel->GetMaterial( matID );
    		if( theMaterial == NULL )
    			continue;
     
    		domMaterial* material = daeSafeCast<domMaterial>( libMaterials->add( "material" ) );
    		if( material == NULL )
    			continue;
     
    		char tmpName[ 100 ];
    		memset( tmpName, 0, sizeof(tmpName) );
     
    		sprintf( tmpName, "mtl%d", matID );
    		material->setId( tmpName );
    		material->add( "instance_effect" )->setAttribute( "url", "#ModelEffect" );
    	}
     
     
        return true;
    }

  2. #2
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771

    Re: D3D Mesh to COLLADA

    Quote Originally Posted by JRichards
    When I add the TRIANGLES I am also assigning a MATERIAL for each subset. Is this correct?
    Mesh primitives (e.g. <triangles>) have a symbolic-name "material" attribute. This is not a URI, ID, or SID. See <bind_material> in the spec for binding details.
    Quote Originally Posted by JRichards
    Now comes the confusing part. I add an EFFECT using the below code. Could someone tell me what is needed to finish this off, ...
    Read the COLLADA specification Chapter 7: Getting Started with FX, for details on the structures and relationships involved between geometry, materials and effects.

  3. #3
    JRichards
    Guest

    Re: D3D Mesh to COLLADA

    Thanks.

    I am printing out both Ch 7 and Ch 8.

  4. #4
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771

    Re: D3D Mesh to COLLADA

    Since you're using the DOM you can also review the rt and fx samples for coding examples. The COLLADA Refinery (also on sourceforge) is also built on the DOM, as are other tools and plug-ins like OpenSceneGraph plugin, CgToGLSL, etc.

  5. #5
    Senior Member
    Join Date
    Aug 2004
    Location
    California
    Posts
    771

    Re: D3D Mesh to COLLADA

    Also for DX vertex buffer creation, have a look at the COLLADA for XNA C# source.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •