News:

Function Finder  Find all the functions within source code files

Main Menu

File Reader help???

Started by ScottieB, June 20, 2013, 10:32:59 AM

Previous topic - Next topic

ScottieB

Here is a text document that I am trying to read and put the values into arrrays.
It's for my 3d engine I-Scream. Model importer.

I'm haveing alot of trouble reading it sometimes I get the right variables and sometimes not.
I need them all to be place into either a float or integer array.

Format is as so...

X Y Z U V  so that's four arrays times the number of vertexes told at the top.

Then vertex connection data or vertexs that make up the tri's polygons.

I am haveing trouble reading these values and comeing up with the identical way to move through it and also
comeing up with identical numbers.  I tried for 4 hours and I think I need help at this point.

So if anyone know how or can help code something up it would be greatly appreciated.

Thanks


*********************************
Sorry, don't need help anymore.
I finally figured it out.
Thanks anyways!





kevin

 
 If it's a text format, load the entire file to a bank (See readmemory), grab the bank as a string and split it to an array (See SplitToArray).   For each vertex,  grab the line and split it that to an array, and do the same for each face.    The SplitToArray command with grab the numeric values and convert them into whatever the destination array type is.  So if the destination array is a float array, it'll convert the row of 5 string fragments into 5 floating point values.  


 Had a quick go and got this (picture1),


Edit #2:

   After lunch, the mesh is stored as triangle pairs, so a pair of triangles, assuming all faces are stored like this we can compressed the tris to quads.. So did that and a back face removal and we get picture #2.  
 

Edit #3:

   The third picture shows the visible faces posted sorting and rendered as gouruad shaded quads.  There's an issue with the z order at certain angles, as when large outter faces occlude smaller inner faces the average depth of the outter face can be smaller than the inner face..


   Links:

    -- Split TO Array



ScottieB

Kevin - I was able to read the file but I also was haveing trouble with sorting.
I gave up when I could'nt texturemap it correctly.
I like your pics of backface removal I did'nt do that.
Could I have a copy of your programs.  What you have so far.
Kevin - to be honest with you I've been working on a 3d engine for 8 months now for playbasic and I stuck
now when it comes to texturemapping the models that I load in.
It still is a remake of atari's 1980's battlzone and it stands to say that it's still a game for it's time.
I was just hopeing I could push the engine a bit more.
I do need the help it's just I don't know if I should drop it and move on or continue to improve it not knowing how to do some things.
I could always release it as a game but I does have potential for a playbasic 3d engine. (Purely Playbasic) Right now.

ScottieB

Kevin thanks for the demo and I'm working on an importer for the game now.
I was wondering if you could explain the hiddel surface removal to me?
I would like to implement this in the future version.

Thanks
ScottieB

ScottieB

Kevin can you please have a look at my model importer.
Somethings wrong I think it's the z-depth thingy you were saying.
How can I get around this?

BlinkOk

you would make things a hell of a lot easier on everyone if you published the source code kevin

ScottieB

#6
BlinkOk His code is in the source code section.

There seems to be holes in the model by this picture.

BlinkOk

i know but there are a lot of other topics where he has not posted code. it's just counter productive not to post the code

ScottieB

Must be busy on other things of his own.

It look like some tri's are still over writeing others even with depth sorting.
Maybe if kevin shows me hidden surface removal it will help.

At least I've got the models loaded in now.  Though I know it still needs work.

ScottieB

Well, Here's backface removal now...

Something is still fishy though?

Kevin can you help?


ScottieB

#10
There's the code.

Now, Here is a pic.

kevin


  If you're going to post pictures at least use compressed format like PNG, JPG.. 

  Here's a slightly cleaner version of your code.

PlayBASIC Code: [Select]
X_Screen_Res = GetScreenWidth()
Y_Screen_Res = GetScreenHeight()


ReadFile "new_tank_01_UV.txt",1

Number_Of_Vertexs = Val(ReadString$(1))

Dim X_Vertex#(Number_Of_Vertexs)
Dim Y_Vertex#(Number_Of_Vertexs)
Dim Z_Vertex#(Number_Of_Vertexs)

Dim U_Vertex#(Number_Of_Vertexs)
Dim V_Vertex#(Number_Of_Vertexs)

Dim X_Scale#(Number_Of_Vertexs)
Dim Y_Scale#(Number_Of_Vertexs)
Dim Z_Scale#(Number_Of_Vertexs)

