Hello.
I am having a problem figuring out what I am doing wrong when setting a rigid body to a ref_attachment and to attachment child of a rigid body constraint.
Not matter hwo I do it I get and error in the API and also in the coherencytest.
To ilustate the problem I made a very simple file to expose problem.
If somebody with expericence in collada run it thought the coherencytest it will show the error, and maybe they can tell me what is wrong and hwo can I solve it,
<?xml version="1.0"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
<asset>
<created>2007-01-01T13:30:00Z</created>
<modified>2007-01-01T13:30:00Z</modified>
<unit name="meter"/>
<up_axis>Y_UP</up_axis>
</asset>
<library_images>
<image id="texture_204e1995" depth="1">
<init_from>./wood.tga</init_from>
</image>
</library_images>
<library_effects>
<effect id="materialFx_0">
<profile_COMMON>
<technique sid="common">
<lambert>
<diffuse>
<color>0.7 0.7 0.7 1</color>
</diffuse>
</lambert>
</technique>
</profile_COMMON>
</effect>
<effect id="materialFx_204e1995">
<profile_COMMON>
<newparam sid="texture_204e1995_image">
<surface type="2D">
<init_from>texture_204e1995</init_from>
<format>A8R8G8B8</format>
</surface>
</newparam>
<newparam sid="texture_204e1995">
<sampler2D>
<source>texture_204e1995_image</source>
</sampler2D>
</newparam>
<technique sid="common">
<lambert>
<diffuse>
<texture texture="texture_204e1995" texcoord="CHANNEL1"/>
</diffuse>
</lambert>
</technique>
</profile_COMMON>
</effect>
</library_effects>
<library_materials>
<material id="material_0">
<instance_effect url="#materialFx_0"/>
</material>
<material id="material_204e1995">
<instance_effect url="#materialFx_204e1995"/>
</material>
</library_materials>
<library_geometries>
<geometry id="box_0000">
<mesh>
<source id="box_0000_position">
<float_array id="box_0000_position-array" count="72">-0.28125 1 0.28125 0.28125 1 0.28125 0.28125 1 -0.28125 -0.28125 1 -0.28125 0.28125 -1 0.28125 0.28125 1 0.28125 -0.28125 1 0.28125 -0.28125 -1 0.28125 0.28125 1 -0.28125 0.28125 1 0.28125 0.28125 -1 0.28125 0.28125 -1 -0.28125 -0.28125 -1 0.28125 -0.28125 1 0.28125 -0.28125 1 -0.28125 -0.28125 -1 -0.28125 0.28125 -1 -0.28125 0.28125 -1 0.28125 -0.28125 -1 0.28125 -0.28125 -1 -0.28125 -0.28125 1 -0.28125 0.28125 1 -0.28125 0.28125 -1 -0.28125 -0.28125 -1 -0.28125</float_array>
<technique_common>
<accessor count="24" offset="0" source="#box_0000_position-array" stride="3">
<param name="x" type="float"/>
<param name="y" type="float"/>
<param name="z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="box_0000_normal">
<float_array id="box_0000_normal-array" count="72">0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 1 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 0 -1 0 0 -1 0 0 -1 0 0 -1 0 0 0 -1 0 0 -1 0 0 -1 0 0 -1</float_array>
<technique_common>
<accessor count="24" offset="0" source="#box_0000_normal-array" stride="3">
<param name="x" type="float"/>
<param name="y" type="float"/>
<param name="z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="box_0000_UV">
<float_array id="box_0000_UV-array" count="48">0.415837 0.584163 0.584163 0.584163 0.584163 0.415837 0.415837 0.415837 0.584163 0.584163 0.584163 0.584163 0.415837 0.584163 0.415837 0.584163 0.584163 0.415837 0.584163 0.584163 0.584163 0.584163 0.584163 0.415837 0.415837 0.584163 0.415837 0.584163 0.415837 0.415837 0.415837 0.415837 0.584163 0.415837 0.584163 0.584163 0.415837 0.584163 0.415837 0.415837 0.415837 0.415837 0.584163 0.415837 0.584163 0.415837 0.415837 0.415837</float_array>
<technique_common>
<accessor count="24" offset="0" source="#box_0000_UV-array" stride="2">
<param name="s" type="float"/>
<param name="t" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="box_0000-vertices">
<input semantic="POSITION" source="#box_0000_position"/>
</vertices>
<triangles count="12" material="material_204e1995">
<input offset="0" semantic="VERTEX" source="#box_0000-vertices"/>
<input offset="0" semantic="NORMAL" source="#box_0000_normal"/>
<input offset="0" semantic="TEXCOORD" source="#box_0000_UV" set="0"/>
0 1 2 0 2 3 4 5 6 4 6 7 8 9 10 8 10 11 12 13 14 12 14 15 16 17 18 16 18 19 20 21 22 20 22 23</p>
</triangles>
</mesh>
<extra>
<technique profile="UNIFIED_VERTEX_FORMAT"/>
</extra>
</geometry>
</library_geometries>
<library_visual_scenes>
<visual_scene id="root_node__visual">
<node id="node_0000">
<matrix>1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</matrix>
</node>
<node id="node_0001">
<matrix>1 0 0 0 0 1 0 4 0 0 1 0 0 0 0 1</matrix>
<instance_geometry url="#box_0000">
<bind_material>
<technique_common>
<instance_material symbol="material_204e1995" target="#material_204e1995"/>
</technique_common>
</bind_material>
</instance_geometry>
</node>
</visual_scene>
</library_visual_scenes>
<library_physics_materials>
<physics_material id="physicsMaterial_0">
<technique_common>
<dynamic_friction>0.4</dynamic_friction>
<restitution>0.3</restitution>
<static_friction>0.6</static_friction>
</technique_common>
</physics_material>
</library_physics_materials>
<library_physics_models>
<physics_model id="physicsModel">
<rigid_body sid="rigidBody_0000">
<technique_common>
<dynamic>false</dynamic>
<mass>0</mass>
<mass_frame>
<translate>0 0 0</translate>
<rotate>0 0 1 0</rotate>
</mass_frame>
<inertia>0 0 0</inertia>
<instance_physics_material url="#physicsMaterial_0"/>
<shape>
<plane>
<equation>0 1 0 -2</equation>
</plane>
<translate>0 0 0</translate>
<rotate>0 0 1 0</rotate>
</shape>
</technique_common>
<extra>
<technique profile="Newton"/>
</extra>
</rigid_body>
<rigid_body sid="rigidBody_0001">
<technique_common>
<dynamic>true</dynamic>
<mass>10</mass>
<mass_frame>
<translate>0 0 0</translate>
<rotate>0 0 1 0</rotate>
</mass_frame>
<inertia>10 10 10</inertia>
<instance_physics_material url="#physicsMaterial_0"/>
<shape>
<sphere>
<radius>0.5625</radius>
</sphere>
<translate>0 0 0</translate>
<rotate>0 0 1 0</rotate>
</shape>
</technique_common>
<extra>
<technique profile="Newton"/>
</extra>
</rigid_body>
<rigid_constraint sid="hingeConstraint_0000">
<ref_attachment rigid_body="rigidBody_0000"/>
<attachment rigid_body="./rigidBody_0001"/>
<technique_common/>
</rigid_constraint>
</physics_model>
</library_physics_models>
</COLLADA>
the ploblem happens when I add the ref_attachment, here is my code
domRigid_constraint* AddRigidContstarint (daeDocument* document, domPhysics_model* model, const NewtonJoint* newtonJoint, int enumID)
{
const NewtonBody* body0;
const NewtonBody* body1;
domRigid_body* rigidBody0;
domRigid_body* rigidBody1;
domRigid_constraint* rigidConstraint;
domRigid_constraint::domAttachment* ref1;
domRigid_constraint::domRef_attachment* ref0;
domRigid_constraint::domTechnique_common* techniqueCommon;
char tmpName[256];
rigidConstraint = daeSafeCast<domRigid_constraint>(model->createAndPlace(COLLADA_ELEMENT_RIGID_CONSTRAINT));
sprintf (tmpName, "%s%04d", D_PHYSICS_RIGIDCONSTRAINT_NAME, enumID);
rigidConstraint->setSid(tmpName);
rigidBody0 = NULL;
ref0 = daeSafeCast<domRigid_constraint::domRef_attachment>(rigidConstraint->createAndPlace(COLLADA_ELEMENT_REF_ATTACHMENT));
body0 = NewtonJointGetBody0 (newtonJoint);
if (body0) {
rigidBody0 = m_rigidBodyMap.Find(body0)->GetInfo();
// sprintf (tmpName, "./%s", rigidBody0->getSid());
// xsAnyURI uri (rigidBody0->getSid());
// daeURI uri(rigidBody0->getSid());
// uri.setElement (rigidBody0);
// uri.resolveElement(rigidBody0->getSid());
// this funtion is failing here
// uri.resolveURI();
daeURI uri(rigidBody0->getSid());
uri.setElement (rigidBody1);
// this funtion set the url to invalid
uri.resolveURI();
ref1->setRigid_body(uri);
ref0->setRigid_body(uri);
} else {
// sprintf (tmpName, "./%s_visual", D_ROOT_NODE_NAME);
// daeURI uri (tmpName);
// ref0->setRigid_body(uri);
}
rigidBody1 = NULL;
ref1 = daeSafeCast<domRigid_constraint::domAttachment>(rigidConstraint->createAndPlace(COLLADA_ELEMENT_ATTACHMENT));
body1 = NewtonJointGetBody1 (newtonJoint);
if (body1) {
rigidBody1 = m_rigidBodyMap.Find(body1)->GetInfo();
sprintf (tmpName, "./%s", rigidBody1->getSid());
daeURI uri (tmpName);
uri.setElement (rigidBody1);
uri.resolveURI();
ref1->setRigid_body(uri);
} else {
// sprintf (tmpName, "./%s_visual", D_ROOT_NODE_NAME);
// daeURI uri (tmpName);
// ref1->setRigid_body(uri);
}
// add rigid constraint info
techniqueCommon = daeSafeCast<domRigid_constraint::domTechnique_common>(rigidConstraint->createAndPlace(COLLADA_ELEMENT_TECHNIQUE_COMMON));
_ASSERTE (techniqueCommon);
return rigidConstraint;
}
the funtion check to see if teh element had and ID and if not then sets invalid and returning, I when is debug mode and I saw that rigid bodies are element that do not have ID, so I can not figure out how to make the valid, here is the part where the function resolveURI bails out.
daeURI::resolveURI()
{
// !!!GAC bug 486, there used to be code here that just returned if state was uri_empty or uri_resolve_local this has been removed.
if (element != NULL)
{
// !!!GAC bug 388 and 421, need to add a fragment (#) before the ID (was setURI(element->getID()))
if(element->getID() == NULL || element->getID()[0] == 0)
{
// We can't resolve to an element that has no ID, so if the ID is blank, fail and return
state = uri_failed_invalid_reference;
return;
}
It looks like the same happen with coherencytest since it also report similar error.
I had made many different kind of file and they are all pass the coherance test, but I can not figure out hwo to make the constraint.
There is not sample code showing how to do it either.
According to documentation section 5-36, I believe I am doing right but it does not work.
I also tried setting the fragment
<rigid_constraint sid="hingeConstraint_0000">
<ref_attachment rigid_body="rigidBody_0000"/>
<attachment rigid_body="./rigidBody_0001"/>
<technique_common/>
</rigid_constraint>
To by hand
<rigid_constraint sid="hingeConstraint_0000">
<ref_attachment rigid_body="#rigidBody_0000"/>
<attachment rigid_body="#rigidBody_0001"/>
<technique_common/>
</rigid_constraint>
and many other permunation, but the coheraance test keep giving me this error
C:\collada>coherencytest.exe -i xxx1.dae
CHECK_uri Failed uri=file:///C:/collada/rigidBody_0000 not resolved