Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

VI2

normal data from .x

This topic is 5632 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can i obtain the normal data thats stored in the .x file? I read in the mesh and it renders properly so it must already have normal data.... given a selected face or position on a face, how can i determine the normal point???

Share this post


Link to post
Share on other sites
Advertisement
This is in VB, but it should work if you convert it. Probably a bit messy - haven''t had time to go through it all yet - but it works fine for me.


Function GetFaceNormal(Mesh As D3DXMesh, Face As Long) As D3DVECTOR
Dim Count As Long
Dim Size As Long
Dim I As Long
Dim shrtibPoints As shortFace
Dim ibPoints As lngFace
Dim verts() As D3DVERTEX
Dim ib As Direct3DIndexBuffer8
Dim VB As Direct3DVertexBuffer8
Set VB = Mesh.GetVertexBuffer()
Size = D3DX.GetFVFVertexSize(Mesh.GetFVF())
Count = Mesh.GetNumVertices()
''Mesh.GetIndexBuffer
Dim typ
Dim iBufferDesc As D3DINDEXBUFFER_DESC

Set ib = Mesh.GetIndexBuffer()
ib.GetDesc iBufferDesc
Dim isize As Long
If iBufferDesc.Format = D3DFMT_INDEX16 Then
isize = 2
Call D3DIndexBuffer8GetData(ib, isize * Face, Len(shrtibPoints), D3DLOCK_READONLY, shrtibPoints)
ibPoints.V1 = shrtibPoints.V1
ibPoints.V2 = shrtibPoints.V2
ibPoints.V3 = shrtibPoints.V3
Else
isize = 4
Call D3DIndexBuffer8GetData(ib, isize * Face, Len(ibPoints), D3DLOCK_READONLY, ibPoints)
End If
Dim iCount As Long
''Call ib.Lock(0, Len(ibPoints(0)), ibPoints(0), D3DLOCK_READONLY)
Dim Vects(3) As D3DVECTOR
If Mesh.GetFVF() = D3DFVF_VERTEX Then
ReDim verts(Count)
D3DVertexBuffer8GetData VB, 0, Size * Count, 0, verts(0)
Vects(0).X = verts(ibPoints.V1).X
Vects(0).Y = verts(ibPoints.V1).Y
Vects(0).z = verts(ibPoints.V1).z
Vects(1).X = verts(ibPoints.V2).X
Vects(1).Y = verts(ibPoints.V2).Y
Vects(1).z = verts(ibPoints.V2).z
Vects(2).X = verts(ibPoints.V3).X
Vects(2).Y = verts(ibPoints.V3).Y
Vects(2).z = verts(ibPoints.V3).z
GetFaceNormal = GenerateTriNormals(Vects(0), Vects(1), Vects(2))
Else
Stop
End If


End Function


Public Function GenerateTriNormals(p0 As D3DVECTOR, p1 As D3DVECTOR, p2 As D3DVECTOR) As D3DVECTOR

''//0. Variables required
Dim v01 As D3DVECTOR ''Vector from points 0 to 1
Dim v02 As D3DVECTOR ''Vector from points 0 to 2
Dim VNorm As D3DVECTOR ''The final vector

''//1. Create the vectors from points 0 to 1 and 0 to 2
D3DXVec3Subtract v01, MakeVector(p1.X, p1.Y, p1.z), MakeVector(p0.X, p0.Y, p0.z)
D3DXVec3Subtract v02, MakeVector(p2.X, p2.Y, p2.z), MakeVector(p0.X, p0.Y, p0.z)

''//2. Get the cross product
D3DXVec3Cross VNorm, v01, v02

''//3. Normalize this vector
D3DXVec3Normalize VNorm, VNorm

''//4. Return the value
GenerateTriNormals.X = VNorm.X
GenerateTriNormals.Y = VNorm.Y
GenerateTriNormals.z = VNorm.z
End Function






Learning to fly is easy, but as a tortoise, the landings are really rough.

Share this post


Link to post
Share on other sites
By the way, the input face is the same as the one returned by the rayintersect function.

Learning to fly is easy, but as a tortoise, the landings are really rough.

Share this post


Link to post
Share on other sites
Hey thanks... just a quick q cuz i''ve never done VB...

whats dim and redim...

Share this post


Link to post
Share on other sites
There must be a better way... I just want to draw a normal of each face on the mesh... like MeshViewer does...

I would think there would be some more efficient functions...

something along the line of GetVertex(mesh, vertex#).normal.x = ...

Anything I might be overlooking? Cuz I just want to draw lines from the faces using the normal data....

Share this post


Link to post
Share on other sites

MView has to do a bit of work in order to present its views of normals, strips, adjacency, etc.
The non-skinned case is fairly straight forward. Build a new line-list of n lines, where one endpoint of each line is the position of a vertex and the other is the normal added to the vertex. Now you can just draw the line-list whenever you want.

Drawing skinned normals are a bit more difficult. You need to skin the position and the normal before doing the addition. The non-skinned version can work on fixed function, whereas the skinned one requires vertex shaders.

Craig Peeper
Microsoft, Direct3D

This posting is provided "AS IS" with no warranties, and confers no rights.

Share this post


Link to post
Share on other sites

MView has to do a bit of work in order to present its views of normals, strips, adjacency, etc.
The non-skinned case is fairly straight forward. Build a new line-list of n lines, where one endpoint of each line is the position of a vertex and the other is the normal added to the vertex. Now you can just draw the line-list whenever you want.

Drawing skinned normals are a bit more difficult. You need to skin the position and the normal before doing the addition. The non-skinned version can work on fixed function, whereas the skinned one requires vertex shaders.

Craig Peeper
Microsoft, Direct3D

This posting is provided "AS IS" with no warranties, and confers no rights.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!