View Full Version : Custom Mesh Render [Managed DirectX]
alexndr
05-14-2006, 10:58 AM
I create Mesh from my own data file (exported from 3ds max or modo), it stores geometry data (vertices and indices) without materials info. So next step is to do material support. If a group of polygons has the same material - they form a subset; I have to set material for each subset and render it. It can be done by calling Mesh.DrawSubset with subset index specifying. The problem that I can't specify subset index when write vertex\index data to VertexBuffer\IndexBuffer. How to solve this problem?
alexndr
05-14-2006, 11:58 AM
AttributeBuffer used to set in which subset polygon is. How to use it? :)
Mjolnir
05-15-2006, 01:56 AM
I'd reckon you should use 'SetAttributeTable(AttributeRange[] table)' when you load mesh geometry (verts/inds). The 'table' parameter should be an array of AttributeRange, with numMaterials elements, each of which should have its AttributeId set to texture identifier (Int32) and then the FaceCount/Start with VertexCount/Start set to define appropriate parts of the mesh.
This should in effect have the mesh split into subsets.
Here's an example of having one subset, easily extended into multiple:
AttributeRange subset0 = new AttributeRange();
subset0.AttributeId = 0;
subset0.FaceStart = 0;
subset0.FaceCount = arrayIndices.Length / 3;
subset0.VertexStart = 0;
subset0.VertexCount = arrayVertices.Length;
mesh.SetAttributeTable(new AttributeRange[] {subset0});
alexndr
05-15-2006, 04:21 AM
SetAttributeTable is not suitable, because different polygons can use same vertices, so the best way to specify attribute for polygon is to use AttributeArray:
Int32[] atr = dxmesh.LockAttributeBufferArray(Microsoft.DirectX. Direct3D.LockFlags.None);
atr[m] = n;
dxmesh.UnlockAttributeBuffer(atr);
Polygon m will be with attribute n
Mjolnir, thanx for help.
Mjolnir
05-15-2006, 07:13 AM
Yup, but there's a performance penalty looming if you don't reorder such polys a bit (as that atr[] array need not be sequential: 0,1,1,2,2,0,0,1,2,1...). Otherwise, DrawSubset() would have to do this whenever called.
So, you should wrap it up with something like this:
int[] adjacency = new int[dxmesh.NumberFaces * 3];
dxmesh.GenerateAdjacency(float.Epsilon, adjacency);
// this will still generate an attribute table (on its own, though)
dxmesh.OptimizeInPlace(MeshFlags.OptimizeAttribute Sort, adjacency);
// or better yet: MeshFlags.OptimizeVertexCache to improve cache hits
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.