Open minusplusminus opened 10 years ago
I've figured it out:
typedef struct
{
ofVec3f scale;
ofVec3f rotation;
ofVec3f position;
} meshTranslation;
meshTranslation ofxAssimpModelLoader::getMeshTranslation(int meshIndex)
{
meshTranslation translation;
aiMatrix4x4 childTransformation = scene->mRootNode->mChildren[meshIndex]->mTransformation;
aiVector3t<float> scaling;
aiQuaterniont<float> rotation;
aiVector3t<float> position;
childTransformation.Decompose(scaling, rotation,position);
translation.position.set(position.x,position.y,position.z);
translation.position = translation.position*normalizedScale;
translation.scale.set(scaling.x, scaling.y,scaling.z);
translation.rotation.set(rotation.x,rotation.y,rotation.z);
return translation;
}
pinging @openframeworks/2d-3d @arturoc
probably what we need is to internally represent ofxAssimpModelLoader meshes using an of3dPrimitive which already includes a node so you can easily query for it's position, rotation... also it will probably make the code cleaner
of3dPrimitive ofxAssimpModelLoader::getMeshTranslation(int meshIndex)
{
of3dPrimitive translation;
if( scene->mRootNode != NULL && meshIndex < scene->mRootNode->mNumChildren)
{
meshIndex = ofClamp(meshIndex,0, scene->mRootNode->mNumChildren);
aiMatrix4x4 childTransformation = scene->mRootNode->mChildren[meshIndex]->mTransformation;
aiVector3t<float> scaling;
aiQuaterniont<float> rotation;
aiVector3t<float> position;
childTransformation.Decompose(scaling, rotation,position);
ofQuaternion q;
q.set(rotation.w, rotation.x, rotation.y, rotation.z);
translation.setPosition(position.x,position.y,position.z);
translation.setPosition(translation.getPosition()*normalizedScale);
translation.setScale(scaling.x, scaling.y,scaling.z);
translation.rotateAround(q, ofPoint(rotation.x,rotation.y,rotation.z));
}
return translation;
}
I'm unsure about the rotation. What do you think @arturoc ?
mmh, no that doesn't make much sense, an of3dPrimitive is an object that has a mesh and an ofNode so it can represent a geometry and it's transformations. what i was saying is that ofxAssimpModelLoader could use of3dPrimitives instead of ofMesh to reprensent the different meshes and at the same time the transformations for each of those meshes, then a function like the one you propose would just need to call getPosition/Rotation... on the corresponding primitive.
it's kind of a big change and if we are going to do that it's probably worth looking into porting the addon to use assimp 3
Hi,
I've mentioned that Assimp model loader doesn't have positions of meshes. I've seen that the data is available in the Assimp library, but not interpreted in the addon.
I've allready made a start, but couldn't get the positions right.
}