mr_friend![]() Member Posts: 17 From: Bonner Springs, KS, USA Registered: 06-19-2005 |
Detailed programming question. Given: Ok I know how to load a mesh from a (.X) file, I know how to manually create a VertexBuffer for simple geometry like is in the DX 3D tutorial section. Goal: In C# to use a detection algorithm that looks at the 3 vertexes per triangle and compares them to a sphere, for a collision detection pass. Issue: When I load a (.X) mesh structure the vertex’s are stored into a vertexBuffer, and I haven’t found any way to directly access this memory for the collision detection algorithm. I have also come to realize that this memory buffer could be memory stored on the graphics card itself. So my question is would it be advisable to keep 2 copies of the mesh data? One in the Graphics card memory for fast rendering, and one copy in system memory for collision detection or is there a better way?
Sample (.X) Mesh Loader: DirectX\ Samples\Managed\Direct3D\Tutorials\Tutorial6 Collision detection algorithm sample: http://www.peroxide.dk/download/tutorials/tut10/pxdtut10.html Gary ------------------ |
|
HanClinto![]() Administrator Posts: 1828 From: Indiana Registered: 10-11-2004 |
You did a great job of laying out the background, thanks! What about the vertexBuffer can't you access? From looking at the MSDN page, it seems like you should be able to do something like: myVertexBuff[0].Position = new Vertex3(0.1f, 0.0f, 2.0f); and be able to access that information in the same way. You're saying that you're trying to access the memory directly? Or can you do it with the public members of the vertices that are stored in your vertexBuffer? Hrm -- perhaps a small paste of code showing what you're trying to do? 3D isn't my specialty, but C# is -- so I'll see what I can do. Respectfully, ------------------ |
|
mr_friend![]() Member Posts: 17 From: Bonner Springs, KS, USA Registered: 06-19-2005 |
I thought in order to get access to the VertexBuffer data, I have to lock the buffer? is this incorrect. something like... Vector3 temp = mesh.LockVertexBuffer(ect.., besides when I have tried using the mesh.VertexBuffer[0] approach it wouldnt let me use the "[]" saying it cannot apply indexing with "[]" error. If I am messing this up please let me know, Im still getting acustom to C#, from c++. ------------------ |
|
Briant![]() Member Posts: 742 From: Stony Plain, Alberta, Canada Registered: 01-20-2001 |
In C++ (which I am much more familiar with) LockVertexBuffer locks the buffer for you and gives you a pointer to the buffer. In C#, in returns a "GraphicsStream". I found this sample code on msdn:
Or you could keep a second copy of the mesh data for your collision detection, but it would probably be cleaner to understand locking and using the vertex buffer instead. |
|
mr_friend![]() Member Posts: 17 From: Bonner Springs, KS, USA Registered: 06-19-2005 |
Brian, Sorry, it's taken me so long to try to emplemnt the code you posted, but I am having a time trying to get a sample to compile with that code snipit. I looked up the MS reference, they that is the exent of code they post. I guess the hardest part about this for me is I am having a real difficult time finding simple, full complete source code to look at, that I can compile, and tweek until I understand how it all works and fits to gether. I have tried a few simple pieces of code but every time I insert the snipit, I get error of one type or another and my example no longer compiles. I will try to get a stripped out version to post here, but if you come across a compilable example of the graphicsStream, please post it. Thanks ------------------ |
|
shadowsill Junior Member Posts: 1 From: Registered: 06-28-2005 |
wow, what are the odds, i just spent the last 5 hours trying to figure out this very question - stumbled across this page while searching for the answer. found all that msdn stuff a while ago, didn't help me much ... perhaps try this page - h**p://www.developerfusion.co.uk/show/4387/4/ haven't really read through it too much, and i am too tired to now, but will read through it tomorrow and let you know if i have found anything out best of luck to you, if you figure anything out before i do please post your solution |
|
mr_friend![]() Member Posts: 17 From: Bonner Springs, KS, USA Registered: 06-19-2005 |
Ok, I think I have caputred the vertex data, safely. but am still working on how to get the index data, so i can correctly create the 3 Vertex triangle to do the collision on. Below is the raw vertex capture. --Inserted into the Tutoral#6 MS sample mesh = Mesh.FromFile("tiger.x", MeshFlags.SystemMemory, device, out materials); for (int i = 0; i < mesh.NumberVertices; i++) mesh.VertexBuffer.Unlock(); ------------------ |
|
mr_friend![]() Member Posts: 17 From: Bonner Springs, KS, USA Registered: 06-19-2005 |
PRAISE THE LORD!, PRAISE GOD!! After looking and not finding, He has provided a way. It's all C# no unsafe code sections, the Vertix points get transfered to Vector3[], and the indexes get transfered to short[]. This would allow loading using the MS .x file loading and then extracting the triangles for a collision detection algoithem. (More then Box, and sphere)
I Left the messageboxes I used. If you looking to understand what I did you can look at the code and message boxes to get a better idea why i used short[] for indices. Later Gary ------------------ |