Jump to content
  • Advertisement
Sign in to follow this  
sakky

Blender's polygons in wrong order

This topic is 4864 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

I made a custom 3D object exporter for Blender to use with my little demo. the plug in half ass works. The polygons are all messed up. The vertex information is wrote correctly, but the polygon indices are not because D3DPT_TRIANGLESTRIP gives me a really crappy looking DrawIndexedPrimitive() result. Now it pretty obvious what's going on here, the indices are not in the correct order for the rendering process. So, I ask you! Do any of you know how to detect the order of indices in Blender so that I may change them while modeling. This will only save me from a few problems though. How do I write triangles that are not in a list or strip with indexed primitives in Direct3D?

Share this post


Link to post
Share on other sites
Advertisement
No takers? Oh well, I figured it out any ways. Hey, if any of you need help with Python extensions or writing Blender scripts, drop me a line. Or maybe I should write a tutorial.

Share this post


Link to post
Share on other sites
I assume this is left handed vs right handed issue.
Usually in D3D, people use LHS but probably Blender is RHS.

Share this post


Link to post
Share on other sites
Well, actually I'm rendering it perfectly with D3DPT_TRIANGLELIST. I think one of the problems was the fact that the polygons were quads and not triangles. That fixed the model problem, but with out depth buffering I can see a few problems in the mesh. Maybe I should just switch to drawing triangles, if Direct3D doesn't suppor it, I can just ditch Direct3D and switch to OpenGL which I know does support that kind of operation. Anyby drawing triangles, I mean traingle by triangle not list, fans or strips, but one by one as a batch.

But any ways, I still have a problem. The model's UV(texture) coordinates are not exporting properly. Either that, or I just don't know how to texture in Blender. My model's texture is all chopped up over the mesh. I write the UVs using the.....screw it! I'll just show you the source to the script


#!BPY

# """
# Name: 'MOD File Format (.MOD)'
# Blender: 232
# Group: 'Export'
# Tooltip: 'Export custom MOD format by Matthew R. Erdman'
# """

___author___ = "Matthew R. Erdman"
___version___ = "1.0"

import Blender, mod_meshtools
import struct

MODSig = 0x4D4F4421L

def write( FileName ):
File = open( FileName, "wb" )

# Initialize Blender interfaces
ObjSel = Blender.Object.GetSelected( )
ObjNam = ObjSel[ 0 ].name
MshNam = ObjSel[ 0 ].data.name
Mesh = Blender.NMesh.GetRaw( MshNam )
Obj = Blender.Object.Get( ObjNam )

# Retrieve object inforamtion
NumVerts = long( len( Mesh.verts ) )
OffVerts = 0L
NumFaces = long( len( Mesh.faces ) )
OffFaces = 0L
Color = 0xFFFFFFFFL

TexCoords = [ ]

for I in range( 0, NumFaces ):
TexCoords.append( Mesh.faces[ I ].uv[ 0 ] )
TexCoords.append( Mesh.faces[ I ].uv[ 0 ] )
TexCoords.append( Mesh.faces[ I ].uv[ 0 ] )

File.write( struct.pack( "LLLLL", MODSig, NumVerts, OffVerts, NumFaces, OffFaces ) )

# Write vertex information
OffVerts = File.tell( )
for I in range( 0, NumVerts ):
File.write( struct.pack( "fffLff", Mesh.verts[ I ].co.x,
Mesh.verts[ I ].co.y,
Mesh.verts[ I ].co.z,
Color,
TexCoords[ I ][ 0 ],
TexCoords[ I ][ 1 ] ) )

# Write polygon information
OffFaces = File.tell( )
for I in range( 0, NumFaces ):
File.write( struct.pack( "HHH", Mesh.faces[ I ].v[ 0 ].index,
Mesh.faces[ I ].v[ 1 ].index,
Mesh.faces[ I ].v[ 2 ].index ) )

# Write the header
File.seek( 0 )
File.write( struct.pack( "LLLLL", MODSig, NumVerts, OffVerts, NumFaces, OffFaces ) )
File.close( )

def fs_callback( FileName ):
if FileName.find( '.mod', -4 ) <= 0: FileName += '.mod'
write( FileName )

Blender.Window.FileSelector( fs_callback, "Export Mod" )



I've tried subtracting the V coordinate from 1, because I though the OpenGL might be causing the problem do to the fact of different UV system. But that didn't help either.

NOTE: The Mesh.verts has UV coordinates, but their "sticky". I tried exporting them and I got nothing. Except the color of the model was tinted the texture color.

Share this post


Link to post
Share on other sites
I don't know Blender script, but this part looks suspicious

for I in range( 0, NumFaces ):
TexCoords.append( Mesh.faces[ I ].uv[ 0 ] )
TexCoords.append( Mesh.faces[ I ].uv[ 0 ] )
TexCoords.append( Mesh.faces[ I ].uv[ 0 ] )

D3D doesn't support quads, so you can reprocess those into tris.

Share this post


Link to post
Share on other sites
Well V-Man, if you read my other post then you would have known that I did change that.

I go the polygons to render, but I have to use a depth buffer or I will see through them. Also, the texture coordinates are all messed up. Like I said, the texture i all chopped up over the model. I got parts of the texture zig zagging all over.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!