Notifications
Clear all

[Closed] Problem loading model


in_name =("C:\Documents and Settings\***\Työpöytä\SupCom3DFormats\SupComSCM_lod0.scm")

in_file = fopen in_name "rb"

Struct SCM_Head --Holds the head data of file
(

fourcc,

version,

boneoffset,

wbonecount,

vertoffset,

extraoffset,

vertcount,

triindexoffset,

triindexcount,

infooffset,

infocount,

totalbones,

tricount,



fn LoadHeadFromStream binstream= --Load model data

(

fourcc = ReadFixedString binstream 4

version = ReadLong binstream

boneoffset = ReadLong binstream

wbonecount = ReadLong binstream

vertoffset = ReadLong binstream

extraoffset = ReadLong binstream

vertcount = ReadLong binstream

triindexoffset = ReadLong binstream

triindexcount = ReadLong binstream

infooffset = ReadLong binstream

infocount = ReadLong binstream

totalbones = ReadLong binstream

tricount = (triindexcount / 3)

),



Struct SCM_Vert --Holds Vertex data

(

Position,

Normal,

Tangent,

Binormal,

UV0,

UV1,

BoneIndex,



fn LoadVertFromStream binstream= ---Loads Vertex data

(

local x = ReadFloat binstream

local y = ReadFloat binstream

local z = ReadFloat binstream

Position = [x, y, z]

local x = ReadFloat binstream

local y = ReadFloat binstream

local z = ReadFloat binstream

Normal = [x, y, z]

local x = ReadFloat binstream

local y = ReadFloat binstream

local z = ReadFloat binstream

Tangent = [x, y, z]

local x = ReadFloat binstream

local y = ReadFloat binstream

local z = ReadFloat binstream

Binormal = [x, y, z]

local u = ReadFloat binstream

local v = ReadFloat binstream

UV0 = [u, v, 0]

local u = ReadFloat binstream

local v = ReadFloat binstream

UV1 = [u, v, 0]

local x = Readbyte binstream #unsigned

local y = Readbyte binstream #unsigned

local z = Readbyte binstream #unsigned

local w = Readbyte binstream #unsigned

BoneIndex = [x, y, z, w]

)

)

Struct SCM_Tri --Holds faces data

(

triindex,

fn LoadTriFromStream binstream= ---Loads face data

(

local x = Readshort binstream

local y = Readshort binstream

local z = Readshort binstream

triindex = [x, y, z]

)

)

ifin_file !=undefined then

(

vertlistarray = #() --There is loaded and held SCM_Vert structure

trilistarray = #() --And there is loaded and held SCM_Tri structure

vertarray = #() --There is loaded SCM_Verts position data

triarray = #() --There is loaded SCM_Tri triindex data



ihead = SCM_Head() --Instance of SCM_Head

ivert = SCM_Vert() --Instance of SCM_Vert

itri = SCM_Tri() --Instance of SCM_Tri



ihead.LoadHeadFromStream in_file --First we read Head data and fill Structures variables



vertlistarray.count = ihead.vertcount --Define size of vertlistarray

trilistarray.count = ihead.tricount --Define size of trilistarray



fseek in_file ihead.vertoffset #seek_set--Seek to vertex dataoffset in stream

for i = 1 to ihead.vertcount do---Loop for filling vertlistarray with SCM_Vert structures

(

ivert.LoadVertFromStream in_file

append vertlistarray (copy ivert) --Copy structure to vertlistarray

)



fseek in_file ihead.triindexoffset #seek_set--Seek to tri dataoffset in stream

for i = 1 to ihead.tricount do---Loop for filling trilistarray with SCM_Vert structures

(

itri.LoadTriFromStream in_file

append trilistarray (copy itri) --Copy structure to trilistarray

)



for i = 1 to ihead.vertcount do--Loop for filling vertarray with SCM_Vert structures postition

(

currentvert = vertlistarray[i].Position --HERE COMES ERROR: Unkown property: "position" in undefined

vertarray[i] = currentvert

)



for i = 1 to ihead.tricount do--Loop for filling triarray with SCM_Tri structures triindex

(

currenttri = trilistarray[i].triindex --HERE COMES ERROR: Unkown property: "triindex" in undefined

triarray[i] = currenttri

)



new_mesh = mesh vertices:vertarray faces:triarray --Create mesh

fclose in_file

)
 
 

I couldn’t figure out by my self whats wrong with my code. But it seems that arrays (vertlistarray and trilistarray) which holds vertex structures and tri structures are empty.
Program fails at filling those arrays but I dont know why.
I am trying to create a script that loads model from one model format.
(Supreme Commander scm file format ;D)
This is pretty chalenging to me.

9 Replies

from quick wiew i se one little mistake here:

Struct SCM_Head –Holds the head data of file
(
fourcc,
version,
boneoffset,
wbonecount,
vertoffset,
extraoffset,
vertcount,
triindexoffset,
triindexcount,
infooffset,
infocount,
totalbones,
tricount,
fn LoadHeadFromStream binstream= –Load model data
(
fourcc = ReadFixedString binstream 4
version = ReadLong binstream
boneoffset = ReadLong binstream
wbonecount = ReadLong binstream
vertoffset = ReadLong binstream
extraoffset = ReadLong binstream
vertcount = ReadLong binstream
triindexoffset = ReadLong binstream
triindexcount = ReadLong binstream
infooffset = ReadLong binstream
infocount = ReadLong binstream
totalbones = ReadLong binstream
tricount = (triindexcount / 3)
), –should not be there
– missing )

I removed one part of code for my post and forgot to add ) so its not the problem.

Hi,

I found :

ifin_file !=undefined then

Should be :

if in_file != undefined then

Also check your values using print method before filling the arrays to see what’s wrong, for example:

print (ihead.vertcount as string)

Wont work still gives same error. Arrays seem to be empty, filled with “undefined”. I cant see what’s wrong.

Debug your script using print (print a value in the listener) function to see what’s wrong. For example in your loops:

for i = 1 to ihead.vertcount do---Loop for filling vertlistarray with SCM_Vert structures
(
ivert.LoadVertFromStream in_file
print ivert
append vertlistarray (copy ivert) --Copy structure to vertlistarray
print vertlistarray
)
1 Reply
 eek
(@eek)
Joined: 2 years ago

Posts: 0

Are the variables in Ivert defined? eg:

 struct ivert 
(
a = 10,
b = 20,
c = 30,
)

Well this is interesting. When i print contents of vertlistarray it seems to be mostly filled with undefineds, but there are also on some parts of array where ivert structures are saved succesfully. Everything seems to be okay with “ivert.LoadVertFromStream in_file” when i use “print ivert”. Problem is this: “append vertlistarray (copy ivert)”. It appends structure to array some times but mostly it’s filled with undefined.

Hi,

Can you send a SCM file, or a link to a SCM file to run your script.

 eek

First off your calling, a fn in a struct using arrays in that struct so i’d instance the struct to declare the variables first.

 struct testStruct 
(
testVal,
 
fn testFn =
(
print testVal as string
),
endofstruct
)
 
 
testStruct01 = testStruct()
 
if testStruct01.testVal == undefined then
(
testStruct01.testVal = 10
 
for i = 1 to (testStruct01.testVal as integer) do
  (
   testStruct01.testFn() -- prints "10" ten times.
   )
)
 

what does ‘vertCount’ give you? is it a value or an array because if its an array your’ll need to add .count eg. for i = 1 to vertcount.count. If its a string in an array and you need its count eg… vertCount = #(“100”,“2000”) you can also do vertCount[1].count == 3, the count of the string.