|
@@ -7,13 +7,13 @@
|
|
rollout ThreeJSExporter "ThreeJSExporter"
|
|
rollout ThreeJSExporter "ThreeJSExporter"
|
|
(
|
|
(
|
|
-- Variables
|
|
-- Variables
|
|
-
|
|
|
|
|
|
+
|
|
local ostream,
|
|
local ostream,
|
|
|
|
|
|
headerFormat = "// Converted from: %
|
|
headerFormat = "// Converted from: %
|
|
// vertices: %
|
|
// vertices: %
|
|
// normals: %
|
|
// normals: %
|
|
-// uvs: %
|
|
|
|
|
|
+// uvs: %
|
|
// triangles: %
|
|
// triangles: %
|
|
// materials: %
|
|
// materials: %
|
|
//
|
|
//
|
|
@@ -24,26 +24,26 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
",
|
|
",
|
|
|
|
|
|
vertexFormat = "%,%,%",
|
|
vertexFormat = "%,%,%",
|
|
-
|
|
|
|
|
|
+
|
|
vertexNormalFormat = "%,%,%",
|
|
vertexNormalFormat = "%,%,%",
|
|
UVFormat = "%,%",
|
|
UVFormat = "%,%",
|
|
-
|
|
|
|
- triFormat = "%,%,%, %",
|
|
|
|
- triUVFormat = "%,%,%, %, %,%,%",
|
|
|
|
- triNFormat = "%,%,%, %, %,%,%",
|
|
|
|
- triUVNFormat = "%,%,%, %, %,%,%, %,%,%",
|
|
|
|
|
|
+
|
|
|
|
+ triFormat = "%,%,%,%",
|
|
|
|
+ triUVFormat = "%,%,%,%,%,%,%",
|
|
|
|
+ triNFormat = "%,%,%,%,%,%,%",
|
|
|
|
+ triUVNFormat = "%,%,%,%,%,%,%,%,%,%",
|
|
|
|
|
|
footerFormat = "}\n\npostMessage( model );"
|
|
footerFormat = "}\n\npostMessage( model );"
|
|
|
|
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- User interface
|
|
-- User interface
|
|
-
|
|
|
|
- group "ThreeJSExporter v0.1"
|
|
|
|
|
|
+
|
|
|
|
+ group "ThreeJSExporter v0.2"
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
label msg "Exports meshes in Three.js ascii JSON format" align:#left
|
|
label msg "Exports meshes in Three.js ascii JSON format" align:#left
|
|
- hyperLink lab1 "Original source can be found here" address:"https://github.com/mrdoob/three.js" align:#left
|
|
|
|
-
|
|
|
|
|
|
+ hyperLink lab1 "Original source can be found here" address:"https://github.com/mrdoob/three.js" align:#left
|
|
|
|
+
|
|
checkbox flipYZ "Flip YZ" checked:true enabled:true
|
|
checkbox flipYZ "Flip YZ" checked:true enabled:true
|
|
checkbox flipUV "Flip UV" checked:true enabled:true
|
|
checkbox flipUV "Flip UV" checked:true enabled:true
|
|
checkbox flipFace "Flip faces" checked:false enabled:true
|
|
checkbox flipFace "Flip faces" checked:false enabled:true
|
|
@@ -53,27 +53,27 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
checkbox exportColor "Export vertex colors" checked:false enabled:false
|
|
checkbox exportColor "Export vertex colors" checked:false enabled:false
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
- button btn_export "Export selected objects"
|
|
|
|
|
|
+
|
|
|
|
+ button btn_export "Export selected objects"
|
|
|
|
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Dump vertices
|
|
-- Dump vertices
|
|
|
|
|
|
function DumpVertices src =
|
|
function DumpVertices src =
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
Format "'vertices': [" to:ostream
|
|
Format "'vertices': [" to:ostream
|
|
-
|
|
|
|
|
|
+
|
|
num = src.count
|
|
num = src.count
|
|
-
|
|
|
|
|
|
+
|
|
if num > 0 then
|
|
if num > 0 then
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
for i = 1 to num do
|
|
for i = 1 to num do
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
vert = src[i]
|
|
vert = src[i]
|
|
-
|
|
|
|
|
|
+
|
|
if flipYZ.checked then
|
|
if flipYZ.checked then
|
|
(
|
|
(
|
|
x = vert.x
|
|
x = vert.x
|
|
@@ -85,44 +85,44 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
)
|
|
)
|
|
else
|
|
else
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
x = vert.x
|
|
x = vert.x
|
|
y = vert.y
|
|
y = vert.y
|
|
z = vert.z
|
|
z = vert.z
|
|
-
|
|
|
|
- )
|
|
|
|
|
|
+
|
|
|
|
+ )
|
|
|
|
|
|
Format vertexFormat x y z to:ostream
|
|
Format vertexFormat x y z to:ostream
|
|
|
|
|
|
- if i < num then Format ", " to:ostream
|
|
|
|
|
|
+ if i < num then Format "," to:ostream
|
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
Format "],\n\n" to:ostream
|
|
Format "],\n\n" to:ostream
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Dump normals
|
|
-- Dump normals
|
|
|
|
|
|
function DumpNormals src =
|
|
function DumpNormals src =
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
Format "'normals': [" to:ostream
|
|
Format "'normals': [" to:ostream
|
|
-
|
|
|
|
|
|
+
|
|
num = src.count
|
|
num = src.count
|
|
-
|
|
|
|
|
|
+
|
|
if num > 0 and exportNormal.checked then
|
|
if num > 0 and exportNormal.checked then
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
for i = 1 to num do
|
|
for i = 1 to num do
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
normal = src[i]
|
|
normal = src[i]
|
|
normal = normalize normal as point3
|
|
normal = normalize normal as point3
|
|
-
|
|
|
|
|
|
+
|
|
if flipYZ.checked then
|
|
if flipYZ.checked then
|
|
(
|
|
(
|
|
|
|
|
|
@@ -141,39 +141,39 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
z = normal.z
|
|
z = normal.z
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
Format vertexNormalFormat x y z to:ostream
|
|
Format vertexNormalFormat x y z to:ostream
|
|
-
|
|
|
|
- if i < num then Format ", " to:ostream
|
|
|
|
|
|
+
|
|
|
|
+ if i < num then Format "," to:ostream
|
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
Format "],\n\n" to:ostream
|
|
Format "],\n\n" to:ostream
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Dump uvs
|
|
-- Dump uvs
|
|
|
|
|
|
function DumpUvs src =
|
|
function DumpUvs src =
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
Format "'uvs': [" to:ostream
|
|
Format "'uvs': [" to:ostream
|
|
-
|
|
|
|
|
|
+
|
|
num = src.count
|
|
num = src.count
|
|
-
|
|
|
|
|
|
+
|
|
if num > 0 and exportUv.checked then
|
|
if num > 0 and exportUv.checked then
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
for i = 1 to num do
|
|
for i = 1 to num do
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
uvw = src[i]
|
|
uvw = src[i]
|
|
-
|
|
|
|
|
|
+
|
|
u = uvw.x
|
|
u = uvw.x
|
|
-
|
|
|
|
|
|
+
|
|
if flipUV.checked then
|
|
if flipUV.checked then
|
|
(
|
|
(
|
|
v = 1 - uvw.y
|
|
v = 1 - uvw.y
|
|
@@ -182,68 +182,68 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
(
|
|
(
|
|
v = uvw.y
|
|
v = uvw.y
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
Format UVFormat u v to:ostream
|
|
Format UVFormat u v to:ostream
|
|
-
|
|
|
|
- if i < num then Format ", " to:ostream
|
|
|
|
|
|
+
|
|
|
|
+ if i < num then Format "," to:ostream
|
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
Format "],\n\n" to:ostream
|
|
Format "],\n\n" to:ostream
|
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Dump face type
|
|
-- Dump face type
|
|
-
|
|
|
|
|
|
+
|
|
function DumpFaceType label content =
|
|
function DumpFaceType label content =
|
|
(
|
|
(
|
|
Format "'%': [" label to:ostream
|
|
Format "'%': [" label to:ostream
|
|
-
|
|
|
|
|
|
+
|
|
num = content.count
|
|
num = content.count
|
|
-
|
|
|
|
|
|
+
|
|
if num > 0 then
|
|
if num > 0 then
|
|
(
|
|
(
|
|
|
|
|
|
for i = 1 to num do
|
|
for i = 1 to num do
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
zface = content[i]
|
|
zface = content[i]
|
|
-
|
|
|
|
|
|
+
|
|
fv = zface[1]
|
|
fv = zface[1]
|
|
fuv = zface[2]
|
|
fuv = zface[2]
|
|
- m = zface[3] - 1
|
|
|
|
-
|
|
|
|
|
|
+ m = zface[3] - 1
|
|
|
|
+
|
|
needsFlip = zface[4]
|
|
needsFlip = zface[4]
|
|
|
|
|
|
hasUVs = (classof fuv == Point3)
|
|
hasUVs = (classof fuv == Point3)
|
|
-
|
|
|
|
|
|
+
|
|
va = (fv.x - 1) as Integer
|
|
va = (fv.x - 1) as Integer
|
|
vb = (fv.y - 1) as Integer
|
|
vb = (fv.y - 1) as Integer
|
|
vc = (fv.z - 1) as Integer
|
|
vc = (fv.z - 1) as Integer
|
|
|
|
|
|
if smoothNormal.checked then
|
|
if smoothNormal.checked then
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
-- normals have the same indices as vertices
|
|
-- normals have the same indices as vertices
|
|
-
|
|
|
|
|
|
+
|
|
na = va
|
|
na = va
|
|
nb = vb
|
|
nb = vb
|
|
nc = vc
|
|
nc = vc
|
|
-
|
|
|
|
|
|
+
|
|
)
|
|
)
|
|
else
|
|
else
|
|
(
|
|
(
|
|
- -- normals have the same indices as faces
|
|
|
|
-
|
|
|
|
|
|
+ -- normals have the same indices as face
|
|
|
|
+
|
|
na = i - 1
|
|
na = i - 1
|
|
nb = na
|
|
nb = na
|
|
nc = na
|
|
nc = na
|
|
-
|
|
|
|
|
|
+
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
if hasUVs then
|
|
if hasUVs then
|
|
(
|
|
(
|
|
|
|
|
|
@@ -252,28 +252,28 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
uc = (fuv.z - 1) as Integer
|
|
uc = (fuv.z - 1) as Integer
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
if flipFace.checked or needsFlip then
|
|
if flipFace.checked or needsFlip then
|
|
(
|
|
(
|
|
tmp = vb
|
|
tmp = vb
|
|
vb = vc
|
|
vb = vc
|
|
vc = tmp
|
|
vc = tmp
|
|
-
|
|
|
|
|
|
+
|
|
tmp = nb
|
|
tmp = nb
|
|
nb = nc
|
|
nb = nc
|
|
nc = tmp
|
|
nc = tmp
|
|
-
|
|
|
|
|
|
+
|
|
if hasUVs then
|
|
if hasUVs then
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
tmp = ub
|
|
tmp = ub
|
|
ub = uc
|
|
ub = uc
|
|
uc = tmp
|
|
uc = tmp
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
if label == "triangles" then
|
|
if label == "triangles" then
|
|
(
|
|
(
|
|
Format triFormat va vb vc m to:ostream
|
|
Format triFormat va vb vc m to:ostream
|
|
@@ -289,18 +289,18 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
else if label == "trianglesNormalsUvs" then
|
|
else if label == "trianglesNormalsUvs" then
|
|
(
|
|
(
|
|
Format triUVNFormat va vb vc m na nb nc ua ub uc to:ostream
|
|
Format triUVNFormat va vb vc m na nb nc ua ub uc to:ostream
|
|
- )
|
|
|
|
-
|
|
|
|
- if i < num then Format ", " to:ostream
|
|
|
|
-
|
|
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ if i < num then Format "," to:ostream
|
|
|
|
+
|
|
)
|
|
)
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
Format "],\n\n" to:ostream
|
|
Format "],\n\n" to:ostream
|
|
-
|
|
|
|
|
|
+
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Dump faces
|
|
-- Dump faces
|
|
|
|
|
|
@@ -308,7 +308,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
(
|
|
(
|
|
|
|
|
|
hasUVs = true
|
|
hasUVs = true
|
|
-
|
|
|
|
|
|
+
|
|
triangles = #()
|
|
triangles = #()
|
|
trianglesUvs = #()
|
|
trianglesUvs = #()
|
|
trianglesNormals = #()
|
|
trianglesNormals = #()
|
|
@@ -318,20 +318,20 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
quadsUvs = #()
|
|
quadsUvs = #()
|
|
quadsNormals = #()
|
|
quadsNormals = #()
|
|
quadsNormalsUvs = #()
|
|
quadsNormalsUvs = #()
|
|
-
|
|
|
|
|
|
+
|
|
num = src.count
|
|
num = src.count
|
|
-
|
|
|
|
|
|
+
|
|
if num > 0 then
|
|
if num > 0 then
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
for i = 1 to num do
|
|
for i = 1 to num do
|
|
(
|
|
(
|
|
|
|
|
|
zface = src[i]
|
|
zface = src[i]
|
|
fuv = zface[2]
|
|
fuv = zface[2]
|
|
-
|
|
|
|
|
|
+
|
|
hasUVs = (classof fuv == Point3)
|
|
hasUVs = (classof fuv == Point3)
|
|
-
|
|
|
|
|
|
+
|
|
if hasUVs and exportUv.checked and exportNormal.checked then
|
|
if hasUVs and exportUv.checked and exportNormal.checked then
|
|
(
|
|
(
|
|
append trianglesNormalsUvs zface
|
|
append trianglesNormalsUvs zface
|
|
@@ -348,11 +348,11 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
(
|
|
(
|
|
append triangles zface
|
|
append triangles zface
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
)
|
|
)
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
DumpFaceType "triangles" triangles
|
|
DumpFaceType "triangles" triangles
|
|
DumpFaceType "trianglesUvs" trianglesUvs
|
|
DumpFaceType "trianglesUvs" trianglesUvs
|
|
DumpFaceType "trianglesNormals" trianglesNormals
|
|
DumpFaceType "trianglesNormals" trianglesNormals
|
|
@@ -361,37 +361,37 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
DumpFaceType "quads" quads
|
|
DumpFaceType "quads" quads
|
|
DumpFaceType "quadsUvs" quadsUvs
|
|
DumpFaceType "quadsUvs" quadsUvs
|
|
DumpFaceType "quadsNormals" quadsNormals
|
|
DumpFaceType "quadsNormals" quadsNormals
|
|
- DumpFaceType "quadsNormalsUvs" quadsNormalsUvs
|
|
|
|
-
|
|
|
|
|
|
+ DumpFaceType "quadsNormalsUvs" quadsNormalsUvs
|
|
|
|
+
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Dump color
|
|
-- Dump color
|
|
-
|
|
|
|
|
|
+
|
|
function DumpColor pcolor label =
|
|
function DumpColor pcolor label =
|
|
(
|
|
(
|
|
r = pcolor.r / 255
|
|
r = pcolor.r / 255
|
|
g = pcolor.g / 255
|
|
g = pcolor.g / 255
|
|
b = pcolor.b / 255
|
|
b = pcolor.b / 255
|
|
-
|
|
|
|
|
|
+
|
|
fr = formattedPrint r format:".4f"
|
|
fr = formattedPrint r format:".4f"
|
|
fg = formattedPrint g format:".4f"
|
|
fg = formattedPrint g format:".4f"
|
|
fb = formattedPrint b format:".4f"
|
|
fb = formattedPrint b format:".4f"
|
|
-
|
|
|
|
|
|
+
|
|
Format "'%' : [%, %, %],\n" label fr fg fb to:ostream
|
|
Format "'%' : [%, %, %],\n" label fr fg fb to:ostream
|
|
-
|
|
|
|
|
|
+
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Dump map
|
|
-- Dump map
|
|
-
|
|
|
|
|
|
+
|
|
function DumpMap pmap label =
|
|
function DumpMap pmap label =
|
|
(
|
|
(
|
|
-
|
|
|
|
- if classof pmap == BitmapTexture then
|
|
|
|
|
|
+
|
|
|
|
+ if classof pmap == BitmapTexture then
|
|
(
|
|
(
|
|
bm = pmap.bitmap
|
|
bm = pmap.bitmap
|
|
-
|
|
|
|
|
|
+
|
|
if bm != undefined then
|
|
if bm != undefined then
|
|
(
|
|
(
|
|
|
|
|
|
@@ -399,21 +399,21 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
Format "'%' : '%',\n" label fname to:ostream
|
|
Format "'%' : '%',\n" label fname to:ostream
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
)
|
|
)
|
|
|
|
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Export materials
|
|
-- Export materials
|
|
-
|
|
|
|
|
|
+
|
|
function ExportMaterials zmaterials =
|
|
function ExportMaterials zmaterials =
|
|
(
|
|
(
|
|
|
|
|
|
Format "'materials': [\n" to:ostream
|
|
Format "'materials': [\n" to:ostream
|
|
-
|
|
|
|
|
|
+
|
|
totalMaterials = zmaterials.count
|
|
totalMaterials = zmaterials.count
|
|
-
|
|
|
|
|
|
+
|
|
for i = 1 to totalMaterials do
|
|
for i = 1 to totalMaterials do
|
|
(
|
|
(
|
|
mat = zmaterials[i]
|
|
mat = zmaterials[i]
|
|
@@ -421,16 +421,16 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
Format "{\n" to:ostream
|
|
Format "{\n" to:ostream
|
|
|
|
|
|
-- debug
|
|
-- debug
|
|
-
|
|
|
|
|
|
+
|
|
Format "'DbgIndex' : %,\n" (i-1) to:ostream
|
|
Format "'DbgIndex' : %,\n" (i-1) to:ostream
|
|
Format "'DbgName' : '%',\n" mat.name to:ostream
|
|
Format "'DbgName' : '%',\n" mat.name to:ostream
|
|
-
|
|
|
|
|
|
+
|
|
-- colors
|
|
-- colors
|
|
-
|
|
|
|
|
|
+
|
|
DumpColor mat.diffuse "colorDiffuse"
|
|
DumpColor mat.diffuse "colorDiffuse"
|
|
DumpColor mat.ambient "colorAmbient"
|
|
DumpColor mat.ambient "colorAmbient"
|
|
- DumpColor mat.specular "colorSpecular"
|
|
|
|
-
|
|
|
|
|
|
+ DumpColor mat.specular "colorSpecular"
|
|
|
|
+
|
|
t = mat.opacity / 100
|
|
t = mat.opacity / 100
|
|
s = mat.glossiness
|
|
s = mat.glossiness
|
|
|
|
|
|
@@ -438,7 +438,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
Format "'specularCoef' : %,\n" s to:ostream
|
|
Format "'specularCoef' : %,\n" s to:ostream
|
|
|
|
|
|
-- maps
|
|
-- maps
|
|
-
|
|
|
|
|
|
+
|
|
DumpMap mat.diffuseMap "mapDiffuse"
|
|
DumpMap mat.diffuseMap "mapDiffuse"
|
|
DumpMap mat.ambientMap "mapAmbient"
|
|
DumpMap mat.ambientMap "mapAmbient"
|
|
DumpMap mat.specularMap "mapSpecular"
|
|
DumpMap mat.specularMap "mapSpecular"
|
|
@@ -446,24 +446,24 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
DumpMap mat.opacityMap "mapAlpha"
|
|
DumpMap mat.opacityMap "mapAlpha"
|
|
|
|
|
|
Format "}" to:ostream
|
|
Format "}" to:ostream
|
|
-
|
|
|
|
|
|
+
|
|
if i < totalMaterials then Format "," to:ostream
|
|
if i < totalMaterials then Format "," to:ostream
|
|
Format "\n\n" to:ostream
|
|
Format "\n\n" to:ostream
|
|
-
|
|
|
|
|
|
+
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
Format "],\n\n" to:ostream
|
|
Format "],\n\n" to:ostream
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Extract vertices from mesh
|
|
-- Extract vertices from mesh
|
|
-
|
|
|
|
|
|
+
|
|
function ExtractVertices obj whereto =
|
|
function ExtractVertices obj whereto =
|
|
(
|
|
(
|
|
|
|
|
|
n = obj.numVerts
|
|
n = obj.numVerts
|
|
-
|
|
|
|
|
|
+
|
|
for i = 1 to n do
|
|
for i = 1 to n do
|
|
(
|
|
(
|
|
|
|
|
|
@@ -473,10 +473,10 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
)
|
|
)
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Extract normals from mesh
|
|
-- Extract normals from mesh
|
|
-
|
|
|
|
|
|
+
|
|
function ExtractNormals obj whereto needsFlip =
|
|
function ExtractNormals obj whereto needsFlip =
|
|
(
|
|
(
|
|
if smoothNormal.checked then
|
|
if smoothNormal.checked then
|
|
@@ -488,14 +488,14 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
(
|
|
(
|
|
|
|
|
|
n = GetNormal obj i
|
|
n = GetNormal obj i
|
|
-
|
|
|
|
|
|
+
|
|
if needsFlip then
|
|
if needsFlip then
|
|
(
|
|
(
|
|
n.x *= -1
|
|
n.x *= -1
|
|
n.y *= -1
|
|
n.y *= -1
|
|
n.z *= -1
|
|
n.z *= -1
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
append whereto n
|
|
append whereto n
|
|
|
|
|
|
)
|
|
)
|
|
@@ -503,14 +503,14 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
)
|
|
)
|
|
else
|
|
else
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
num = obj.numFaces
|
|
num = obj.numFaces
|
|
-
|
|
|
|
|
|
+
|
|
for i = 1 to num do
|
|
for i = 1 to num do
|
|
(
|
|
(
|
|
|
|
|
|
n = GetFaceNormal obj i
|
|
n = GetFaceNormal obj i
|
|
-
|
|
|
|
|
|
+
|
|
if needsFlip then
|
|
if needsFlip then
|
|
(
|
|
(
|
|
n.x *= -1
|
|
n.x *= -1
|
|
@@ -525,10 +525,10 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
)
|
|
)
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Extract uvs from mesh
|
|
-- Extract uvs from mesh
|
|
-
|
|
|
|
|
|
+
|
|
function ExtractUvs obj whereto =
|
|
function ExtractUvs obj whereto =
|
|
(
|
|
(
|
|
n = obj.numTVerts
|
|
n = obj.numTVerts
|
|
@@ -542,18 +542,18 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
)
|
|
)
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Extract faces from mesh
|
|
-- Extract faces from mesh
|
|
-
|
|
|
|
|
|
+
|
|
function ExtractFaces objMesh objMaterial whereto allMaterials needsFlip offsetVert offsetUv =
|
|
function ExtractFaces objMesh objMaterial whereto allMaterials needsFlip offsetVert offsetUv =
|
|
(
|
|
(
|
|
n = objMesh.numFaces
|
|
n = objMesh.numFaces
|
|
hasUVs = objMesh.numTVerts > 0
|
|
hasUVs = objMesh.numTVerts > 0
|
|
-
|
|
|
|
|
|
+
|
|
useMultiMaterial = false
|
|
useMultiMaterial = false
|
|
materialIDList = #()
|
|
materialIDList = #()
|
|
-
|
|
|
|
|
|
+
|
|
if ( classof objMaterial ) == StandardMaterial then
|
|
if ( classof objMaterial ) == StandardMaterial then
|
|
(
|
|
(
|
|
fm = findItem allMaterials objMaterial
|
|
fm = findItem allMaterials objMaterial
|
|
@@ -561,7 +561,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
else
|
|
else
|
|
(
|
|
(
|
|
useMultiMaterial = true
|
|
useMultiMaterial = true
|
|
-
|
|
|
|
|
|
+
|
|
for i = 1 to n do
|
|
for i = 1 to n do
|
|
(
|
|
(
|
|
mID = GetFaceMatID objMesh i
|
|
mID = GetFaceMatID objMesh i
|
|
@@ -575,7 +575,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
)
|
|
)
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
)
|
|
)
|
|
|
|
|
|
for i = 1 to n do
|
|
for i = 1 to n do
|
|
@@ -588,39 +588,39 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
fv.x += offsetVert
|
|
fv.x += offsetVert
|
|
fv.y += offsetVert
|
|
fv.y += offsetVert
|
|
fv.z += offsetVert
|
|
fv.z += offsetVert
|
|
-
|
|
|
|
|
|
+
|
|
if useMultiMaterial then
|
|
if useMultiMaterial then
|
|
(
|
|
(
|
|
mID = GetFaceMatID objMesh i
|
|
mID = GetFaceMatID objMesh i
|
|
fm = materialIDList[mID]
|
|
fm = materialIDList[mID]
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
if hasUVs then
|
|
if hasUVs then
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
fuv = GetTVFace objMesh i
|
|
fuv = GetTVFace objMesh i
|
|
|
|
|
|
fuv.x += offsetUv
|
|
fuv.x += offsetUv
|
|
fuv.y += offsetUv
|
|
fuv.y += offsetUv
|
|
fuv.z += offsetUv
|
|
fuv.z += offsetUv
|
|
-
|
|
|
|
|
|
+
|
|
)
|
|
)
|
|
else
|
|
else
|
|
(
|
|
(
|
|
fuv = false
|
|
fuv = false
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
append zface fv
|
|
append zface fv
|
|
append zface fuv
|
|
append zface fuv
|
|
append zface fm
|
|
append zface fm
|
|
append zface needsFlip
|
|
append zface needsFlip
|
|
-
|
|
|
|
|
|
+
|
|
append whereto zface
|
|
append whereto zface
|
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Extract materials from eventual multimaterial
|
|
-- Extract materials from eventual multimaterial
|
|
|
|
|
|
@@ -639,7 +639,7 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
)
|
|
)
|
|
else if materialClass == MultiMaterial then
|
|
else if materialClass == MultiMaterial then
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
n = objMesh.numFaces
|
|
n = objMesh.numFaces
|
|
|
|
|
|
for i = 1 to n do
|
|
for i = 1 to n do
|
|
@@ -666,9 +666,9 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
function NeedsFaceFlip node =
|
|
function NeedsFaceFlip node =
|
|
(
|
|
(
|
|
needsFlip = false
|
|
needsFlip = false
|
|
-
|
|
|
|
|
|
+
|
|
local tmp = Snapshot node
|
|
local tmp = Snapshot node
|
|
-
|
|
|
|
|
|
+
|
|
face_normal = normalize ( getfacenormal tmp 1 )
|
|
face_normal = normalize ( getfacenormal tmp 1 )
|
|
|
|
|
|
face = getface tmp 1
|
|
face = getface tmp 1
|
|
@@ -677,21 +677,21 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
vb = getvert tmp face[2]
|
|
vb = getvert tmp face[2]
|
|
vc = getvert tmp face[3]
|
|
vc = getvert tmp face[3]
|
|
|
|
|
|
- computed_normal = normalize ( cross (vc - vb) (va - vb) )
|
|
|
|
-
|
|
|
|
|
|
+ computed_normal = normalize ( cross (vc - vb) (va - vb) )
|
|
|
|
+
|
|
if distance computed_normal face_normal > 0.1 then needsFlip = true
|
|
if distance computed_normal face_normal > 0.1 then needsFlip = true
|
|
|
|
|
|
delete tmp
|
|
delete tmp
|
|
-
|
|
|
|
|
|
+
|
|
return needsFlip
|
|
return needsFlip
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Extract only things that either already are or can be converted to meshes
|
|
-- Extract only things that either already are or can be converted to meshes
|
|
-
|
|
|
|
|
|
+
|
|
function ExtractMesh node =
|
|
function ExtractMesh node =
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
if SuperClassOf node == GeometryClass then
|
|
if SuperClassOf node == GeometryClass then
|
|
(
|
|
(
|
|
return #( SnapshotAsMesh node, node.name, node.material, NeedsFaceFlip node )
|
|
return #( SnapshotAsMesh node, node.name, node.material, NeedsFaceFlip node )
|
|
@@ -703,104 +703,119 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
return #( false, node.name, 0 )
|
|
return #( false, node.name, 0 )
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Export scene
|
|
-- Export scene
|
|
-
|
|
|
|
|
|
+
|
|
function ExportScene =
|
|
function ExportScene =
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
-- Extract meshes
|
|
-- Extract meshes
|
|
-
|
|
|
|
|
|
+
|
|
meshObjects = #()
|
|
meshObjects = #()
|
|
-
|
|
|
|
|
|
+
|
|
mergedVertices = #()
|
|
mergedVertices = #()
|
|
mergedNormals = #()
|
|
mergedNormals = #()
|
|
mergedUvs = #()
|
|
mergedUvs = #()
|
|
mergedFaces = #()
|
|
mergedFaces = #()
|
|
mergedMaterials = #()
|
|
mergedMaterials = #()
|
|
-
|
|
|
|
|
|
+
|
|
for obj in selection do
|
|
for obj in selection do
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
result = ExtractMesh obj
|
|
result = ExtractMesh obj
|
|
-
|
|
|
|
|
|
+
|
|
meshObj = result[1]
|
|
meshObj = result[1]
|
|
meshName = result[2]
|
|
meshName = result[2]
|
|
meshMaterial = result[3]
|
|
meshMaterial = result[3]
|
|
needsFlip = result[4]
|
|
needsFlip = result[4]
|
|
-
|
|
|
|
|
|
+
|
|
if ClassOf meshObj == TriMesh then
|
|
if ClassOf meshObj == TriMesh then
|
|
(
|
|
(
|
|
-
|
|
|
|
|
|
+
|
|
append meshObjects result
|
|
append meshObjects result
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ vertexOffset = mergedVertices.count
|
|
|
|
+ uvOffset = mergedUvs.count
|
|
|
|
+
|
|
ExtractMaterials meshObj meshMaterial mergedMaterials
|
|
ExtractMaterials meshObj meshMaterial mergedMaterials
|
|
-
|
|
|
|
|
|
+
|
|
ExtractVertices meshObj mergedVertices
|
|
ExtractVertices meshObj mergedVertices
|
|
ExtractNormals meshObj mergedNormals needsFlip
|
|
ExtractNormals meshObj mergedNormals needsFlip
|
|
ExtractUvs meshObj mergedUvs
|
|
ExtractUvs meshObj mergedUvs
|
|
-
|
|
|
|
- --ExtractFaces meshObj zmaterial mergedFaces mergedVertices.count mergedUvs.count
|
|
|
|
- ExtractFaces meshObj meshMaterial mergedFaces mergedMaterials needsFlip 0 0
|
|
|
|
|
|
+
|
|
|
|
+ ExtractFaces meshObj meshMaterial mergedFaces mergedMaterials needsFlip vertexOffset uvOffset
|
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
totalVertices = mergedVertices.count
|
|
totalVertices = mergedVertices.count
|
|
- totalNormals = mergedNormals.count
|
|
|
|
- totalUvs = mergedUvs.count
|
|
|
|
totalFaces = mergedFaces.count
|
|
totalFaces = mergedFaces.count
|
|
- totalMaterials = sceneMaterials.count
|
|
|
|
|
|
+ totalMaterials = mergedMaterials.count
|
|
|
|
+
|
|
|
|
+ totalNormals = 0
|
|
|
|
+ if exportNormal.checked then
|
|
|
|
+ (
|
|
|
|
+ totalNormals = mergedNormals.count
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ totalUvs = 0
|
|
|
|
+ if exportUv.checked then
|
|
|
|
+ (
|
|
|
|
+ totalUvs = mergedUvs.count
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
|
|
-- Dump header
|
|
-- Dump header
|
|
-
|
|
|
|
|
|
+
|
|
Format headerFormat maxFileName totalVertices totalNormals totalUvs totalFaces totalMaterials to:ostream
|
|
Format headerFormat maxFileName totalVertices totalNormals totalUvs totalFaces totalMaterials to:ostream
|
|
|
|
|
|
-
|
|
|
|
|
|
+ -- Dump objects (debug)
|
|
|
|
+
|
|
Format "// Source objects:\n\n" to:ostream
|
|
Format "// Source objects:\n\n" to:ostream
|
|
-
|
|
|
|
|
|
+
|
|
i = 0
|
|
i = 0
|
|
-
|
|
|
|
|
|
+
|
|
for obj in meshObjects do
|
|
for obj in meshObjects do
|
|
(
|
|
(
|
|
|
|
|
|
meshName = obj[2]
|
|
meshName = obj[2]
|
|
Format "// %: %\n" i meshName to:ostream
|
|
Format "// %: %\n" i meshName to:ostream
|
|
i += 1
|
|
i += 1
|
|
-
|
|
|
|
|
|
+
|
|
)
|
|
)
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ -- Dump model
|
|
|
|
+
|
|
Format "\n\nvar model = {\n\n" to:ostream
|
|
Format "\n\nvar model = {\n\n" to:ostream
|
|
-
|
|
|
|
|
|
+
|
|
-- Dump all materials in the scene
|
|
-- Dump all materials in the scene
|
|
-
|
|
|
|
|
|
+
|
|
ExportMaterials mergedMaterials
|
|
ExportMaterials mergedMaterials
|
|
-
|
|
|
|
|
|
+
|
|
-- Dump merged data from all selected geometries
|
|
-- Dump merged data from all selected geometries
|
|
-
|
|
|
|
|
|
+
|
|
DumpVertices mergedVertices
|
|
DumpVertices mergedVertices
|
|
DumpNormals mergedNormals
|
|
DumpNormals mergedNormals
|
|
DumpUvs mergedUvs
|
|
DumpUvs mergedUvs
|
|
DumpFaces mergedFaces
|
|
DumpFaces mergedFaces
|
|
-
|
|
|
|
|
|
+
|
|
-- Dump footer
|
|
-- Dump footer
|
|
-
|
|
|
|
- Format footerFormat to:ostream
|
|
|
|
-
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ Format footerFormat to:ostream
|
|
|
|
+
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Open and prepare a file handle for writing
|
|
-- Open and prepare a file handle for writing
|
|
-
|
|
|
|
|
|
+
|
|
function GetSaveFileStream =
|
|
function GetSaveFileStream =
|
|
(
|
|
(
|
|
zname = getFilenameFile maxFileName
|
|
zname = getFilenameFile maxFileName
|
|
zname += ".js"
|
|
zname += ".js"
|
|
-
|
|
|
|
|
|
+
|
|
fname = GetSaveFileName filename:zname types:"JavaScript file (*.js)|*.js|All Files(*.*)|*.*|"
|
|
fname = GetSaveFileName filename:zname types:"JavaScript file (*.js)|*.js|All Files(*.*)|*.*|"
|
|
if fname == undefined then
|
|
if fname == undefined then
|
|
return undefined
|
|
return undefined
|
|
@@ -814,10 +829,10 @@ rollout ThreeJSExporter "ThreeJSExporter"
|
|
|
|
|
|
return ostream
|
|
return ostream
|
|
)
|
|
)
|
|
-
|
|
|
|
|
|
+
|
|
-------------------------------------------------------------------------------------
|
|
-------------------------------------------------------------------------------------
|
|
-- Export button click handler
|
|
-- Export button click handler
|
|
-
|
|
|
|
|
|
+
|
|
on btn_export pressed do
|
|
on btn_export pressed do
|
|
(
|
|
(
|
|
ostream = GetSaveFileStream()
|
|
ostream = GetSaveFileStream()
|