Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get position of ofxAssimpModelLoader mesh #2989

Closed
minusplusminus opened this issue May 21, 2014 · 9 comments
Closed

get position of ofxAssimpModelLoader mesh #2989

minusplusminus opened this issue May 21, 2014 · 9 comments

Comments

@minusplusminus
Copy link

Hi,

I'm trying to get a position of a mesh from Assimp. But I could not figure out how. Is there a simple solution for this? This could be a handy feature.

@wasawi
Copy link
Contributor

wasawi commented May 21, 2014

+1

@minusplusminus
Copy link
Author

I've allready made some code for getting the verticles. I still can't figure out how to get the position of the mesh:

      vector<ofPoint> ofxAssimpModelLoader::getMeshVerticles(int meshIndex)
 {
     aiMesh * mesh = getMeshHelper(meshIndex).mesh;
     aiVector3D* aiPts = mesh->mVertices;

     for(int x=0; x<mesh->mNumVertices; x++ )
     {

         Pts[x] = ofPoint(aiPts[x].x,aiPts[x].y,aiPts[x].z) * normalizedScale;

     }
     return Pts;
 }

@bilderbuchi
Copy link
Member

This feels like it would be more appropriate in the forum, but in any case, @openframeworks/2d-3d, can you help?

@elliotwoods
Copy link
Contributor

I presume that using the mean of the vertices isn't a solution

I'm not familiar with Assimp, but if it's like ofMesh, then the mesh itself doesn't have a position, but the individual vertices do. Which means that your question can usually mean either:
A) what's the mid point of the bounding box
B) what's the mean vertex position

@danzeeeman
Copy link
Member

you need to get the matrix of the individual mesh from ofxAssimpModelLoader

I exposed it in a branch here https://github.com/danthemellowman/openFrameworks/blob/ofxassimp-update-access-mesh-matrix/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp#L827

but you can also just get the MeshHelper for a given mesh and get the matrix from that.

https://github.com/openFrameworks/openFrameworks/blob/master/addons/ofxAssimpModelLoader/src/ofxAssimpModelLoader.cpp#L580

@danzeeeman
Copy link
Member

You can also do something like this and get the bounding box of the mesh and then find the center point.

https://github.com/YCAMInterlab/mapamok/blob/master/SharedCode/MeshUtils.h#L305

@julapy
Copy link
Member

julapy commented May 31, 2014

here is how ive been creating a duplicate mesh from a model and transforming it back into world space. you need to create a ofMatrix4x4 which is combination of the model matrix and the mesh matrix, once you have this, you can re-calculate your mesh back into world space like below. using this approach, you can also re-calculate the mesh position back into world space.

i do this quite a bit when working with ofxAssimpModelLoader and looks like others do too.
perhaps this should be a feature in ofxAssimpModelLoader?

    int meshIndex = 0;
    ofMatrix4x4 modelMatrix = model.getModelMatrix();
    ofMatrix4x4 meshMatrix = model.getMeshHelper(meshIndex).matrix;
    ofMatrix4x4 concatMatrix;
    concatMatrix.preMult(modelMatrix);
    concatMatrix.preMult(meshMatrix);

    ofMesh mesh = model.getMesh(meshIndex);

    for(int i=0; i<mesh.getNumVertices(); i++) {
        ofVec3f & vert = mesh.getVertices()[i];
        vert.set(concatMatrix.preMult(vert));
    }

cc @ikillbombs @wasawi

@julapy julapy self-assigned this May 31, 2014
@edap
Copy link
Member

edap commented Aug 15, 2017

What if, ofxAssimpModelLoader, when importing the meshes, convert them to of3dPrimitive?
of3dPrimitive has ofNode, and all the meshes belonging to the same model could have as parent an ofNode that defines the position of the model.
In this way it is also easier move the model around and getting the position.

@NickHardeman
Copy link
Contributor

Each node in ofxAssimp extends ofNode, ie meshes and bones. Meshes have both local and global bounding boxes and a center location. Functions have been added to get the transformed vertices as ofMeshes.

/// \brief Get a transformed OF mesh based on name of assimp mesh.
/// \param aname name of the desired assimp mesh.
/// \return Transformed ofMesh.
ofMesh getTransformedOFMeshForMesh(const std::string& aname);
/// \brief Get a transformed OF mesh based on the vector index of the assimp mesh.
/// \param ameshIndex vector index of the assimp mesh.
/// \return Transformed ofMesh.
ofMesh getTransformedOFMeshForMesh(unsigned int ameshIndex);

closed by #7776

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants