Wanna contribute to this thread a bit.
'[R-DEV wrote:rPoXoTauJIo;2171216']...Infact i'm already working on export tools for blender, as with zero experience in it i made PoC in just few hours.

Could always utilize some help as the free time ain't infinite
I already have implemented
mesh parser in py3, so getting mesh with all the metadata isn't a problem for me.
Anyone who's wanna play with it:
1. Clone repo, and look at
box_new.py, it will generate new staticmesh from
mocked object.
2. Create new blender scene, make box in it.
3. Use script for extracting vertex positions, their normals, indices.
As the blender works with polygons instead of tris, and meshdata are all tris, we have to triangulate our box first.
Code: Select all
import bpy
class VertexObject:
def __init__(self):
self.bpy_vert = None
self.normal = None
self.index = None
def __eq__(self, other):
if (self.bpy_vert.co, self.normal) == (other.bpy_vert.co, other.normal):
return True
else:
return False
def main():
for object in bpy.data.objects:
if object.name.startswith('root_'):
print(object)
for geom in object.children:
print(geom)
for lod in geom.children:
print(lod)
for bf2object in lod.children:
print(bf2object)
for bf2child in bf2object.children:
print(bf2child)
vertices = []
indices = []
normals = []
VBO = []
#bf2object.data.vertices # vert array
#face.vertices # indicies array
for id_f, face in enumerate(bf2object.data.polygons):
face_vertices = []
face_indices = []
triorder = [2, 1, 0, 0, 3, 2]
for id_v in triorder:
vertex = bf2object.data.vertices[face.vertices[id_v]]
index = id_f*4 + id_v
VO = VertexObject()
VO.bpy_vert = vertex
VO.normal = face.normal
VO.index = index
if VO not in VBO:
VBO.append(VO)
face_vertices.append(vertex)
face_indices.append(index)
vertices.extend(face_vertices)
indices.extend(face_indices)
for i in range(len(triorder)):
normals.append(face.normal)
for vertex in face_vertices:
vertex
#print('VERTICES')
for vertex in vertices:
#print(vertex.co)
pass
#print('NORMALS')
for normal in normals:
#print(normal)
pass
#print('INDICES')
for index in indices:
print('{},'.format(index))
pass
for VO in VBO:
#print('[{}] {}'.format(VO.index, VO.bpy_vert.co))
print('{},'.format(VO.bpy_vert.co).replace('<Vector ', '').replace(')>', ')'))
#print('{},'.format(VO.normal).replace('<Vector ', '').replace(')>', ')'))
#pass
print('\nNORMALS')
for VO in VBO:
#print('[{}] {}'.format(VO.index, VO.bpy_vert.co))
#print('{},'.format(VO.bpy_vert.co).replace('<Vector ', '').replace(')>', ')'))
print('{},'.format(VO.normal).replace('<Vector ', '').replace(')>', ')'))
#pass
#print('\nINDICES')
for VO in VBO:
#print('{},'.format(VO.index))
#print('{},'.format(VO.bpy_vert.co).replace('<Vector ', '').replace(')>', ')'))
#print('{},'.format(VO.normal).replace('<Vector ', '').replace(')>', ')'))
pass
if __name__ == "__main__":
print('\n POC')
main()
4. Change vertices positions and their normals in function
_create_vertices and indices in
_create_indices, after that generate test box.
Current problem that's stopping me from working further is vertex order&index being diffirent on export from blender. I think problem laying somewhere in theory where i do suck, so here a raw data if anyone wanna solve it for me faster than i am without setting all the dev shit.
Reference box(evil_box/meshes/evil_box.staticmesh). Keep note that it has 25 vertices for some reason, i've exported&reexported model from max from scratch multiple times to confirm that.

