Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

How to make instances of the same mesh?

This topic is 901 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Currently I got an tailor-made IK system on hand.
When I load the .x file, I create one instance of the mesh and dish out
to various game objects, However, I find this is prone to errors.
Because when I reference the local transformation matrix of the handle,
it is referring to the same position!
So I want to instance out to 3 instances of the mesh, I think unlike animation controller,
it is fairly cheap to clone an animation controller, but what about cloning the mesh itself?
So how do I clone the mesh and give each game object an instance?
Thanks
Jack

Share this post


Link to post
Share on other sites
Advertisement

class CMesh

{

public:

 

  Vec3* m_pVertices;

 Vec3* m_pNormals;

 

etc...

 

};

 

class CMeshComponent

{

public:

   CMeshComponent(CMesh* pMesh) :

    m_pMesh(pMesh)

{

 

}

 

 CMesh* GetMesh() const { return m_pMesh; }

 

 const Transform& GetTransform() const { return m_transform;}

 

  void SetTransform(const Transform& Transform)

{

 m_transform = Transform;

 

private:

 

 std::smart_ptr<CMesh> m_pMesh;

 

Transform m_transform;

};

 

 

load all of the mesh data from a file, and put into a mesh class, in this case CMesh, for each game object that needs the mesh, give it a Mesh Component, CMeshComponent, that references the mesh, the mesh component will hold the transform that you need, and the mesh, therefore solving your problem

Share this post


Link to post
Share on other sites

Currently I got an tailor-made IK system on hand.
When I load the .x file, I create one instance of the mesh and dish out
to various game objects, However, I find this is prone to errors.
Because when I reference the local transformation matrix of the handle,
it is referring to the same position!
So I want to instance out to 3 instances of the mesh, I think unlike animation controller,
it is fairly cheap to clone an animation controller, but what about cloning the mesh itself?
So how do I clone the mesh and give each game object an instance?
Thanks
Jack

 

One of the most basic design principle tells us to rule out anything that can change, and make it managable.

Therefore if you have mesh data that should be the same but different matrix handlers, rule out the matrix handler and make it dynamic. 

So you should end up with something like this:

class MyGameObj

{

 Mesh meshData;

MatrixHandler matrices; 

}

The mesh describes what kind of graphical data you have,

The matrix handler describes the class that has the matrix behavior. 

The GameObj should be concerened only about what this game obj does (A door, wall, enemy, w/e). 

 

(It's not the perfrect design, but should clear out my point).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!