Notifications
Clear all
[Closed] LWO TO MAX Beta
Feb 03, 2010 1:59 pm
Here i am for now, slow, but works !!!
supported for now:
geometry, curves, bones, basic materials, herarchy
Realy hate LightWave but this utility helps a lot. Try it.
ClearListener()
try destroydialog Test catch true
LWOname="D:\ tt.lwo"
max select all
max delete
------------------------------------------------------------------------------
----GLOBALS
------------------------------------------------------------------------------
if (int(heapsize))<550000000 then heapSize += 550000000
objectID=0
layerID=0
mul = units.decodeValue "1m" as float
LWOMATERIALS=#()
LAYR=#() --LayerArray
TagsArray=#() --TagsArray
PTagsArray=#() --PTagsArray
SurfArray=#() --Contains Surface numbers from ALL SURF PTAGS
PrimID=#("LAYR","PNTS","VMAP","POLS","TAGS","PTAG","_ENVL","_CLIP","SURF", \
"BBOX","_DESC","_TEXT","_ICON","VMAD")
------------------------------------------------------------------------------
----CLASSES
------------------------------------------------------------------------------
struct LwoFace (pointIndex=#())
struct LwoObj (Type="",Faces=#(),Ptags=#())
struct LwoUV (Uvname="",V_MAP=#(),V_MAD=#())
struct LwoLayer (Lnumber=0,Lflags=0,Lpivot=[0,0,0],Lname="",Lparent=-1,Lobjects=#(),Lpoints=#(),Luvs=#())
------------------------------------------------------------------------------
----INTERFACES
------------------------------------------------------------------------------
rollout Test "Progress" Width:320 height:710 (
label lbl "Chunk"
progressbar Test color:blue
edittext txt fieldWidth:300 height:500 labelOnTop:true
)
createdialog Test
fn materials=(
ClearListener()
mat=Standardmaterial ()
c=compositeTextureMap()
mat.diffuseMap = c
c.maplist.count=4
for x =1 to c.maplist.count do
(
m=Mask name:("Layer:"+(x as string))
m.map = Checker name:("Map:"+(x as string))
o=output name:("Opacity:"+(x as string))
o.output.Output_Amount = 0.81 ---set opacity
m.Mask = o
c.maplist[x]=m
)
meditMaterials[1]=mat
)
------------------------------------------------------------------------------
----Big to little indean convertion
------------------------------------------------------------------------------
fn swapshort short = bit.swapBytes short 1 2
------------------------------------------------------------------------------
fn swaplong long =(
long = bit.swapBytes long 1 4
long = bit.swapBytes long 2 3
)
------------------------------------------------------------------------------
----LW DATA TYPES
------------------------------------------------------------------------------
fn GetID4 BinStrm =((bit.intAsChar (readbyte BinStrm)+bit.intAsChar (readbyte BinStrm)+bit.intAsChar (readbyte BinStrm)+bit.intAsChar (readbyte BinStrm)))
fn GetI1 BinStrm =(readbyte BinStrm #signed)
fn GetI2 BinStrm =(swapshort(readshort BinStrm #signed))
fn GetI4 BinStrm =(swaplong(readlong BinStrm #signed))
fn GetU1 BinStrm =(readbyte BinStrm #unsigned)
fn GetU2 BinStrm =(swapshort(readshort BinStrm #unsigned))
fn GetU4 BinStrm =(swaplong(readlong BinStrm #unsigned))
fn GetF4 BinStrm =(bit.intAsFloat (GetI4 BinStrm))
fn GetS0 BinStrm =
(
local filevalue = readstring BinStrm
--if (bit.and (ftell BinStrm) 1) ==1 then fseek BinStrm -1 #seek_cur
(filevalue as string)
)
fn GetVEC12 BinStrm =([(GetF4 BinStrm)*mul,(GetF4 BinStrm)*mul,(GetF4 BinStrm)*mul])
fn GetVX BinStrm =(
local oldftell = ftell BinStrm
local filevalue=(GetU2 Binstrm)
if filevalue > 65279 then (
fseek BinStrm oldftell #seek_set
filevalue=bit.shift (bit.shift (GetU4 Binstrm) 8) -8
)
filevalue
)
fn GetCOL12 BinStrm =(GetVEC12 BinStrm)
fn GetFP4 BinStrm =(GetF4 BinStrm)
fn GetANG4 BinStrm =(GetF4 BinStrm)
fn GetFNAM BinStrm =(GetS0 BinStrm)
------------------------------------------------------------------------------
----READINGZ
------------------------------------------------------------------------------
---------------------------------------------------------------------MAIN INFO--------------------------------------------------------------------------
fn Read_MAIN BinStrm = (
fseek BinStrm 0 #seek_set
local CHchunk =GetID4 BinStrm
local Chunk_Length =GetU4 BinStrm
local Chunk_Tag =GetID4 BinStrm
#(CHchunk,Chunk_Length,Chunk_Tag)
)
--------------------------------------------------------------------CHUNK NAME AND LENGTH
fn Read_ID BinStrm p= (
fseek BinStrm p #seek_set
local Chunk_Tag=GetID4 BinStrm
local Chunk_Length =GetU4 BinStrm
#(Chunk_Tag,Chunk_Length)
)
--------------------------------------------------------------------SUB_CHUNK NAME AND LENGTH
fn Read_SubChunkID BinStrm = (
local Chunk_Tag=GetID4 BinStrm
local Chunk_Length =GetU2 BinStrm
#(Chunk_Tag,Chunk_Length)
)
---------------------------------------------------------------------TAGS
fn Read_TAGS BinStrm p=(
Test.lbl.caption="TAGS"
Test.Test.value =0.0
fseek BinStrm (p-4) #seek_set
local Chunk_Length = GetU4 BinStrm
local filevalue=#()
local xxx=""
for i = 1 to Chunk_Length do
(
local tempVal = readbyte BinStrm
if tempVal !=0 then xxx=xxx+(bit.intAsChar tempVal) else
(
if xxx!="" then append filevalue xxx
xxx=""
)
)
filevalue
)
---------------------------------------------------------------------LAYR
fn Read_LAYR BinStrm p=(
Test.Test.value =0.0
fseek BinStrm (p-4) #seek_set
local TempLayer=LwoLayer()
local Chunk_Length = GetU4 BinStrm
local oldftel= ftell BinStrm
TempLayer.Lnumber=((GetU2 BinStrm)+1)
TempLayer.Lflags=(GetU2 BinStrm)
TempLayer.Lpivot=(GetVEC12 BinStrm)
TempLayer.Lname=(GetS0 BinStrm)
oldftel=(ftell BinStrm)-oldftel+1
if oldftel < Chunk_Length then TempLayer.Lparent=(GetU2 BinStrm) else fseek BinStrm 1 #seek_cur
Test.txt.text+=("LAYER: "+((TempLayer.Lnumber) as string)+ "
"+"Name: "+(TempLayer.Lname as string)+"
"+"Pivot: "+(TempLayer.Lpivot as string)+"
")
fseek BinStrm (p+Chunk_Length) #seek_set
TempLayer
)
---------------------------------------------------------------------PNTS
fn Read_PNTS BinStrm p=(
Test.lbl.caption="Points "
Test.Test.value =0.0
fseek BinStrm (p-4) #seek_set
local Chunk_Length = (GetU4 BinStrm)/12
local LWOPoints=#()
for i = 1 to Chunk_Length do
(
Test.Test.value = 100.*i/Chunk_Length
Test.lbl.caption=("Points "+(i as string))
append LWOPoints (GetVEC12 BinStrm)
)
Test.txt.text+=("PointCount:"+(LWOPoints.count as string)+"
")
LWOPoints
)
---------------------------------------------------------------------BBOX
fn Read_BBOX BinStrm p=(
Test.lbl.caption="BoundingBox"
Test.Test.value =0.0
fseek BinStrm p #seek_set
local bbmin= GetVEC12 BinStrm
local bbmax= GetVEC12 BinStrm
Test.txt.text+=("Layer Bounding Box:
"+(bbmin as string)+"
"+(bbmax as string)+"
")
#(bbmin,bbmax)
)
---------------------------------------------------------------------POLS
fn Read_POLS BinStrm p=(
Test.lbl.caption="Polygons "
Test.Test.value =0.0
--INCREASE OBJ ID IDENTIFIER
fseek BinStrm (p-4) #seek_set
local Chunk_Length = GetU4 BinStrm
local oldftel= ftell BinStrm
local Chunk_Tag=GetID4 BinStrm
local tempFace=LwoFace()
local FACELIST=LwoObj()
local facecount=0
local endface=0 ---ITTERATE UNTILL ALL FACES ARE DONE
FACELIST.Type=Chunk_Tag
while endface != 1 do
(
local FPnts = bit.shift (bit.shift (GetU2 BinStrm) 6) -6 --GET POINTS COUNT
for i = 1 to FPnts do append tempFace.pointIndex ((GetVX BinStrm)+1) --FIX 0 BASED INDEXES
local ftl=ftell BinStrm
if ftl >=(p+Chunk_Length) then endface=1
append FACELIST.Faces tempFace
tempFace=LwoFace()
facecount=facecount+1
Test.lbl.caption=("Polygons "+(facecount as string)+"
")
Test.Test.value = 100.*(ftl-p)/Chunk_Length
)
Test.txt.text+=("Polygon Count: "+(facecount as string)+"
")
FACELIST
)
---------------------------------------------------------------------PTAG
fn Read_PTAG BinStrm p=(
Test.lbl.caption="Ptag"
Test.Test.value =0.0
fseek BinStrm (p-4) #seek_set
local Chunk_Length = GetU4 BinStrm
local filevalue=#()
local Chunk_Tag=GetID4 BinStrm
append filevalue Chunk_Tag
while (ftell BinStrm) <(p+Chunk_Length) do
(
append filevalue ((GetVX BinStrm)+1) --FIX 0 BASED INDEXES
local tempval=(GetU2 BinStrm)+1
append filevalue tempval --FIX 0 BASED INDEXES
if Chunk_Tag=="SURF"then appendIfUnique SurfArray tempval
Test.Test.value = 100.*((ftell BinStrm)-p)/Chunk_Length
)
filevalue
)
---------------------------------------------------------------------END PTAG
---------------------------------------------------------------------VMAP
-- VMAP 98
-- TXUV
-- 2
-- "UV Texture"
-- 0 0.125 0.0
-- 1 0.375 0.0
-- 2 0.125 1.0
-- 3 0.375 1.0
-- 4 0.625 0.0
-- 5 0.875 0.0
-- 6 0.625 1.0
-- 7 0.875 1.0
--VMAP { type[ID4], dimension[U2], name[S0],
--( vert[VX], value[F4] # dimension )* }
--PICK
--Selection set. This is a VMAP of dimension 0 that marks points for quick selection by name during modeling.
--WGHT
--Weight maps have a dimension of 1 and are generally used to alter the influence of deformers such as bones.
--Weights can be positive or negative, and the default weight for unmapped vertices is 0.0.
--MNVW
--Subpatch weight maps affect the shape of geometry created by subdivision patching.
--TXUV
--UV texture maps have a dimension of 2.
--RGB, RGBA
--Color maps, with a dimension of 3 or 4.
--MORF
--These contain vertex displacement deltas.
--SPOT
--These contain absolute vertex displacements (alternative vertex positions).
fn Read_VMAP BinStrm p=(
Test.lbl.caption="Vmap"
Test.Test.value = 0.0
local filevalue=LwoUV()
fseek BinStrm (p-4) #seek_set
local Chunk_Length = GetU4 BinStrm
local Chunk_Tag=GetID4 BinStrm
if Chunk_Tag =="TXUV" then (
uvDim= GetU2 BinStrm
uvName = GetS0 BinStrm
filevalue.uvName=uvName
while (ftell BinStrm) <(p+Chunk_Length) do (
idx = GetVX BinStrm
U = GetF4 BinStrm
V = GetF4 BinStrm
append filevalue.V_map idx
append filevalue.V_map u
append filevalue.V_map v
)
filevalue
)else (
fseek BinStrm (p+Chunk_Length) #seek_set -- Go to end of chunk
)
filevalue
)
---------------------------------------------------------------------END VMAP
---------------------------------------------------------------------VMAD
-- VMAD 42
-- TXUV
-- 2
-- "UV Texture"
-- 5 4 -0.125 0.0
-- 7 4 -0.125 1.0
--Each entry contains both a point and a polygon index.
--The seam in this case falls in the middle of polygon 4,
--and the VMAD says that when rendering any part of this polygon,
--the VMAP values for points 5 and 7 should be replaced with
--the ones in the VMAD for those points.
--Other polygons that share those points are unaffected by
--this replacement.
--VMADs were added to the file format with version 6.5 of LightWave.
--Although they will be used most often for UV mapping,
--they can be used to supplement other kinds of vertex mapping.
--They can also be applied without a corresponding VMAP
fn Read_VMAD BinStrm p=(
Test.lbl.caption="Vmad"
Test.Test.value = 0.0
local filevalue=LwoUV()
fseek BinStrm (p-4) #seek_set
local Chunk_Length = GetU4 BinStrm
local Chunk_Tag=GetID4 BinStrm
if Chunk_Tag =="TXUV" then (
uvDim= GetU2 BinStrm
uvName = GetS0 BinStrm
filevalue.uvName=uvName
while (ftell BinStrm) <(p+Chunk_Length) do (
pidx = GetVX BinStrm
fidx = GetVX BinStrm
U = GetF4 BinStrm
V = GetF4 BinStrm
append filevalue.V_MAD pidx --Pointindex
append filevalue.V_MAD fidx --Faceindex
append filevalue.V_MAD u
append filevalue.V_MAD v
)
filevalue
)else (
fseek BinStrm (p+Chunk_Length) #seek_set -- Go to end of chunk
)
filevalue
)
---------------------------------------------------------------------END VMAD
---------------------------------------------------------------------SURF
fn Read_SURF BinStrm p=
(
Test.lbl.caption="SURF"
Test.Test.value =0.0
local TempArray = #("SHRP","RBLR","TBLR","CLRH","CLRF","ADTR")
local oldftel=p
local TempSurf = Standardmaterial shaderName:"Translucent Shader" adTextureLock:on
fseek BinStrm (p-4) #seek_set
local Chunk_Length = GetU4 BinStrm
local SurfName=GetS0 BinStrm
local ParentSurfName=GetS0 BinStrm
if (bit.and (ftell BinStrm) 1) ==1 then fseek BinStrm -1 #seek_cur
if ParentSurfName=="" then fseek BinStrm 2 #seek_cur
TempSurf.name=SurfName
TempSurf.faceted = on
while (ftell BinStrM) < (oldftel+Chunk_Length) do
(
s=0
local SubChunk =Read_SubChunkID BinStrm
local SubChunkName = SubChunk[1] --SUBCHUNK NAME
local SubChunkSize = SubChunk[2] --SUBCHUNK SIZE
--print ("SubChunkName:"+(SubChunkName as string)+" Size:"+(SubChunkSize as string))
if (findItem TempArray SubChunk[1]) !=0 then
(
(GetFP4 BinStrm)
(GetVX BinStrm)
s=SubChunk[2]
)
if SubChunk[1]=="COLR" then
(
theColor=(255/(100/(GetVEC12 BinStrm))) as color
TempSurf.diffuse = theColor
(GetVX BinStrm)
s=SubChunk[2]
)
if SubChunk[1]=="SIDE" then (
if (GetU2 BinStrm) == 3 then TempSurf.twoSided = on else TempSurf.twoSided=off
s=SubChunk[2])-- Polygon Sidedness
if SubChunk[1]=="LUMI" then
(
TempSurf.useSelfIllumColor = off
TempSurf.selfIllumAmount =((GetFP4 BinStrm)*100)
(GetVX BinStrm)
s=SubChunk[2]
)
if SubChunk[1]=="DIFF" then
(
TempSurf.diffuseLevel = ((GetFP4 BinStrm)*100)
(GetVX BinStrm)
s=SubChunk[2]
)
if SubChunk[1]=="SPEC" then
(
TempSurf.specularLevel = ((GetFP4 BinStrm)*100)
(GetVX BinStrm)
s=SubChunk[2]
)
if SubChunk[1]=="REFL" then
(
TempSurf.reflectionMapAmount = ((GetFP4 BinStrm)*100)
(GetVX BinStrm)
s=SubChunk[2]
)
if SubChunk[1]=="TRAN" then
(
TempSurf.opacity = 100-((GetFP4 BinStrm)*100)
(GetVX BinStrm)
s=SubChunk[2]
)
if SubChunk[1]=="RIND" then
(
TempSurf.ior = (GetFP4 BinStrm)
(GetVX BinStrm)
s=SubChunk[2]
)
if SubChunk[1]=="BUMP" then
(
TempSurf.bumpMapAmount = ((GetFP4 BinStrm)*100)
(GetVX BinStrm)
s=SubChunk[2]
)
if SubChunk[1]=="GLOS" then
(
TempSurf.glossiness = ((GetFP4 BinStrm)*100)
(GetVX BinStrm)
s=SubChunk[2]
)
if SubChunk[1]=="TRNL" then
(
TempSurf.translucentColorMapAmount = ((GetFP4 BinStrm)*100)
TempSurf.translucentColorMap = RGB_Tint red:TempSurf.Diffuse green:TempSurf.Diffuse blue:TempSurf.Diffuse
(GetVX BinStrm)
s=SubChunk[2]
)
if SubChunk[1]=="RFOP" then (
rfop = (GetU2 BinStrm)
if rfop==1 or rfop==3 then TempSurf.reflectionMap = Raytrace ()
s=SubChunk[2])-- Reflection Options
if SubChunk[1]=="ALPH" then (
(GetU2 BinStrm)
(GetFP4 BinStrm)
s=SubChunk[2]
)-- Alpha Mode
if SubChunk[1]=="TROP" then (
(GetU4 BinStrm)
s=SubChunk[2]
)-- Transparency Options
if SubChunk[1]=="RIMG" then (
(GetVX BinStrm)
s=SubChunk[2]
)-- Reflection Map Image
if SubChunk[1]=="TIMG" then (
(GetVX BinStrm)
s=SubChunk[2]
)-- Refraction Map Image
if SubChunk[1]=="SMAN" then (
if (GetANG4 BinStrm)>0 then TempSurf.faceted = off
s=SubChunk[2]
)-- Max Smoothing Angle
if SubChunk[1]=="RSAN" then (
(GetANG4 BinStrm)
(GetVX BinStrm)
s=SubChunk[2]
)-- Reflection Map Image Seam Angle
fseek BinStrm (SubChunk[2]-s) #seek_cur
)
fseek BinStrm (p+Chunk_Length) #seek_set -- Go to end of chunk
TempSurf
)
---------------------------------------------------------------------END SURF
fn Read_ENVL BinStrm p=()
fn Read_CLIP BinStrm p=()
fn Read_DESC BinStrm p=()
fn Read_TEXT BinStrm p=()
fn Read_ICON BinStrm p=()
------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------MAIN-----------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------
f=fopen LWOname "rb"
lwofileinfo=Read_MAIN f
LWOSIZE=lwofileinfo[2]
clearListener()
while (ftell f) < LWOSIZE do
(
TEMPID=Read_ID f (ftell f)
testfn=findItem PrimID TEMPID[1]
if testfn ==0 then --SKIP
(
ft = (ftell f)
print (TEMPID[1]+" SKIP "+(TEMPID[2]as string)+" "+(ft as string))
fseek f TEMPID[2] #seek_cur
)
if testfn ==1 then --READ LYERS
(
layerID=layerID+1
objectID=0
append LAYR (Read_LAYR f (ftell f))
)
if testfn ==2 then --READ POINTS
(
LAYR[layerID].Lpoints=(Read_PNTS f (ftell f))
)
---------------------------------------------------------------------UV----------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------
if testfn ==3 then --VMAP LwoUV (LayerIndex=0,V_MAP=#(),V_MAD=#())
(
local temp=(Read_VMAP f (ftell f))
local xx=0
for i= 1 to Layr[LayerID].Luvs.count do
(
if Layr[LayerID].Luvs[i].uvname==temp.uvname then xx=i
)
if xx!=0 then Layr[LayerID].Luvs[xx].V_MAP=temp.V_MAP else append Layr[LayerID].Luvs temp
)
if testfn ==14 then --VMAD LwoUV (LayerIndex=0,V_MAP=#(),V_MAD=#())
(
local temp=(Read_VMAD f (ftell f))
local xx=0
for i= 1 to Layr[LayerID].Luvs.count do
(
if Layr[LayerID].Luvs[i].uvname==temp.uvname then xx=i
)
if xx!=0 then Layr[LayerID].Luvs[xx].V_MAD=temp.V_MAD else append Layr[LayerID].Luvs temp
)
---------------------------------------------------------------------END UV----------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------
if testfn ==4 then --READ POLY
(
objectID=objectID+1
append LAYR[layerID].Lobjects (Read_POLS f (ftell f))
)
if testfn ==5 then TagsArray = Read_TAGS f (ftell f)
if testfn ==6 then append LAYR[layerID].Lobjects[objectID].Ptags (Read_PTAG f (ftell f)) --READ PTAGS
if testfn ==9 then append LWOMATERIALS (Read_SURF f (ftell f))
--if testfn ==9 then Print(Read_SURF f (ftell f))
if testfn ==10 then Read_BBOX f (ftell f)
)
fclose f
Test.Test.value = 0.0
Test.lbl.caption="DONE"
-------------------UVTATAT SA TUK layr[1].Luvs.count
------------------------------------------------------------------------------
-------------------------------------RECONSTRUCT OBJECTS
------------------------------------------------------------------------------
----CREATION FLAGS
DoPolygons=true
DoBones=true
DoCurves=true
DoSurfaces=true
undo off (
------------------------------------------------------------------------------
-------------------------------------DO MULTIMATERIAL
------------------------------------------------------------------------------
--SurfArray contains material indexes in TagsArray
sort SurfArray
numMats=(SurfArray.count)
MatNamesArray=#()
for i = 1 to numMats do append MatNamesArray (TagsArray[SurfArray[i]])
--MatNamesArray contains materialnames from TagsArray
MultiMat = Multimaterial numsubs:numMats
MultiMat.names=MatNamesArray
MultiMat.name="LWO SURFACES"
for i = 1 to MultiMat.materiallist.count do (
--x=findItem MatNamesArray LWOMATERIALS[i].name
MultiMat.materiallist[i]=LWOMATERIALS[i]
)
--meditMaterials[1] = MultiMat
------------------------------------------------------------------------------
-------------------------------------END MULTIMATERIAL
------------------------------------------------------------------------------
for i = 1 to LAYR.count do
(
layername=""
layernumber =(LAYR[i].Lnumber) as string
layername=(LAYR[i].Lname) as string
theName=(layernumber+":"+layername)
layer=layermanager.newLayerFromName theName
if layer==undefined then layer=(layermanager.getLayerFromName theName)
layer.current = true
lpivot=Point()
lpivot.name=(layernumber+":LayerPivot")
lpivot.position=LAYR[i].Lpivot
for j = 1 to LAYR[i].Lobjects.count do
(
--LOCATE SURF,PART,BONE,BNUP in PTAG
SURFTAG=0
PARTTAG=0
BONETAG=0
BNUPTAG=0
for p = 1 to LAYR[i].Lobjects[j].Ptags.count do
(
if LAYR[i].Lobjects[j].Ptags[p] [1]=="SURF" then SURFTAG=p
if LAYR[i].Lobjects[j].Ptags[p] [1]=="PART" then PARTTAG=p
if LAYR[i].Lobjects[j].Ptags[p] [1]=="BONE" then BONETAG=p
if LAYR[i].Lobjects[j].Ptags[p] [1]=="BNUP" then BNUPTAG=p
)
------------------------------------------------------------------------------
-------------------------------------DO POLYGONS
------------------------------------------------------------------------------
if DoPolygons then (
Test.Test.value = 0.0
Test.lbl.caption=("Creating Layer:"+((LAYR[i].Lnumber)as string)+" Polygons")
local TheObjectType = (LAYR[i].Lobjects[j].Type) as string
local TheObjectName=""
if TheObjectType=="FACE" or TheObjectType=="PTCH" then
(
if TheObjectType=="FACE" then TheObjectName=(uniquename (layernumber+":Poly")) else TheObjectName=(uniquename (layernumber+":Subd"))
------CREATES EMPTY MESH
local TheObj=mesh vertices:LAYR[i].Lpoints faces:#()
TheObj.name=TheObjectName
TheObj.wirecolor=((random [10,10,10] [200,200,200])as color)
local ThePolyCount=LAYR[i].Lobjects[j].Faces.count
Test.lbl.caption=("Creating Layer:"+((LAYR[i].Lnumber)as string)+" Polygons:"+(ThePolyCount as string))
for k = 1 to ThePolyCount do --Iterate Faces
(
MatId=1
local indexCount = LAYR[i].Lobjects[j].Faces[k].PointIndex.count
--Creates Faces
local PolyMatId=(k*2)+1
PolyMatId=LAYR[i].Lobjects[j].Ptags[SURFTAG][PolyMatId]
MatId = (findItem SurfArray PolyMatId)
TheFaceArray=LAYR[i].Lobjects[j].Faces[k].PointIndex
meshop.createPolygon TheOBJ TheFaceArray matID:MatId
Test.Test.value = 100.*k/ThePolyCount
)
--meshop.deleteIsoVerts TheOBJ ---KILL ALL UNUSED POINTS
TheObj.material = MultiMat
TheOBJ.parent = lpivot
)
)
------------------------------------------------------------------------------
-------------------------------------END POLYGONS
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-------------------------------------CREATE CURVES
------------------------------------------------------------------------------
if DoCurves then (
if LAYR[i].Lobjects[j].Type=="CURV" then
(
local pc=0
for k = 1 to Layr[i].lobjects[j].faces.count do
(
TheOBJ = splineShape wirecolor:(red)
addNewSpline TheOBJ
for p = 1 to Layr[i].lobjects[j].faces[k].pointIndex.count do
(
local pointPos = Layr[i].lobjects[j].faces[k].pointIndex[p]
pointPos=Layr[i].lpoints[pointPos]
addKnot TheOBJ 1 #smooth #curve pointPos
)
updateshape TheOBJ
)
TheOBJ.parent = lpivot
)
)
------------------------------------------------------------------------------
-------------------------------------END CREATE CURVES
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-------------------------------------CREATE BONES
------------------------------------------------------------------------------
if DoBones then (
if LAYR[i].Lobjects[j].Type=="BONE" then
(
local bones_count=Layr[i].lobjects[j].Faces.count
local bups=#()
local tempObj=""
local TheObj=""
local oldInd=""
local bupvector =[0,0,0]
local bindex = 0
local bonepart = 0
local bStartInd =0
local bEndInd =0
local bStartPos=[0,0,0]
local bEndPos=[0,0,0]
for b = 1 to bones_count do (
bindex = b
bonepart = TagsArray[Layr[i].lobjects[j].Ptags[PARTTAG] [(b*2)+1]]
bupvector = TagsArray[Layr[i].lobjects[j].Ptags[BNUPTAG] [(b*2)+1]]
bups=filterstring bupvector " "
bupvector=[(bups[1] as float),(bups[2] as float),(bups[3] as float)]
bStartInd = Layr[i].lobjects[j].Faces[b].PointIndex[1]
bEndInd = Layr[i].lobjects[j].Faces[b].PointIndex[2]
bStartPos=LAYR[i].Lpoints[bStartInd]
bEndPos=LAYR[i].Lpoints[bEndInd]
TheObj=BoneSys.createBone bStartPos bEndPos (bupvector as point3)
TheObj.name=(layernumber+":Scelegon "+(bindex as string)+":"+bonepart)
if oldInd==bStartInd and tempObj !="" then TheOBJ.parent = tempObj else TheOBJ.parent = lpivot
oldInd = bEndInd
tempObj = TheObj
)
)
)
------------------------------------------------------------------------------
-------------------------------------END CREATE BONES
------------------------------------------------------------------------------
)--END OBJECTS
--SomeStatistics--
uvcount=0
for x =1 to Layr.count do (
uvcount+=Layr[x].luvs.count
)
Test.txt.text+=("
UVmaps Count: "+(uvcount as string)+"
")
Test.txt.text+=("
Materials Count: "+(LWOMATERIALS.count as string)+"
")
if lpivot != undefined then(
a=point()
lpivot.parent=a
rotate a (angleaxis -90 [1,0,0])
lpivot.parent=none
delete a
)
)--END LAYERS
)--END UNDO OFF