Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn ImportRip RipFilePath =
- (
- f = fopen RipFilePath "rb"
- Signature = readlong f #unsigned
- Version = readlong f #unsigned
- if Version != RipFileVersion do(
- printDebug "Not RIP file"
- ---print ( "FileSig: " + Version as String )
- ---print ( "Sig : " + RipFileVersion as String )
- return 0
- )
- dwFacesCnt = readlong f #unsigned
- dwVertexesCnt = readlong f #unsigned
- VertexSize = readlong f #unsigned
- TextureFilesCnt= readlong f #unsigned
- ShaderFilesCnt= readlong f #unsigned
- VertexAttributesCnt= readlong f #unsigned
- printDebug ( "*****ImportRip() File: " + RipFilePath as String )
- printDebug ( "dwFacesCnt=" + dwFacesCnt as String )
- printDebug ( "dwVertexesCnt=" + dwVertexesCnt as String )
- printDebug ( "VertexAttributesCnt=" + VertexAttributesCnt as String )
- VertexAttribTypesArray= #() ---Contain all types
- TextureFiles = #()
- ShaderFiles = #()
- Face_array = #()
- Normal_array = #()
- Vert_array = #()
- UV_array = #()
- TempPosIdx = 0 ---Get only first index attribute flag
- TempNormalIdx = 0
- TempTexCoordIdx = 0
- ---Read vertex attributes
- for i = 1 to VertexAttributesCnt do (
- Semantic = ReadStr f
- SemanticIndex = readlong f #unsigned
- Offset = readlong f #unsigned
- Size = readlong f #unsigned
- TypeMapElements = readlong f #unsigned
- for j = 1 to TypeMapElements do (
- TypeElement = readlong f #unsigned
- append VertexAttribTypesArray TypeElement
- )
- printDebug "------------"
- printDebug( "Semantic="+ Semantic )
- printDebug( "SemanticIndex=" + SemanticIndex as String )
- printDebug( "Offset=" + Offset as String )
- printDebug( "Size=" + Size as String )
- printDebug( "TypeMapElements=" + TypeMapElements as String )
- ---Recognize semantic if "AUTO" set
- if g_VertexFormatRecog == 0 do ( ---AUTO recognition
- if Semantic == "POSITION" do ( --- Get as "XYZ_"
- if TempPosIdx == 0 do (
- g_PosX_Idx = Offset / 4
- g_PosY_Idx = g_PosX_Idx + 1
- g_PosZ_Idx = g_PosX_Idx + 2
- TempPosIdx = TempPosIdx + 1
- )
- )
- if Semantic == "NORMAL" do (
- if TempNormalIdx == 0 do (
- g_NormX_Idx = Offset / 4
- g_NormY_Idx = g_NormX_Idx + 1
- g_NormZ_Idx = g_NormX_Idx + 2
- TempNormalIdx = TempNormalIdx + 1
- )
- )
- if Semantic == "TEXCOORD" do (
- if TempTexCoordIdx == 0 do(
- g_Tc0_U_Idx = Offset / 4
- g_Tc0_V_Idx = g_Tc0_U_Idx + 1
- TempTexCoordIdx = TempTexCoordIdx + 1
- )
- )
- )
- )
- printDebug "-----------------------------"
- ---Read texture files list to array ( if present )
- for i = 1 to TextureFilesCnt do (
- TexFile = ReadStr f
- append TextureFiles ( TexFile as String )
- )
- ---Read shader files list to array ( if present )
- for i = 1 to ShaderFilesCnt do (
- ShaderFile = ReadStr f
- append ShaderFiles ( ShaderFile as String )
- )
- printDebug ( "Texture Files:" )
- for i = 1 to TextureFiles.count do (
- printDebug ( TextureFiles[ i ] as String )
- )
- printDebug ( "------------" )
- ---Read indexes
- for x = 1 to dwFacesCnt do(
- i0 = readlong f #unsigned
- i1 = readlong f #unsigned
- i2 = readlong f #unsigned
- if g_flipXZAxis == 1 then (
- append Face_array[i2+1,i1+1,i0+1]
- ) else (
- append Face_array[i0+1,i1+1,i2+1]
- )
- --- print( "idx0: " + i0 as String + " idx1: " + i1 as String + " idx2: " + i2 as String )
- )
- printDebug( "PosX idx: " + g_PosX_Idx as String )
- printDebug( "PosY idx: " + g_PosY_Idx as String )
- printDebug( "PosZ idx: " + g_PosZ_Idx as String )
- printDebug( "NormX idx: " + g_NormX_Idx as String )
- printDebug( "NormY idx: " + g_NormY_Idx as String )
- printDebug( "NormZ idx: " + g_NormZ_Idx as String )
- printDebug( "Tu0 idx: " + g_Tc0_U_Idx as String )
- printDebug( "Tv0 idx: " + g_Tc0_V_Idx as String )
- ---Read vertexes
- for k = 1 to dwVertexesCnt do(
- --- print ( "VertexIdx : " + (k-1) as String )
- vx = 0.0
- vy = 0.0
- vz = 0.0
- vw = 0.0
- nx = 0.0
- ny = 0.0
- nz = 0.0
- nw = 0.0
- tu = 0.0
- tv = 0.0
- for j = 0 to VertexAttribTypesArray.count - 1 do(
- --- print ( "VertAttr Idx: " + j as String )
- ElementType = VertexAttribTypesArray[ j + 1 ]
- if ElementType == 0 then ( --- EFLOAT
- z = readfloat f
- )
- else if ElementType == 1 then ( ---EUINT
- z = readlong f #unsigned
- )
- else if ElementType == 2 then ( ---ESINT
- z = readlong f #signed
- )
- else (
- z = readlong f #unsigned
- )
- if j == g_PosX_Idx do vx = z
- if j == g_PosY_Idx do vy = z
- if j == g_PosZ_Idx do vz = z
- !if j == g_PosW_Idx do vw = z
- if j == g_NormX_Idx do nx = z
- if j == g_NormY_Idx do ny = z
- if j == g_NormZ_Idx do nz = z
- if j == g_Tc0_U_Idx do tu = z
- if j == g_Tc0_V_Idx do tv = z
- vx = vx as Float
- vy = vy as Float
- vz = vz as Float
- !vw = vw as Float
- nx = nx as Float
- ny = ny as Float
- nz = nz as Float
- tu = tu as Float
- tv = tv as Float
- )
- append Vert_array[(vx * g_ninjaScale),(vy * g_ninjaScale),(vz * g_ninjaScale)]
- !append Vert_array[((vx*vw) * g_ninjaScale),((vy*vw) * g_ninjaScale),((vz*vw) * g_ninjaScale)]
- append Normal_array [nz,ny,nx]
- append UV_array[tu,tv * g_flipUV,0]
- --- print( "vx: " + vx as String + " vy: " + vy as String + " vz: " + vz as String )
- --- print( "tu: " + tu as String + " tv: " + tv as String )
- )
- TexFile = TextureFiles [ 1 + g_Tex0_FileLev ]
- if TexFile == undefined do ( TexFile = "notexture.dds" )
- TexFileName = getFilenamePath RipFilePath
- TexFileName = TexFileName + TexFile
- printDebug ( "TEXTURE FILE: " + TexFileName )
- ---Material
- -- thenewmaterial = multimaterial numsubs:1
- -- thenewsubmaterial = standardmaterial name:TexFile
- -- thenewsubmaterial.diffusemap = bitmaptexture name:TexFile
- -- thenewsubmaterial.diffusemap.filename = TexFileName
- -- thenewmaterial.materiallist[1] = thenewsubmaterial
- -- showtexturemap thenewsubmaterial thenewsubmaterial.diffusemap true
- thenewmaterial = standardmaterial name:TexFile
- thenewmaterial.diffusemap = bitmaptexture name:TexFile
- thenewmaterial.diffusemap.filename = TexFileName
- -- thenewmaterial.bumpmap = bitmaptexture name:TexFile
- -- thenewmaterial.bumpmap.filename = TexFileName
- showtexturemap thenewmaterial thenewmaterial.diffusemap true
- msh = mesh vertices:Vert_array faces:Face_array
- setNumTVerts msh UV_array.count
- for i = 1 to UV_array.count do (setTVert msh i UV_array[i])
- buildTVFaces msh false
- for i = 1 to Face_array.count do (setTVFace msh i Face_array[i])
- --for i = 1 to Normal_array.count do (setNormal msh j Normal_array[j])
- --Aplly mesh rotation
- currentMatrix = msh.transform
- preRotate currentMatrix (eulertoquat (eulerAngles g_ninjarotX g_ninjarotY g_ninjarotZ))
- msh.transform = currentMatrix
- resetxform msh
- maxOps.CollapseNode msh off
- msh.name = getFilenameFile RipFilePath
- msh.material = thenewmaterial
- --Redraw screen
- --windows.processPostedMessages() -- This prevents 3DS Max from hanging!
- --completeredraw()
- --gw.updateScreen()
- )
- on BtnImport pressed do (
- if RadioVertexFormat.state == 1 then ( ---Auto
- printDebug "***Auto***"
- g_VertexFormatRecog = 0
- ---Set default values
- g_PosX_Idx = 0
- g_PosY_Idx = 1
- g_PosZ_Idx = 2
- !g_PosW_Idx = 3
- g_ninjarotX = spnrotateX.value
- g_ninjarotY = spnrotateY.value
- g_ninjarotZ = spnrotateZ.value
- meshscale = spnscale.value
- )
- else ( ---Manual
- printDebug "***Manual***"
- g_VertexFormatRecog = 1
- ---Position
- g_PosX_Idx = ( pos_x.value as Integer )
- g_PosY_Idx = ( pos_y.value as Integer )
- g_PosZ_Idx = ( pos_z.value as Integer )
- ---Normals
- g_NormX_Idx = ( norm_x.value as Integer )
- g_NormY_Idx = ( norm_y.value as Integer )
- g_NormZ_Idx = ( norm_z.value as Integer )
- ---Tex coords
- g_Tc0_U_Idx = ( tc0_u.value as Integer )
- g_Tc0_V_Idx = ( tc0_v.value as Integer )
- g_ninjarotX = spnrotateX.value
- g_ninjarotY = spnrotateY.value
- g_ninjarotZ = spnrotateZ.value
- meshscale = spnscale.value
- )
- g_Tex0_FileLev = spnTex0Lev.value as Integer
- ---Import part
- if g_ImportType == 1 then ( ---Single file import
- if g_InputSrc.count > 0 then ( ImportRip g_InputSrc )
- !ImportRip2 g_InputSrc
- else ( messageBox "Please select a .RIP file" )
- )
- else if g_ImportType == 0 then ( ---Group import
- if InputSrc.text.count > 0 then (
- if RipList.text.count > 0 then (
- RipDir = getFilenamePath InputSrc.text
- ---print ( "RipDir: " + RipDir as String )
- tokens = filterString RipList.text ","
- FilteredTokens = #()
- ---Remove token whitespaces
- for i = 1 to tokens.count do (
- ---print ( "Tokens: " + tokens[i] as String )
- local Str = StringClear tokens[i]
- append FilteredTokens ( Str as String )
- )
- ---Import loop. Split tokens with "-"
- for i = 1 to FilteredTokens.count do (
- printDebug ( "Filtered Tokens: " + FilteredTokens[i] as String )
- RangeTokens = filterString FilteredTokens[ i ] "-"
- if RangeTokens.count == 1 then ( --Single element
- RipDir1 = RipDir
- ss = CreateMeshName RangeTokens[ 1 ]
- RipDir1 = RipDir1 + ss;
- printDebug ( "Single Import:" + RipDir1 as String )
- ImportRip RipDir1
- !ImportRip2
- )
- else( ---Range element
- r0 = RangeTokens[1] as Integer
- r1 = RangeTokens[2] as Integer
- if r0 < r1 then (
- t1 = r0
- t2 = r1
- messageBox("Screen redrawing has been disabled to help boost performance.")
- disableSceneRedraw()
- tStart = timestamp()
- doProcess = true
- setProgressCancel = false
- progressBarText = "Importing "+ (t2 as string) +" objects..."
- progressStart (progressBarText as string)
- for j = r0 to r1 while doProcess do(
- if getProgressCancel() == true do (
- doProcess = false
- setProgressCancel = true
- )
- if (getProgressCancel() == false) and (setProgressCancel == false) do (
- RipDir1 = RipDir
- ss = CreateMeshName j
- RipDir1 = RipDir1 + ss;
- printDebug ( "Group Import:" + RipDir1 as String )
- ImportRip RipDir1
- !ImportRip2
- t1 = t1 + 1
- tp = (100.0*t1/t2)
- progressUpdate (tp)
- )
- )
- progressEnd()
- enableSceneRedraw()
- tEnd = timestamp()
- tTimer = ((tEnd-tStart)/1000.0)
- if (tTimer <= 1) do ( tTime = (((tTimer) as string)+" second"))
- if (tTimer >= 2) do ( tTime = (((tTimer) as string)+" seconds"))
- if (tTimer > 60) do ( tTime = ((((tTimer)/60) as string)+" minute"))
- if (tTimer > 120) do ( tTime = ((((tTimer)/60) as string)+" minutes"))
- if (doProcess == true) and (setProgressCancel == false) then (
- messageBox("Successfully imported "+ (t1 as string) +" objects in "+((tTime) as string)+"!")
- ) else (
- messageBox("Import interrupted! "+ (t1 as string) +"/"+(t2 as string)+" objects imported.")
- )
- completeRedraw()
- gw.updateScreen()
- )
- else (
- printDebug( "Incorrect range: " + r0 as String + " to " + r1 as String )
- )
- )
- )
- )
- else(
- printDebug "Type file list"
- )
- )
- else (
- printDebug "Select dir"
- )
- )
- else(
- printDebug "Import from list file not realized"
- )
- )
- on BtnImport2 pressed do (
- if RadioVertexFormat.state == 1 then ( ---Auto
- printDebug "***Auto***"
- g_VertexFormatRecog = 0
- ---Set default values
- g_PosX_Idx = 0
- g_PosY_Idx = 1
- g_PosZ_Idx = 2
- g_PosW_Idx = 3
- g_ninjarotX = spnrotateX.value
- g_ninjarotY = spnrotateY.value
- g_ninjarotZ = spnrotateZ.value
- meshscale = spnscale.value
- )
- else ( ---Manual
- printDebug "***Manual***"
- g_VertexFormatRecog = 1
- ---Position
- g_PosX_Idx = ( pos_x.value as Integer )
- g_PosY_Idx = ( pos_y.value as Integer )
- g_PosZ_Idx = ( pos_z.value as Integer )
- --g_PosW_Idx = ( pos_w.value as Integer )
- ---Normals
- g_NormX_Idx = ( norm_x.value as Integer )
- g_NormY_Idx = ( norm_y.value as Integer )
- g_NormZ_Idx = ( norm_z.value as Integer )
- ---Tex coords
- g_Tc0_U_Idx = ( tc0_u.value as Integer )
- g_Tc0_V_Idx = ( tc0_v.value as Integer )
- g_ninjarotX = spnrotateX.value
- g_ninjarotY = spnrotateY.value
- g_ninjarotZ = spnrotateZ.value
- meshscale = spnscale.value
- )
- g_Tex0_FileLev = spnTex0Lev.value as Integer
- ---Import part
- if g_ImportType == 1 then ( ---Single file import
- if g_InputSrc.count > 0 then ( ImportRip2 g_InputSrc )
- else ( messageBox "Please select a .RIP file" )
- )
- else if g_ImportType == 0 then ( ---Group import
- if InputSrc.text.count > 0 then (
- if RipList.text.count > 0 then (
- RipDir = getFilenamePath InputSrc.text
- ---print ( "RipDir: " + RipDir as String )
- tokens = filterString RipList.text ","
- FilteredTokens = #()
- ---Remove token whitespaces
- for i = 1 to tokens.count do (
- ---print ( "Tokens: " + tokens[i] as String )
- local Str = StringClear tokens[i]
- append FilteredTokens ( Str as String )
- )
- ---Import loop. Split tokens with "-"
- for i = 1 to FilteredTokens.count do (
- printDebug ( "Filtered Tokens: " + FilteredTokens[i] as String )
- RangeTokens = filterString FilteredTokens[ i ] "-"
- if RangeTokens.count == 1 then ( --Single element
- RipDir1 = RipDir
- ss = CreateMeshName RangeTokens[ 1 ]
- RipDir1 = RipDir1 + ss;
- printDebug ( "Single Import:" + RipDir1 as String )
- ImportRip2 RipDir1
- )
- else( ---Range element
- r0 = RangeTokens[1] as Integer
- r1 = RangeTokens[2] as Integer
- if r0 < r1 then (
- t1 = r0
- t2 = r1
- messageBox("Screen redrawing has been disabled to help boost performance.")
- disableSceneRedraw()
- tStart = timestamp()
- doProcess = true
- setProgressCancel = false
- progressBarText = "Importing "+ (t2 as string) +" objects..."
- progressStart (progressBarText as string)
- for j = r0 to r1 while doProcess do(
- if getProgressCancel() == true do (
- doProcess = false
- setProgressCancel = true
- )
- if (getProgressCancel() == false) and (setProgressCancel == false) do (
- RipDir1 = RipDir
- ss = CreateMeshName j
- RipDir1 = RipDir1 + ss;
- printDebug ( "Group Import:" + RipDir1 as String )
- ImportRip2 RipDir1
- t1 = t1 + 1
- tp = (100.0*t1/t2)
- progressUpdate (tp)
- )
- )
- progressEnd()
- enableSceneRedraw()
- tEnd = timestamp()
- tTimer = ((tEnd-tStart)/1000.0)
- if (tTimer <= 1) do ( tTime = (((tTimer) as string)+" second"))
- if (tTimer >= 2) do ( tTime = (((tTimer) as string)+" seconds"))
- if (tTimer > 60) do ( tTime = ((((tTimer)/60) as string)+" minute"))
- if (tTimer > 120) do ( tTime = ((((tTimer)/60) as string)+" minutes"))
- if (doProcess == true) and (setProgressCancel == false) then (
- messageBox("Successfully imported "+ (t1 as string) +" objects in "+((tTime) as string)+"!")
- ) else (
- messageBox("Import interrupted! "+ (t1 as string) +"/"+(t2 as string)+" objects imported.")
- )
- completeRedraw()
- gw.updateScreen()
- )
- else (
- printDebug( "Incorrect range: " + r0 as String + " to " + r1 as String )
- )
- )
- )
- )
- else(
- printDebug "Type file list"
- )
- )
- else (
- printDebug "Select dir"
- )
- )
- else(
- printDebug "Import from list file not realized"
- )
- )
- )
- createDialog MainRollout 300 374 50 60
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement