Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by 7th_zorro. 04/27/24 04:42
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Quad), 773 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
MDL7 skinpoints #283929
08/10/09 18:55
08/10/09 18:55
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
I am using the MDL7 library with VC++ and I have managed to load a model and render it in DX9. The only thing left to do is handle the textures.

I have notices that some skinpoints are mapped to the same vertex so I would need to duplicate the appropriate vertices and apply the skinpoints to the uv values. I have tried all day to figure out a method of doing this and I have searched for samples with no luck. I have been testing a cube model with 8 vertices and 12 faces. When I load the model in 3DGS the D3DXMESH objects has 12 vertices and 12 faces.

Is there a DirectX mesh function you use to optimise the mesh or is it done manually in the vertex buffer? All I need is a push in the right direction.

Thanks!

Re: MDL7 skinpoints [Re: sheefo] #283930
08/10/09 19:13
08/10/09 19:13
Joined: Feb 2007
Posts: 353
A
amy Offline
Senior Member
amy  Offline
Senior Member
A

Joined: Feb 2007
Posts: 353
I would iterate through all triangles and generate a list of needed vertices by using a STL container like set or map or something like that.

Re: MDL7 skinpoints [Re: amy] #283960
08/10/09 21:30
08/10/09 21:30
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
If I try and add new vertices it screws with the index buffer. I think I need a small sample of the source code or a detailed explanation.

Re: MDL7 skinpoints [Re: sheefo] #283968
08/10/09 22:27
08/10/09 22:27
Joined: Feb 2007
Posts: 353
A
amy Offline
Senior Member
amy  Offline
Senior Member
A

Joined: Feb 2007
Posts: 353
Code:
// pseudo code
vertices = set()
foreach triangle:
    foreach vertex of triangle:
        vertices.add(vertex.x, vertex.y, vertex.z, vertex.nx, vertex.ny, vertex.nz, vertex.u, vertex.v)



The set or map or some other hashed data structure will make sure that you will end up with exactly the amount of vertices you need for your vertex buffer. Afterwards you can loop through the triangles again to build your index buffer.

Re: MDL7 skinpoints [Re: amy] #284002
08/11/09 08:19
08/11/09 08:19
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The duplication of 8 to 12 vertices is done in the MDL7 library, transparent to the user. There is no DirectX function for this - it has to be done with a code such as posted by amy.

Re: MDL7 skinpoints [Re: jcl] #284053
08/11/09 13:07
08/11/09 13:07
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
I think I am too stupid to figure it out. I used an std::map<int, std::set<int>> object to store the vertices and their corrisponding skinpoints and it gave the correct number of vertices needed but I cannot seem to figure out how to store the vertex pos and normals or fill the index buffer with the new vertex values.

Since the verts and tris need to be read from seperate loops I need to store everything for access in a single loop. I got that done but storing unique vertices is proving tricky (for me).

EDIT: I have managed to create a list of all needed vertices but for some reason the list is not in the same order as the 3DGS vertex buffer. I made sure no sorting is done on the list by not using std::set.

Last edited by sheefo; 08/11/09 15:28.
Re: MDL7 skinpoints [Re: sheefo] #284099
08/11/09 18:28
08/11/09 18:28
Joined: Feb 2007
Posts: 353
A
amy Offline
Senior Member
amy  Offline
Senior Member
A

Joined: Feb 2007
Posts: 353
It doesn't matter that the order isn't the same. You have to use different indices anyway since the number of vertices very likely won't be the same as in the mdl7 file anymore.

Once you have the vertex buffer you have to build your index buffer. Loop through the mdl7 triangles again and do a look-up in your map to figure out the new indices.

Re: MDL7 skinpoints [Re: amy] #284310
08/12/09 17:50
08/12/09 17:50
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
I have re-written the vertex code to work just like the example above. The vertex buffer seems to be correct because I rendered the points in world space and they form a box (and other model shapes I have tested). The only thing left is the index buffer.
I don't understand how to calculate the new indices. In the index buffer I loop through each triangle but then I don't know how to look up the value of the new index. The code below is my setup, although it uses old indices.

Code:
for (unsigned i = 0; i < dwNumTris; i++) {
	MD7_TRIANGLE tr;
	memcpy(&tr, &pTriangles[i], sizeof(MD7_TRIANGLE));

	// triangle
	pIndexBuffer[i*3+0] = tr.v_index[0]; // old index
	pIndexBuffer[i*3+1] = tr.v_index[1]; // old index
	pIndexBuffer[i*3+2] = tr.v_index[2]; // old index
}



Re: MDL7 skinpoints [Re: sheefo] #284325
08/12/09 19:40
08/12/09 19:40
Joined: Feb 2007
Posts: 353
A
amy Offline
Senior Member
amy  Offline
Senior Member
A

Joined: Feb 2007
Posts: 353
Your second loop will look almost like the first pseudo code loop I posted above but instead of adding to the hashed data structure you do an index look-up. The details depend on what data structure you use but here is some pseudo code again:
Code:
// first loop
vertices = set()
foreach triangle:
    foreach vertex of triangle:
        vertices.add(vertex.x, vertex.y, vertex.z, vertex.nx, vertex.ny, vertex.nz, vertex.u, vertex.v)

// second loop
indices = array()
foreach triangle:
    foreach vertex of triangle:
        indices.add(vertices.indexof(vertex.x, vertex.y, vertex.z, vertex.nx, vertex.ny, vertex.nz, vertex.u, vertex.v))

I hope you get the idea now?

I think it also would be possible to do the whole job in one loop but then it gets a bit more complicated and I don't think it would have much performance advantage.

Re: MDL7 skinpoints [Re: amy] #284329
08/12/09 20:13
08/12/09 20:13
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
IT WORKED! Thank You very much. My nightmare is over laugh


Moderated by  old_bill, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1