Sign in to follow this  
QuadMV

Traversing Geometry of an .X object model?

Recommended Posts

Hi all, I need to identify certain poly’s within a model. Additionally, I need to remove these poly’s from the geometry dynamically. I’m currently using the D3DXLoadMeshFromX DX utility to get the model loaded. I think I can get to the geometry through the mesh, but I’ve never done this? Also, my idea (thanks to some brain storming with other members) is to color my poly’s in 3dsmax and export them with color. Then if I can get to the geometry and scan for the various colors, I should be able to find the poly’s I want, right? I suspect the trickier part might be pulling the poly out, since it might be embedded in a triangle fan or strip or something, I don’t know if there is a way to control that? Does anyone have experience with something like this? Is it a good technique and are there any suggestions you can provide before I dive head first into it? Basically, these poly’s are markers for special effects and alignment. I don’t want to render them, but their position and direction (front facing) is critical to me need. Thanks

Share this post


Link to post
Share on other sites
hey dude

You can certainly get to your geometry. Before you do though, what you want to look into is vertex buffers and index buffers. The sdk has some tutorials on them and what they do. understanding how they work is important.

one of the things you'll realize is that x files do not have lists of "polygons" you can draw or not draw. xfiles have a vertex buffer that holds all the vertices of your mesh. tied closely to this is the index buffer. the index buffer tells you how to draw your triangles between all your vertices using triangle lists (not strips). the directx sdk docs will explain best.

when you create an xfile using some 3d app, you can also add color information to your vertices. you could assign your vertices color values and use those values. also, if you plan to texture your mesh, you'll want to export UV coordinates too. and, if you plan to use lighting, you'll need normals.

to summarize, think more in terms of vertices and drawing triangles between those vertices. that and read the sdk =)

Share this post


Link to post
Share on other sites
Thanks. I am familiar with vertex buffers and index buffers. If that's what's going on with an X model, it should be pretty easy, right? If I just loop through each index buffer and whereever three consecutive verticies have the color I'm targetting, I take those entries out of the vertex list. I'll need to make sure if the 4th vertex isn't my target color that I only remove the first vertex, since it's a list, so it doesn't mess up subsequent triangles. Thanks again

Share this post


Link to post
Share on other sites
yeah look up FVF, too.... the FVF states what a vertex actually is. like, does your vertex have just x,y,z and u,v (5 floats) or does it have normals too? (8 floats total). your vertex buffer contains that info, so when you step across you vertex buffer you want to make sure you are using the right kind of vertex structure pointer.

in your case, each vertex will have at least 1 extra "float" or 32bit chunk that contains RGBA data. that's the data you want to check.

if you want to not draw a specific triangle then you should remove that triangle's entry from the index buffer. the index buffer tell DrawIndexedPrimitive which triangles to draw. if you delete vertices out of the vertex buffer then you will invalidate the entire index buffer and the mesh will look wrong.

so, your vertices' color info is in the vertex buffer. the indices that control which triangles you draw are in the index buffer. i think you got it from there.

Share this post


Link to post
Share on other sites
I am doing something very similar to this on my mesh modeling program. I create a new vertex buffer with just the point and color (D3DFVF_XYZ | D3DFVF_DIFFUSE), copy the vertices over and set the color. At first they are all set to one color. I change the colors based on mouse clicks to indicate they are selected, and when an operation is performed I can then only operate on the ones that are set to the other "selected" color. I draw my colored vertex list after drawing the mesh with pDevice->DrawPrimitive(D3DPT_POINTLIST, 0, sBuff).

If in vertex editing mode, just the vertices can be selected. I only need to use the index buffer in face editing mode (use D3DXIntersect to get the face and the index buffer to get the vertices of the face).

To delete a face, you need to create a new mesh that will have the number of vertices and faces that will be there after a face is deleted. If only one face is to be deleted, the you only need to delete the face from the index buffer. If mulitiple faces are selected, you will need to determine what vertices (if any) should be deleted because they will no longer be used in the remaining faces.

The hard part for me was making it work efficiently, since I had to scan the entire index buffer to see if the vertex number being deleted still existed or not and to be sure not to check a face that was in my delete list.

I used several STL vectors for it.

Share this post


Link to post
Share on other sites
You may also check D3DXIntersectTri function in DXSDK. On mouse click you simply iterate over all triangles in mesh, find the one closest to you and remove that one. Then rebuild vertex and index buffers and continue.

Check out Pick sample in DXSDK.

Share this post


Link to post
Share on other sites
Hey dudes, forgot to vertex/index buffer locking! It should be enought to bind different material to designated poly's in 3D editor. In the .x file different materials is drawn by different DrawSubset(DWORD AttribId) calls. Find appropriate AttribId and don't render it.

Share this post


Link to post
Share on other sites
Thanks for all the input and suggestions. I was looking at one of my objects in DX8 viewer ( I like this viewer better than the dx9 version), and I noticed it has an option to click and choose on different parts of the object, which in turn is selecting the different meshes within the object. Additionally, it shows the mesh name in the bottom left corner of the screen upon selection. I also see be viewing the .X file, the name I give the mesh is correctly exported. I’ve been trying to find where this information is after calling D3DXLoadMeshFromX? Can someone tell me where/how I can access the list of meshes and their names from the mesh object that is loaded?

To render the object I’m looping through the materials and calling mesh->DrawSubset ( matid ). Is there a way I can isolate each mesh and choose to draw or not draw at this level?

Thanks

Share this post


Link to post
Share on other sites
never mind my last post. I figured it out. I needed to use D3DXLoadMeshHierarchyFromX to load the model instead of D3DXLoadMeshFromX

Maybe someone can help explain this to me. I thought loadmeshhierarchy was only for animated objects, but apparently it's also for models with multiple mesh objects nested? I guess when using LoadMeshFromX it combines everything to one mesh and using LoadMeshHierarchyFromX keeps it in the native layout?

Am I ok here, or do I need to watch out for something?

Thanks

Share this post


Link to post
Share on other sites
D3DXLoadMeshFromX will apply transformations to meshes and combine all meshes into one. If multiple materials are present, then you'll have more subsets. It is better to use D3DXLoadMeshFromX if you simply want to check out the model or on small meshes. When you have entire level in .x file, D3DXLoadMeshHierarchyFromX will keep different meshes separate.

A good thing for optimization is that if you load static data with D3DXLoadMeshHierarchyFromX you collect all meshes and combine matrix transformations.

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