Jump to content


Custom Mesh Render [Managed DirectX]


  • You cannot reply to this topic
4 replies to this topic

#1 alexndr

    New Member

  • Members
  • PipPip
  • 28 posts

Posted 14 May 2006 - 05:58 PM

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?

10% luck, 20% skill, 15% concentrated power of will, 5% pleasure, 50% pain
and 100% reason to remember the name

My Weblog "Project Delta" » http://project-delta.blogspot.com/

#2 alexndr

    New Member

  • Members
  • PipPip
  • 28 posts

Posted 14 May 2006 - 06:58 PM

AttributeBuffer used to set in which subset polygon is. How to use it? :)

10% luck, 20% skill, 15% concentrated power of will, 5% pleasure, 50% pain
and 100% reason to remember the name

My Weblog "Project Delta" » http://project-delta.blogspot.com/

#3 Mjolnir

    Member

  • Members
  • PipPip
  • 42 posts

Posted 15 May 2006 - 08: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});


#4 alexndr

    New Member

  • Members
  • PipPip
  • 28 posts

Posted 15 May 2006 - 11: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.

10% luck, 20% skill, 15% concentrated power of will, 5% pleasure, 50% pain
and 100% reason to remember the name

My Weblog "Project Delta" » http://project-delta.blogspot.com/

#5 Mjolnir

    Member

  • Members
  • PipPip
  • 42 posts

Posted 15 May 2006 - 02:13 PM

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.OptimizeAttributeSort, adjacency);

// or better yet: MeshFlags.OptimizeVertexCache to improve cache hits







1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users