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

Started by
4 comments, last by lucky6969b 11 years, 6 months ago
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


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


I need to derive a D3DRenderer for my case


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());
}

Am I on the right track?
Thanks
Jack
Advertisement
I discover that when mesh is declared as const Mesh &mesh
it cannot update itself since it is a constant.
What is your approach, my friends?
Thanks
Jack
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.
[cancelled]
Thanks
Jack

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 );


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

Why does Mesh need to update its children? This is the job of the renderer.



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.

This topic is closed to new replies.

Advertisement