Dim X_Yaw#(Number_Of_Vertexs)
Dim Y_Yaw#(Number_Of_Vertexs)
Dim Z_Yaw#(Number_Of_Vertexs)

Dim X_Pitch#(Number_Of_Vertexs)
Dim Y_Pitch#(Number_Of_Vertexs)
Dim Z_Pitch#(Number_Of_Vertexs)

Dim X_Roll#(Number_Of_Vertexs)
Dim Y_Roll#(Number_Of_Vertexs)
Dim Z_Roll#(Number_Of_Vertexs)

Dim X2D_Vertex#(Number_Of_Vertexs)
Dim Y2D_Vertex#(Number_Of_Vertexs)
Dim Z2D_Vertex#(Number_Of_Vertexs)

dim Values#(5)
dim Values(5)

TextureWidth=512
TextureHeight=512
For Vertexs = 1 To Number_Of_Vertexs
String$ = ReadString$(1)
Count=SplitToArray(String$," ",Values#())
if Count=5
X_Vertex#(Vertexs)=Values#(0)
Y_Vertex#(Vertexs)=Values#(1)
Z_Vertex#(Vertexs)=Values#(2)
U_Vertex#(Vertexs)=Values#(3)*TextureWidth
V_Vertex#(Vertexs)=Values#(4)*TextureHeight
else
#print "Error reading Vertex #"+str$(Vertexs)
endif
next



/*
What is this ????????????????????????????


For Vertexs = 1 To Number_Of_Vertexs

String$ = ReadString$(1)
Lenght_Of_String = Len(String$)

L = 1

For Lenght = L To Lenght_Of_String

Check$ = Cutleft$(Left$(String$,Lenght),Lenght - 1)

If Check$ = Chr$(32) Then L = Lenght + 1:Goto Done_1

X_Vertex#(Vertexs) = Val#(Left$(String$,Lenght))

Next Lenght

Done_1:

For Lenght = L To Lenght_Of_String

Check$ = Cutleft$(Left$(String$,Lenght),Lenght - 1)

If Check$ = Chr$(32) Then L = Lenght + 1:Goto Done_2

Y_Vertex#(Vertexs) = Val#(CutLeft$(Left$(String$,Lenght),L - 1))

Next Lenght

Done_2:

For Lenght = L To Lenght_Of_String

Check$ = Cutleft$(Left$(String$,Lenght),Lenght - 1)

If Check$ = Chr$(32) Then L = Lenght + 1:Goto Done_3

Z_Vertex#(Vertexs) = Val#(CutLeft$(Left$(String$,Lenght),L - 1))

Next Lenght

Done_3:

For Lenght = L To Lenght_Of_String

Check$ = Cutleft$(Left$(String$,Lenght),Lenght - 1)

If Check$ = Chr$(32) Then L = Lenght + 1:Goto Done_4

U_Vertex#(Vertexs) = WrapValue(Val#(CutLeft$(Left$(String$,Lenght),L - 1)) * 512,0,511)

Next Lenght

Done_4:

For Lenght = L To Lenght_Of_String

V_Vertex#(Vertexs) = WrapValue(Val#(CutLeft$(Left$(String$,Lenght),L - 1)) * 512,0,511)

Next Lenght

Next Vertexs


*/



Number_Of_Tris = Val(ReadString$(1))

Dim P1(Number_Of_Tris)
Dim P2(Number_Of_Tris)
Dim P3(Number_Of_Tris)

;Dim Old_Z#(Number_Of_Tris)
;Dim New_Z#(Number_Of_Tris)

;Dim Poly_List(Number_Of_Tris)

;Dim UX#(Number_Of_Tris)
;Dim UY#(Number_Of_Tris)
;Dim UZ#(Number_Of_Tris)

;Dim VX#(Number_Of_Tris)
;Dim VY#(Number_Of_Tris)
;Dim VZ#(Number_Of_Tris)

;Dim NX#(Number_Of_Tris)
Login required to view complete source code

ScottieB

#12
Thanks kevin that looks alot better.

Would you know how I could get the texturemap working?

Here it is.


ScottieB

Do you know what's the slight bug while it's rotatateing?

Also is there a way to get flat shaded polygons?

ScottieB

#14
Got Texturemapping working.
I had to flip UV's.

BlinkOk - Care to color the first tank?
Here is the new model and texturemap.

BlinkOk - Your models are working but some some are not centered about 0,0,0
And I think it would be better if we had all tris and no missing planes.
That will come in handy for lighting later.