Здравствуйте, кто может помочь подправить скрипт? кого не искал никто не разбирается
Часть моделей открывает нормально, а часть наполовину, с потерей груп/полигонов
Часть моделей открывает нормально, а часть наполовину, с потерей груп/полигонов
if (heapSize < 200000) then
heapSize = 2000000 -- allow ~ 90 MB instead of just 7.5 MB. Prevents "Runtime Error: Out of scripter memory"
fname = getOpenFileName \
caption:"Open .mesh from Mesh folder" \
types:"MLB Models (*.dat;*.dfont)|*.dat;*.dfont" \
historyCategory:"MLBObjectPresets"
f = fopen fname "rb"
clearlistener()
fn ReadHalfFloat fstream =
(
hf=readshort fstream
sign = bit.get hf 16
exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
fraction = bit.and hf (bit.hexasint "03FF")
if sign==true then sign = 1 else sign = 0
exponentF = exponent + 127
outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
(bit.shift exponentF 23)) (bit.shift sign 31)
return bit.intasfloat outputasfloat*2
)
fn readFixedString bstream fixedLen = (
local str = ""
for i = 1 to fixedLen do (
str += bit.intAsChar (ReadByte bstream #unsigned))
str
)
struct weight_data
(
boneids,weights
)
struct Mesh_Info_Struct
(
VertexCount, FaceCount, VertexId,UsedBones, VertexEnd,Vsize
)
clearlistener()
CheckFile=readshort f
if CheckFile!=0 then fclose f
if CheckFile==0 then (
MshCount=readlong f
for i = 1 to MshCount do (--MshCount do (
try (
vertArray = #()
Facearray = #()
UV_array = #()
Weight_array=#()
MeshId=readshort f
FaceSecSize=readlong f
FaceSize=readlong f
Print ("Face Start @ 0x"+((bit.intAsHex(ftell f))as string))
for x=1 to (FaceSecSize/6)do (
fa = (readshort f #unsigned) + 1
fb = (readshort f #unsigned) + 1
fc = (readshort f #unsigned) + 1
append faceArray [fa,fb,fc]
)
VertexSecSize=readlong f
VertexSize=readlong f
Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell f))as string))
if VertexSize==72 then
for x = 1 to (VertexSecSize/VertexSize) do (
getPos = ftell f + VertexSize
vx = ReadFloat f
vy = ReadFloat f
vz = ReadFloat f
tu=Readfloat f
tv=Readfloat f *-1
fseek f 0x24 #seek_cur
bone1 = readbyte f #unsigned
bone2 = readbyte f #unsigned
bone3 = readbyte f #unsigned
bone4 = readbyte f #unsigned
weight1 = ReadFloat f
weight2 = ReadFloat f
weight3 = ReadFloat f
weight4 = ReadFloat f
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
maxweight = maxweight + weight1
if(weight2 != 0) then
maxweight = maxweight + weight2
if(weight3 != 0) then
maxweight = maxweight + weight3
if(weight4 != 0) then
maxweight = maxweight + weight4
if(maxweight != 0) then (
if(weight1 != 0) then (
w1 = weight1 as float
append w.boneids (bone1 + 1)
append w.weights (w1)
)
if(weight2 != 0) then (
w2 = weight2 as float
append w.boneids (bone2 + 1)
append w.weights (w2)
)
if(weight3 != 0) then (
w3 = weight3 as float
append w.boneids (bone3 + 1)
append w.weights (w3)
)
if(weight4 != 0) then (
w4 = weight4 as float
append w.boneids (bone4 + 1)
append w.weights (w4)
)
)
append Weight_array w
fseek f getPos #seek_set
append vertArray [vx,vy,vz]
append UV_array [tu,tv,0]
)
if VertexSize==56 then
for x = 1 to (VertexSecSize/56) do (
getPos = ftell f + 56
vx = ReadFloat f
vy = ReadFloat f
vz = ReadFloat f
tu=Readfloat f
tv=Readfloat f *-1
fseek f getPos #seek_set
append vertArray [vx,vy,vz]
append UV_array [tu,tv,0]
)
if VertexSize==32 then
for x = 1 to (VertexSecSize/32) do (
getPos = ftell f + 32
vx = ReadHalfFloat f
vy = ReadHalfFloat f
vz = ReadHalfFloat f
Unk = ReadShort f
tu=Readfloat f
tv=Readfloat f *-1
fseek f 0x4 #seek_cur
bone1 = readbyte f #unsigned
bone2 = readbyte f #unsigned
bone3 = readbyte f #unsigned
bone4 = readbyte f #unsigned
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
weight3 = readbyte f #unsigned
weight4 = readbyte f #unsigned
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
maxweight = maxweight + weight1
if(weight2 != 0) then
maxweight = maxweight + weight2
if(weight3 != 0) then
maxweight = maxweight + weight3
if(weight4 != 0) then
maxweight = maxweight + weight4
if(maxweight != 0) then (
if(weight1 != 0) then (
w1 = weight1 as float
append w.boneids (bone1 + 1)
append w.weights (w1/255.0)
)
if(weight2 != 0) then (
w2 = weight2 as float
append w.boneids (bone2 + 1)
append w.weights (w2/255.0)
)
if(weight3 != 0) then (
w3 = weight3 as float
append w.boneids (bone3 + 1)
append w.weights (w3/255.0)
)
if(weight4 != 0) then (
w4 = weight4 as float
append w.boneids (bone4 + 1)
append w.weights (w4/255.0)
)
)
append Weight_array w
fseek f getPos #seek_set
append vertArray [vx,vy,vz]
append UV_array [tu,tv,0]
)
if VertexSize==24 then
for x = 1 to (VertexSecSize/24) do (
getPos = ftell f + 24
vx = ReadHalfFloat f
vy = ReadHalfFloat f
vz = ReadHalfFloat f
Unk = ReadShort f
tu=ReadHalfFloat f
tv=ReadHalfFloat f*-1
fseek f getPos #seek_set
append vertArray [vx,vy,vz]
append UV_array [tu,tv,0]
)
Print ("Vertex End @ 0x"+((bit.intAsHex(ftell f))as string))
Null=readlong f
MNameSize=(readbyte f#unsigned-192)
MeshName=readFixedString f MNameSize
Unk=readshort f
if VertexSize==24 then fseek f 0x80 #seek_cur
if VertexSize==56 then fseek f 0x80 #seek_cur
Print ("MeshInfo End @ 0x"+((bit.intAsHex(ftell f))as string))
if VertexSize==32 then (
fseek f 0x68 #seek_cur
BoneCount=readlong f
BoneNameArray=#()
for i=1 to BoneCount do (
NameSize=(readbyte f#unsigned-192)
BoneName=readFixedString f NameSize
append BoneNameArray BoneName
)
Print ("BoneName End @ 0x"+((bit.intAsHex(ftell f))as string))
BoneCount=readlong f
BNArr=#()
Print ("Bone Start @ 0x"+((bit.intAsHex(ftell f))as string))
for i = 1 to BoneCount do(
m11=readfloat f ; m12=readfloat f ; m13=readfloat f; m14=readfloat f;
m21=readfloat f ; m22=readfloat f ; m23=readfloat f; m24=readfloat f;
m31=readfloat f ; m32=readfloat f ; m33=readfloat f*-1; m34=readfloat f;
sx = ReadFloat f; sy = ReadFloat f; sz = ReadFloat f
)
Print ("Bone End @ 0x"+((bit.intAsHex(ftell f))as string))
fseek f 0x28 #seek_cur
)
if VertexSize==72 then (
fseek f 0x68 #seek_cur
BoneCount=readlong f
BoneNameArray=#()
for i=1 to BoneCount do (
NameSize=(readbyte f#unsigned-192)
BoneName=readFixedString f NameSize
append BoneNameArray BoneName
)
Print ("BoneName End @ 0x"+((bit.intAsHex(ftell f))as string))
BoneCount=readlong f
BNArr=#()
Print ("Bone Start @ 0x"+((bit.intAsHex(ftell f))as string))
for i = 1 to BoneCount do(
m11=readfloat f ; m12=readfloat f ; m13=readfloat f; m14=readfloat f;
m21=readfloat f ; m22=readfloat f ; m23=readfloat f; m24=readfloat f;
m31=readfloat f ; m32=readfloat f ; m33=readfloat f*-1; m34=readfloat f;
sx = ReadFloat f; sy = ReadFloat f; sz = ReadFloat f
)
Print ("Bone End @ 0x"+((bit.intAsHex(ftell f))as string))
fseek f 0x28 #seek_cur
)
--print "qqq"
--print vertArray
--print "rrr"
try(
msh = mesh vertices:vertArray faces:faceArray
msh.name=MeshName
msh.numTVerts = UV_array.count
buildTVFaces msh
for j = 1 to UV_array.count do setTVert msh j UV_array[j]
for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
msh.displayByLayer = false
msh.backfacecull = false
msh.wirecolor = (color 230 200 210)
)catch(format "failed!!\n")
) catch "Error!"
)
)
fclose f
heapSize = 2000000 -- allow ~ 90 MB instead of just 7.5 MB. Prevents "Runtime Error: Out of scripter memory"
fname = getOpenFileName \
caption:"Open .mesh from Mesh folder" \
types:"MLB Models (*.dat;*.dfont)|*.dat;*.dfont" \
historyCategory:"MLBObjectPresets"
f = fopen fname "rb"
clearlistener()
fn ReadHalfFloat fstream =
(
hf=readshort fstream
sign = bit.get hf 16
exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
fraction = bit.and hf (bit.hexasint "03FF")
if sign==true then sign = 1 else sign = 0
exponentF = exponent + 127
outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
(bit.shift exponentF 23)) (bit.shift sign 31)
return bit.intasfloat outputasfloat*2
)
fn readFixedString bstream fixedLen = (
local str = ""
for i = 1 to fixedLen do (
str += bit.intAsChar (ReadByte bstream #unsigned))
str
)
struct weight_data
(
boneids,weights
)
struct Mesh_Info_Struct
(
VertexCount, FaceCount, VertexId,UsedBones, VertexEnd,Vsize
)
clearlistener()
CheckFile=readshort f
if CheckFile!=0 then fclose f
if CheckFile==0 then (
MshCount=readlong f
for i = 1 to MshCount do (--MshCount do (
try (
vertArray = #()
Facearray = #()
UV_array = #()
Weight_array=#()
MeshId=readshort f
FaceSecSize=readlong f
FaceSize=readlong f
Print ("Face Start @ 0x"+((bit.intAsHex(ftell f))as string))
for x=1 to (FaceSecSize/6)do (
fa = (readshort f #unsigned) + 1
fb = (readshort f #unsigned) + 1
fc = (readshort f #unsigned) + 1
append faceArray [fa,fb,fc]
)
VertexSecSize=readlong f
VertexSize=readlong f
Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell f))as string))
if VertexSize==72 then
for x = 1 to (VertexSecSize/VertexSize) do (
getPos = ftell f + VertexSize
vx = ReadFloat f
vy = ReadFloat f
vz = ReadFloat f
tu=Readfloat f
tv=Readfloat f *-1
fseek f 0x24 #seek_cur
bone1 = readbyte f #unsigned
bone2 = readbyte f #unsigned
bone3 = readbyte f #unsigned
bone4 = readbyte f #unsigned
weight1 = ReadFloat f
weight2 = ReadFloat f
weight3 = ReadFloat f
weight4 = ReadFloat f
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
maxweight = maxweight + weight1
if(weight2 != 0) then
maxweight = maxweight + weight2
if(weight3 != 0) then
maxweight = maxweight + weight3
if(weight4 != 0) then
maxweight = maxweight + weight4
if(maxweight != 0) then (
if(weight1 != 0) then (
w1 = weight1 as float
append w.boneids (bone1 + 1)
append w.weights (w1)
)
if(weight2 != 0) then (
w2 = weight2 as float
append w.boneids (bone2 + 1)
append w.weights (w2)
)
if(weight3 != 0) then (
w3 = weight3 as float
append w.boneids (bone3 + 1)
append w.weights (w3)
)
if(weight4 != 0) then (
w4 = weight4 as float
append w.boneids (bone4 + 1)
append w.weights (w4)
)
)
append Weight_array w
fseek f getPos #seek_set
append vertArray [vx,vy,vz]
append UV_array [tu,tv,0]
)
if VertexSize==56 then
for x = 1 to (VertexSecSize/56) do (
getPos = ftell f + 56
vx = ReadFloat f
vy = ReadFloat f
vz = ReadFloat f
tu=Readfloat f
tv=Readfloat f *-1
fseek f getPos #seek_set
append vertArray [vx,vy,vz]
append UV_array [tu,tv,0]
)
if VertexSize==32 then
for x = 1 to (VertexSecSize/32) do (
getPos = ftell f + 32
vx = ReadHalfFloat f
vy = ReadHalfFloat f
vz = ReadHalfFloat f
Unk = ReadShort f
tu=Readfloat f
tv=Readfloat f *-1
fseek f 0x4 #seek_cur
bone1 = readbyte f #unsigned
bone2 = readbyte f #unsigned
bone3 = readbyte f #unsigned
bone4 = readbyte f #unsigned
weight1 = readbyte f #unsigned
weight2 = readbyte f #unsigned
weight3 = readbyte f #unsigned
weight4 = readbyte f #unsigned
w = (weight_data boneids:#() weights:#())
maxweight = 0
if(weight1 != 0) then
maxweight = maxweight + weight1
if(weight2 != 0) then
maxweight = maxweight + weight2
if(weight3 != 0) then
maxweight = maxweight + weight3
if(weight4 != 0) then
maxweight = maxweight + weight4
if(maxweight != 0) then (
if(weight1 != 0) then (
w1 = weight1 as float
append w.boneids (bone1 + 1)
append w.weights (w1/255.0)
)
if(weight2 != 0) then (
w2 = weight2 as float
append w.boneids (bone2 + 1)
append w.weights (w2/255.0)
)
if(weight3 != 0) then (
w3 = weight3 as float
append w.boneids (bone3 + 1)
append w.weights (w3/255.0)
)
if(weight4 != 0) then (
w4 = weight4 as float
append w.boneids (bone4 + 1)
append w.weights (w4/255.0)
)
)
append Weight_array w
fseek f getPos #seek_set
append vertArray [vx,vy,vz]
append UV_array [tu,tv,0]
)
if VertexSize==24 then
for x = 1 to (VertexSecSize/24) do (
getPos = ftell f + 24
vx = ReadHalfFloat f
vy = ReadHalfFloat f
vz = ReadHalfFloat f
Unk = ReadShort f
tu=ReadHalfFloat f
tv=ReadHalfFloat f*-1
fseek f getPos #seek_set
append vertArray [vx,vy,vz]
append UV_array [tu,tv,0]
)
Print ("Vertex End @ 0x"+((bit.intAsHex(ftell f))as string))
Null=readlong f
MNameSize=(readbyte f#unsigned-192)
MeshName=readFixedString f MNameSize
Unk=readshort f
if VertexSize==24 then fseek f 0x80 #seek_cur
if VertexSize==56 then fseek f 0x80 #seek_cur
Print ("MeshInfo End @ 0x"+((bit.intAsHex(ftell f))as string))
if VertexSize==32 then (
fseek f 0x68 #seek_cur
BoneCount=readlong f
BoneNameArray=#()
for i=1 to BoneCount do (
NameSize=(readbyte f#unsigned-192)
BoneName=readFixedString f NameSize
append BoneNameArray BoneName
)
Print ("BoneName End @ 0x"+((bit.intAsHex(ftell f))as string))
BoneCount=readlong f
BNArr=#()
Print ("Bone Start @ 0x"+((bit.intAsHex(ftell f))as string))
for i = 1 to BoneCount do(
m11=readfloat f ; m12=readfloat f ; m13=readfloat f; m14=readfloat f;
m21=readfloat f ; m22=readfloat f ; m23=readfloat f; m24=readfloat f;
m31=readfloat f ; m32=readfloat f ; m33=readfloat f*-1; m34=readfloat f;
sx = ReadFloat f; sy = ReadFloat f; sz = ReadFloat f
)
Print ("Bone End @ 0x"+((bit.intAsHex(ftell f))as string))
fseek f 0x28 #seek_cur
)
if VertexSize==72 then (
fseek f 0x68 #seek_cur
BoneCount=readlong f
BoneNameArray=#()
for i=1 to BoneCount do (
NameSize=(readbyte f#unsigned-192)
BoneName=readFixedString f NameSize
append BoneNameArray BoneName
)
Print ("BoneName End @ 0x"+((bit.intAsHex(ftell f))as string))
BoneCount=readlong f
BNArr=#()
Print ("Bone Start @ 0x"+((bit.intAsHex(ftell f))as string))
for i = 1 to BoneCount do(
m11=readfloat f ; m12=readfloat f ; m13=readfloat f; m14=readfloat f;
m21=readfloat f ; m22=readfloat f ; m23=readfloat f; m24=readfloat f;
m31=readfloat f ; m32=readfloat f ; m33=readfloat f*-1; m34=readfloat f;
sx = ReadFloat f; sy = ReadFloat f; sz = ReadFloat f
)
Print ("Bone End @ 0x"+((bit.intAsHex(ftell f))as string))
fseek f 0x28 #seek_cur
)
--print "qqq"
--print vertArray
--print "rrr"
try(
msh = mesh vertices:vertArray faces:faceArray
msh.name=MeshName
msh.numTVerts = UV_array.count
buildTVFaces msh
for j = 1 to UV_array.count do setTVert msh j UV_array[j]
for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
msh.displayByLayer = false
msh.backfacecull = false
msh.wirecolor = (color 230 200 210)
)catch(format "failed!!\n")
) catch "Error!"
)
)
fclose f
Вложения
-
1,6 МБ Просмотров: 217