Sign in to follow this  
lucky6969b

Static Rigid Mesh with each part having an individual Transformation(combinedTransform)

Recommended Posts

When I model in 3dsmax, each part of the rigid mesh (say a warehouse wall) has its own absolute positions.
But they are not grouped as one.
So when I render it, I need to combine the transformation with its parents.
I wonder in swiftcoder's code

[code]
class IRenderer // Has OpenGLRenderer and D3DRenderer as subclasses
{
virtual void render(const Mesh &mesh, Matrix4 modelMatrix, const CCamera &camera) = 0;
};
[/code]

I need to derive a D3DRenderer for my case

[code]
class CD3DRenderer : public IRenderer
{

};

void CD3DRenderer::render((const Mesh &mesh, Matrix4 modelMatrix, const CCamera &camera)
{
// Do I define a method in Mesh so that it's always updating its corresponding children?
mesh.UpdateFrame(modelMatrix);
RenderFrame(mesh.getRoot());
}
[/code]
Am I on the right track?
Thanks
Jack Edited by lucky6969b

Share this post


Link to post
Share on other sites
Why does Mesh need to update its children? This is the job of the renderer.

This is how my engine does it: (simplified, but this is the general idea)
[source lang="cpp"]
struct Object
{
Shape* shape;
Transformation3D transform; // 3x3 rotation, position, scale, gets converted to 4x4 matrix later, defined relative to parent Object or world space.
std::vector<Object*> children;
};

// Base for different shape types (static mesh, animated mesh, heightfield, procedural sphere, cylinder, box, etc).
struct Shape
{
// Get the best mesh suited for the camera's viewpoint, allows LOD.
virtual const MeshChunk* getMesh( const Camera& camera ) const = 0;
};

struct MeshChunk
{
VertexBuffer* vertices; // hardware vertex buffer containing shader vertex attributes.
IndexBuffer* indices; // hardware index buffer
Material* material; // shader, uniform variables
Matrix4x4 transform; // transformation from mesh to camera space.
};

// Find the objects that are visible to the given camera
void cullObjects( const Scene& scene, // some representation of the scene, usually a list of Object*
const Camera& camera,
vector<Object*>& visibleObjects );

// This is a class in my engine but a function here for simplicity.
void flattenHierarchy( const vector<Object*>& visibleObjects, vector<const MeshChunk*>& visibleChunks )
{
// recursively combine the object/shape transformations, calling getMesh() for each
// object's shape, then place the output chunks in the output vector.
}

// could be a virtual method of a class as you have above.
// The application renderer iterates over the list of mesh chunks and renders them using this function.
void renderMeshChunk( const MeshChunk& chunk );
[/source]

Notice that the objects are mostly data (with methods to operate on it, not shown). While simplified, this is a good starting point for a graphics engine. This architecture as-is doesn't really allow you to have global shader attributes (shadow maps, for example). My engine solves this by keeping a cache of global shader attributes which is updated lazily whenever mesh chunks need that information. This cache is passed into renderMeshChunk() which then uses the cache to provide shader attributes that aren't explicitly specified in the Material object. Edited by Aressera

Share this post


Link to post
Share on other sites
[code]
struct Object
{
Shape* shape;
Transformation3D transform; // 3x3 rotation, position, scale, gets converted to 4x4 matrix later, defined relative to parent Object or world space.
std::vector children;
LPD3DXANIMATIONCONTROLLER m_pAnimCtrl;
};

// Base for different shape types (static mesh, animated mesh, heightfield, procedural sphere, cylinder, box, etc).
struct Shape
{
// Get the best mesh suited for the camera's viewpoint, allows LOD.
virtual const MeshChunk* getMesh( const Camera& camera ) const = 0;
};

struct MeshChunk
{
LPD3DXFRAME m_pRoot;
Matrix4x4 transform; // transformation from mesh to camera space.
};

// Find the objects that are visible to the given camera
void cullObjects( const Scene& scene, // some representation of the scene, usually a list of Object*
const Camera& camera,
vector& visibleObjects );

// This is a class in my engine but a function here for simplicity.
void flattenHierarchy( const vector& visibleObjects, vector& visibleChunks )
{
// recursively combine the object/shape transformations, calling getMesh() for each
// object's shape, then place the output chunks in the output vector.
}

// could be a virtual method of a class as you have above.
// The application renderer iterates over the list of mesh chunks and renders them using this function.
void renderMeshChunk( const MeshChunk& chunk );
[/code]

I've made a few modifications to your coding specific to the D3D renderer and the D3DX helpers, Where should I put the "master" animation controller for each object from which it would be cloned to individual objects.

Does flattenHierarchy mean to combine the transformations of each body part of a blended mesh? Do I call it as a function not as a method of certain class?

Thanks
Jack Edited by lucky6969b

Share this post


Link to post
Share on other sites
[quote name='Aressera' timestamp='1348205545' post='4982243']
Why does Mesh need to update its children? This is the job of the renderer.

[/quote]

I catch your point, when a const Mesh& mesh is passed to the renderer, it is a "one-way parameter passing", After the animator has animated the mesh, the transformations are done.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this