4 class model(Structure
):
6 _fields_
= [("identifier",c_uint32
),
7 ("vertex_count",c_uint32
),
8 ("indice_count",c_uint32
),
9 ("layer_count",c_uint32
)]
11 class sdf_primative(Structure
):
13 _fields_
= [("origin",c_float
*4),
16 class submodel(Structure
):
18 _fields_
= [("indice_start",c_uint32
),
19 ("indice_count",c_uint32
),
20 ("vertex_start",c_uint32
),
21 ("vertex_count",c_uint32
),
22 ("bbx",(c_float
*3)*2),
23 ("sdf",sdf_primative
),
27 class model_vert(Structure
):
29 _fields_
= [("co",c_float
*3),
34 def fixed_string(dest
,string
):
36 for i
in range(len(string
)):
39 def write_model(name
):
40 fp
= open(F
"/home/harry/Documents/carve/models/{name}.mdl", "wb")
41 collection
= bpy
.data
.collections
[name
]
44 header
.identifier
= 0xABCD0000
45 header
.vertex_count
= 0
46 header
.indice_count
= 0
47 header
.layer_count
= 0
53 for obj
in collection
.objects
:
54 if obj
.type == 'MESH':
55 dgraph
= bpy
.context
.evaluated_depsgraph_get()
56 data
= obj
.evaluated_get(dgraph
).data
57 data
.calc_loop_triangles()
58 data
.calc_normals_split()
61 sm
.indice_start
= header
.indice_count
62 sm
.vertex_start
= header
.vertex_count
63 sm
.vertex_count
= len(data
.vertices
)
64 sm
.indice_count
= len(data
.loop_triangles
)*3
68 sm
.bbx
[1][i
] = -999999
70 if F
"{obj.name}.sdf_cone" in bpy
.data
.objects
:
71 cone
= bpy
.data
.objects
[F
"{obj.name}.sdf_cone"]
72 sm
.sdf
.origin
[0] = cone
.location
[0]
73 sm
.sdf
.origin
[1] = cone
.location
[2] + cone
.scale
[1]*2.0
74 sm
.sdf
.origin
[2] = -cone
.location
[1]
75 sm
.sdf
.origin
[3] = 0.0
78 la
= cone
.scale
[1]*2.0
79 lh
= math
.sqrt(lo
*lo
+la
*la
)
83 sm
.sdf
.info
[2] = lo
/lh
84 sm
.sdf
.info
[3] = la
/lh
88 sm
.name
= obj
.name
.encode('utf-8')
90 for vert
in data
.vertices
:
102 sm
.bbx
[0][i
] = min( sm
.bbx
[0][i
], v
.co
[i
] )
103 sm
.bbx
[1][i
] = max( sm
.bbx
[1][i
], v
.co
[i
] )
106 pvert
= vertex_buffer
[l
.vertex_index
+ sm
.vertex_start
]
108 pvert
.norm
[0] = norm
[0]
109 pvert
.norm
[1] = norm
[2]
110 pvert
.norm
[2] = -norm
[1]
112 #if data.vertex_colors:
113 # colour = data.vertex_colors.active.data[ l.index ].color
114 # pvert.colour[0] = colour[0]
117 uv
= data
.uv_layers
.active
.data
[ l
.index
].uv
121 for tri
in data
.loop_triangles
:
122 indice_buffer
+= [c_uint32(tri
.vertices
[_
]) for _
in range(3)]
125 header
.layer_count
+= 1
126 header
.vertex_count
+= sm
.vertex_count
127 header
.indice_count
+= sm
.indice_count
129 fp
.write( bytearray( header
) )
131 fp
.write( bytearray(l
) )
132 for v
in vertex_buffer
:
133 fp
.write( bytearray(v
) )
134 for i
in indice_buffer
:
135 fp
.write( bytearray(i
) )
139 write_model( "test" )
140 write_model( "free_dev" )
141 write_model( "char_dev" )