Papervision Collada Interactivity
Getting interactivity to work with Papervision3D Collada objects can be a little tricky.
There are two main confusion points:
If you have any suggestions, questions, or know a better way please let me know!
There are two main confusion points:
- The Collada class is a container for the 3D objects defined in the .dae file. You will need to get a reference to the child object of the Collada class for which you want to interact with. I found this to be a little troublesome because of some getChildByName not working as I expected it to. I also found it clunky to have to hardcode somewhere the name of the object as defined by the designer. So I cobbled together the following function to return the first child DirectObject3D for a given Collada object. Fortunately for me, the collada files I am using are simple and only contain one object per. If yours are more complex, you may have to go a different route. It's a little hacky as you can tell, but it works.
- Interactivity events are based on the material that is applied to the object, not the object itself. So, you need to obtain a reference to the object's material, set interactive=true, and then add your event listener to the object. Here is another function that I hacked together to retrieve a reference to a Collada child object's material.
private function getColladaNodeMaterial(colladaNode:DisplayObject3D):MaterialObject3D { var returnVal:MaterialObject3D; try { var materialName:String = StringUtil.trim(String(colladaNode.materials)); trace("materialName: '" + materialName + "'"); returnVal = colladaNode.getMaterialByName(materialName); } catch(errObject:Error) { trace(errObject.message); } return returnVal; }
public function getColladaDisplayObj(tempCO:DisplayObject3D):DisplayObject3D {
var returnObj:DisplayObject3D;
try {
var childname:String = String(tempCO.childrenList()).substring(0,String(tempCO.childrenList()).indexOf(": "));
returnObj = tempCO.getChildByName(childname);
this.myDisplayObj = returnObj;
//trace("found colladaNode: " + childname);
} catch(errObject:Error) {
trace(errObject.message);
}
return returnObj;
}
If you have any suggestions, questions, or know a better way please let me know!
Comments
Where can i find the StringUtil Class ?
Thanks.
http://code.google.com/p/as3corelib/
thanks CJ in advance.
i allready now the object name...