Code: Select all
### VERTICES ###
# bottom
[0] (0.5, 0.0, 0.5),
[1] (-0.5, 0.0, 0.5),
[2] (-0.5, 0.0, -0.5),
[3] (0.5, 0.0, -0.5),
# top
[4] (0.5, 1.0, 0.5),
[5] (0.5, 1.0, -0.5),
[6] (-0.5, 1.0, -0.5),
[7] (-0.5, 1.0, 0.5),
# front
[8] (0.5, 1.0, -0.5),
[9] (0.5, 0.0, -0.5),
[10] (-0.5, 0.0, -0.5),
[11] (-0.5, 1.0, -0.5),
# right
[12] (0.5, 1.0, 0.5),
[13] (0.5, 0.0, 0.5),
[14] (0.5, 0.0, -0.5),
[15] (0.5, 1.0, -0.5),
# back
[16] (-0.5, 1.0, 0.5),
[17] (-0.5, 0.0, 0.5),
[18] (0.5, 0.0, 0.5),
[19] (0.5, 1.0, 0.5),
# left
[20] (-0.5, 1.0, -0.5),
[21] (-0.5, 0.0, -0.5),
[22] (-0.5, 0.0, 0.5),
[23] (-0.5, 1.0, 0.5),
# random vertex, right back front - same as [14]
[24] (0.5, 0.0, -0.5),
### NORMALS ###
# bottom
[0] (0.0, -1.0, 0.0),
[1] (0.0, -1.0, 0.0),
[2] (0.0, -1.0, 0.0),
[3] (0.0, -1.0, 0.0),
# top
[4] (0.0, 1.0, 0.0),
[5] (0.0, 1.0, 0.0),
[6] (0.0, 1.0, 0.0),
[7] (0.0, 1.0, 0.0),
# front
[8] (0.0, 0.0, -1.0),
[9] (0.0, 0.0, -1.0),
[10] (0.0, 0.0, -1.0),
[11] (0.0, 0.0, -1.0),
# right
[12] (1.0, 0.0, 0.0),
[13] (1.0, 0.0, 0.0),
[14] (1.0, 0.0, 0.0),
[15] (1.0, 0.0, 0.0),
# back
[16] (0.0, 0.0, 1.0),
[17] (0.0, 0.0, 1.0),
[18] (0.0, 0.0, 1.0),
[19] (0.0, 0.0, 1.0),
# left
[20] (-1.0, 0.0, 0.0),
[21] (-1.0, 0.0, 0.0),
[22] (-1.0, 0.0, 0.0),
[23] (-1.0, 0.0, 0.0),
# random vertice same as [14]
[24] (1.0, 0.0, 0.0),
### INDICES ###
# those are being rendered in reversed order
# left
22,
23,
20,
20,
21,
22,
# back
18,
19,
16,
16,
17,
18,
# right
# using random 24 vertice
24,
15,
12,
12,
13,
24,
# front
10,
11,
8,
8,
9,
10,
# top
6,
7,
4,
4,
5,
6,
# bottom
2,
3,
0,
0,
1,
2,
Blender export data(24 vertices):
Code: Select all
### VERTICES ###
# front
[0] (-1.0000, -1.0000, -1.0000),
[1] (1.0000, -1.0000, -1.0000),
[2] (1.0000, 1.0000, -1.0000),
[3] (-1.0000, 1.0000, -1.0000),
# back
[4] (-1.0000, -1.0000, 1.0000),
[5] (-1.0000, 1.0000, 1.0000),
[6] (1.0000, 1.0000, 1.0000),
[7] (1.0000, -1.0000, 1.0000),
# right
[8] (1.0000, -1.0000, 1.0000),
[9] (1.0000, 1.0000, 1.0000),
[10] (1.0000, 1.0000, -1.0000),
[11] (1.0000, -1.0000, -1.0000),
# bottom
[12] (-1.0000, -1.0000, 1.0000),
[13] (1.0000, -1.0000, 1.0000),
[14] (1.0000, -1.0000, -1.0000),
[15] (-1.0000, -1.0000, -1.0000),
# left
[16] (-1.0000, 1.0000, 1.0000),
[17] (-1.0000, -1.0000, 1.0000),
[18] (-1.0000, -1.0000, -1.0000),
[19] (-1.0000, 1.0000, -1.0000),
# top
[20] (-1.0000, 1.0000, -1.0000),
[21] (1.0000, 1.0000, -1.0000),
[22] (1.0000, 1.0000, 1.0000),
[23] (-1.0000, 1.0000, 1.0000),
### NORMALS ###
# front
[0] (0.0000, 0.0000, -1.0000),
[1] (0.0000, 0.0000, -1.0000),
[2] (0.0000, 0.0000, -1.0000),
[3] (0.0000, 0.0000, -1.0000),
# back
[4] (0.0000, -0.0000, 1.0000),
[5] (0.0000, -0.0000, 1.0000),
[6] (0.0000, -0.0000, 1.0000),
[7] (0.0000, -0.0000, 1.0000),
# right
[8] (1.0000, -0.0000, 0.0000),
[9] (1.0000, -0.0000, 0.0000),
[10] (1.0000, -0.0000, 0.0000),
[11] (1.0000, -0.0000, 0.0000),
# bottom
[12] (-0.0000, -1.0000, -0.0000),
[13] (-0.0000, -1.0000, -0.0000),
[14] (-0.0000, -1.0000, -0.0000),
[15] (-0.0000, -1.0000, -0.0000),
# left
[16] (-1.0000, 0.0000, -0.0000),
[17] (-1.0000, 0.0000, -0.0000),
[18] (-1.0000, 0.0000, -0.0000),
[19] (-1.0000, 0.0000, -0.0000),
# top
[20] (0.0000, 1.0000, 0.0000),
[21] (0.0000, 1.0000, 0.0000),
[22] (0.0000, 1.0000, 0.0000),
[23] (0.0000, 1.0000, 0.0000),
### INDICES ###
# front
2,
1,
0,
0,
3,
2,
# back
6,
5,
4,
4,
7,
6,
# right
10,
9,
8,
8,
11,
10,
# bottom
14,
13,
12,
12,
15,
14,
# left
18,
17,
16,
16,
19,
18,
# top
22,
21,
20,
20,
23,
22,