-
Notifications
You must be signed in to change notification settings - Fork 0
/
export-meshes.py
68 lines (62 loc) · 1.87 KB
/
export-meshes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import bpy
import random
import math
import os
f = open("build/" + os.path.basename(bpy.data.filepath) + ".js", "w")
for obj in bpy.data.objects:
obj.modifiers.new(name = "edge_split", type = "EDGE_SPLIT")
mesh = obj.to_mesh(scene = bpy.context.scene, apply_modifiers = True, settings = "PREVIEW")
#for mesh in bpy.data.meshes:
if obj.name[:4] == "neon":
f.write("var " + obj.name + "Points=")
f.write('[')
for i in range(0, len(mesh.vertices)):
f.write(str(mesh.vertices[i].co.x))
f.write(',')
f.write(str(mesh.vertices[i].co.z))
f.write(',')
f.write(str(-mesh.vertices[i].co.y))
if i != len(mesh.vertices) - 1:
f.write(',')
f.write(']\n')
else:
f.write("var " + obj.name + "MeshBuffer=")
f.write('{"positions":[')
for i in range(0, len(mesh.vertices)):
f.write(str(mesh.vertices[i].co.x))
f.write(',')
f.write(str(mesh.vertices[i].co.z))
f.write(',')
f.write(str(-mesh.vertices[i].co.y))
if i != len(mesh.vertices) - 1:
f.write(',')
f.write('],')
f.write('"normals":[')
for i in range(0, len(mesh.vertices)):
f.write(str(mesh.vertices[i].normal.x))
f.write(',')
f.write(str(mesh.vertices[i].normal.z))
f.write(',')
f.write(str(-mesh.vertices[i].normal.y))
if i != len(mesh.vertices) - 1:
f.write(',')
f.write('],')
mesh.update(calc_tessface = True)
f.write('"indices":[')
for i in range(0, len(mesh.tessfaces)):
f.write(str(mesh.tessfaces[i].vertices[0]))
f.write(',')
f.write(str(mesh.tessfaces[i].vertices[2]))
f.write(',')
f.write(str(mesh.tessfaces[i].vertices[1]))
if (len(mesh.tessfaces[i].vertices) > 3):
f.write(',')
f.write(str(mesh.tessfaces[i].vertices[2]))
f.write(',')
f.write(str(mesh.tessfaces[i].vertices[0]))
f.write(',')
f.write(str(mesh.tessfaces[i].vertices[3]))
if i != len(mesh.tessfaces) - 1:
f.write(',')
f.write(']}\n')
f.close()