your code :
# generate the triangle strip
triangleStrip = GeomTristrips( Geom.UHStatic )
for z in range( self.header[ 'height' ] - 1 ): # loop through the rows
# fill in the row
for x in range( self.header[ 'width' ] - 1 ): # loop through the columns
# fill in the column
triangleStrip.addVertex( x )
triangleStrip.addVertex( z ) <---- WHAT FOR ????
# close the the primitive
triangleStrip.closePrimitive( )
why do you go back to vtx ?
this works :
w = self.header[ 'width' ]
for z in range( 0, w*(self.header[ 'height' ] - 1),w ): # loop through the rows
# fill in the row
for x in range( self.header[ 'width' ] - 1 ): # loop through the columns
# fill in the column
triangleStrip.addVertex( z+x )
# close the the primitive
triangleStrip.closePrimitive( )
or this :
w = self.header[ 'width' ]
w2=w*2
for z in range( 0, w*(self.header[ 'height' ]-1),w ): # loop through the rows
# fill in the row
triangleStrip.addNextVertices( w2 )
# close the the primitive
triangleStrip.closePrimitive( )
1 more thing :
your vtx data building is clockwise, which yields flipped poly normals. So flip the order from z -> (z+1) to b -> z[/b].
the closer I saw your code, the more I found :
- you already know that there are 3 channels, but you don’t have to use them all, or even swapping the B & R. Using 1 channel is enough, as long as the image is grayscale.
I fixed it this way :
# unpack the pixel data into a list
BGRpixels = list( unpack( "%dB" % self.imgMemorySize, self.imgFile.read( self.imgMemorySize ) ) )
# let's use 1 channel only
self.pixels = BGRpixels[::3]
- your height query is wrong, the z must be multiplied with the width, not height.
let’s say I have this 4x2 grid :
| 0123
--|------
1| 4567
0| 0123
and I need the “7” (row=1,col=3), I shouldn’t get it this way :
row x height + col = 1x2 + 3 = 5 --> wrong
but this way :
row x width + col = 1x4 + 3 = 7 --> correct
- your height query also doesn’t respect the 3 channels, you’re using it as if it’s 1 channel. By using only 1 channel, this issue is automatically solved.
self.pixels = BGRpixels[ : : 3 ]
No, it’s not using the 3rd, but the 1st : [0,3,6,9,12,…], and it should be the Blue, as you said the order is reversed (I’m not sure though, I didn’t xperiment with the individual channel).
I’m not sure with your current problem. It doesn’t matter if you’re using Y-up (I use Z-up, so I swap the z and the height), it should work.
How does it look now ?
No, don’t do that, the width&height are already the image’s w&h, regardless of the channels count.
get it –[HERE]–
I use Z-up.
funny.
of course, what else.
wait, could it be your tga ?
try mine :
GIMP
Photoshop
make sure you’re only generating (height-1) tristrips, because the pixels are the grid points.
disregard that, I guess I know why. You didn’t run the whole code, did you ?
So you must missed the -1 here (in generate) :
for z in range( self.header[ 'height' ]-1 ): # go through the rows
for x in range( self.header[ 'width' ] ): # go through the columns
Your orig code (3 channels) uses 2 times larger data, so it survives, but once you’re using 1 channel, and when python is iterating on the last z (height-1), this is what happening :
(z+1) = height
but the last index is height-1, thus the out-of-range error.
oh, you’re using 16 bpp tga. I see that now. I use 24 bpp. Have you tried my tgas ?
wait, why do you want to use 16 bpp, or multi channel ? Do you have any specific purposes ? Or you just follow that algo ?
If only for heightfield, 8 bpp (1 channel) grayscale is enough.
same link