add triangle face support
This commit is contained in:
parent
112b63319f
commit
078dc952e7
@ -393,12 +393,13 @@ def load_basic_floor(mesh, floor_type, rotation, height_multiplier, d1, d2, side
|
|||||||
# now, we can process real mesh
|
# now, we can process real mesh
|
||||||
# load existed base count
|
# load existed base count
|
||||||
global_offset_vec = len(mesh.vertices)
|
global_offset_vec = len(mesh.vertices)
|
||||||
global_offset_face = len(mesh.polygons)
|
global_offset_polygons = len(mesh.polygons)
|
||||||
global_offset_facex4 = global_offset_face * 4
|
global_offset_loops = len(mesh.loops)
|
||||||
vecList = []
|
vecList = []
|
||||||
uvList = []
|
uvList = []
|
||||||
normalList = []
|
normalList = []
|
||||||
faceList = []
|
faceList = []
|
||||||
|
faceIndList = []
|
||||||
faceMatList = []
|
faceMatList = []
|
||||||
for face_define in needCreatedFaces:
|
for face_define in needCreatedFaces:
|
||||||
base_indices = len(vecList)
|
base_indices = len(vecList)
|
||||||
@ -411,27 +412,40 @@ def load_basic_floor(mesh, floor_type, rotation, height_multiplier, d1, d2, side
|
|||||||
uvList.append(solve_uv_data(uv, d1, d2, height_multiplier, block_uvworld_unit))
|
uvList.append(solve_uv_data(uv, d1, d2, height_multiplier, block_uvworld_unit))
|
||||||
|
|
||||||
for face in face_define['Faces']:
|
for face in face_define['Faces']:
|
||||||
|
if face['Type'] == 'RECTANGLE':
|
||||||
|
# rectangle
|
||||||
vec_indices = (
|
vec_indices = (
|
||||||
face['P1'] + base_indices,
|
face['P1'] + base_indices,
|
||||||
face['P2'] + base_indices,
|
face['P2'] + base_indices,
|
||||||
face['P3'] + base_indices,
|
face['P3'] + base_indices,
|
||||||
face['P4'] + base_indices)
|
face['P4'] + base_indices)
|
||||||
|
indCount = 4
|
||||||
|
elif face['Type'] == 'TRIANGLE':
|
||||||
|
# triangle
|
||||||
|
vec_indices = (
|
||||||
|
face['P1'] + base_indices,
|
||||||
|
face['P2'] + base_indices,
|
||||||
|
face['P3'] + base_indices)
|
||||||
|
indCount = 3
|
||||||
|
|
||||||
# we need calc normal and push it into list
|
# we need calc normal and push it into list
|
||||||
four_point_normal = solve_normal_data(vecList[vec_indices[0]], vecList[vec_indices[1]], vecList[vec_indices[2]])
|
point_normal = solve_normal_data(vecList[vec_indices[0]], vecList[vec_indices[1]], vecList[vec_indices[2]])
|
||||||
for i in range(4):
|
for i in range(indCount):
|
||||||
normalList.append(four_point_normal)
|
normalList.append(point_normal)
|
||||||
|
|
||||||
# push indices into list
|
# push indices into list
|
||||||
for i in range(4):
|
for i in range(indCount):
|
||||||
faceList.append(vec_indices[i] + global_offset_vec)
|
faceList.append(vec_indices[i] + global_offset_vec)
|
||||||
|
|
||||||
# push material into list
|
# push material into list
|
||||||
faceMatList.append(materialDict[face['Textures']])
|
faceMatList.append(materialDict[face['Textures']])
|
||||||
|
|
||||||
|
# push face vec count into list
|
||||||
|
faceIndList.append(indCount)
|
||||||
|
|
||||||
# push data into blender struct
|
# push data into blender struct
|
||||||
mesh.vertices.add(len(vecList))
|
mesh.vertices.add(len(vecList))
|
||||||
mesh.loops.add(len(faceMatList)*4) # 4 vec face confirm
|
mesh.loops.add(len(faceList))
|
||||||
mesh.polygons.add(len(faceMatList))
|
mesh.polygons.add(len(faceMatList))
|
||||||
if mesh.uv_layers.active is None:
|
if mesh.uv_layers.active is None:
|
||||||
# if no uv, create it
|
# if no uv, create it
|
||||||
@ -439,15 +453,18 @@ def load_basic_floor(mesh, floor_type, rotation, height_multiplier, d1, d2, side
|
|||||||
mesh.create_normals_split()
|
mesh.create_normals_split()
|
||||||
|
|
||||||
virtual_foreach_set(mesh.vertices, "co", global_offset_vec, vecList)
|
virtual_foreach_set(mesh.vertices, "co", global_offset_vec, vecList)
|
||||||
virtual_foreach_set(mesh.loops, "vertex_index", global_offset_facex4, faceList)
|
virtual_foreach_set(mesh.loops, "vertex_index", global_offset_loops, faceList)
|
||||||
virtual_foreach_set(mesh.loops, "normal", global_offset_facex4, normalList)
|
virtual_foreach_set(mesh.loops, "normal", global_offset_loops, normalList)
|
||||||
virtual_foreach_set(mesh.uv_layers[0].data, "uv", global_offset_facex4, uvList)
|
virtual_foreach_set(mesh.uv_layers[0].data, "uv", global_offset_loops, uvList)
|
||||||
|
|
||||||
|
cache_counter = 0
|
||||||
for i in range(len(faceMatList)):
|
for i in range(len(faceMatList)):
|
||||||
mesh.polygons[i + global_offset_face].loop_start = i * 4 + global_offset_facex4
|
indCount = faceIndList[i]
|
||||||
mesh.polygons[i + global_offset_face].loop_total = 4
|
mesh.polygons[i + global_offset_polygons].loop_start = global_offset_loops + cache_counter
|
||||||
mesh.polygons[i + global_offset_face].material_index = faceMatList[i]
|
mesh.polygons[i + global_offset_polygons].loop_total = indCount
|
||||||
mesh.polygons[i + global_offset_face].use_smooth = True
|
mesh.polygons[i + global_offset_polygons].material_index = faceMatList[i]
|
||||||
|
mesh.polygons[i + global_offset_polygons].use_smooth = True
|
||||||
|
cache_counter += indCount
|
||||||
|
|
||||||
|
|
||||||
def load_derived_floor(mesh, floor_type, height_multiplier, d1, d2, sides_struct):
|
def load_derived_floor(mesh, floor_type, height_multiplier, d1, d2, sides_struct):
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 0,
|
"P1": 0,
|
||||||
"P2": 1,
|
"P2": 1,
|
||||||
"P3": 2,
|
"P3": 2,
|
||||||
@ -51,6 +52,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 3,
|
"P1": 3,
|
||||||
"P2": 2,
|
"P2": 2,
|
||||||
"P3": 1,
|
"P3": 1,
|
||||||
@ -74,6 +76,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 3,
|
"P1": 3,
|
||||||
"P2": 2,
|
"P2": 2,
|
||||||
"P3": 1,
|
"P3": 1,
|
||||||
@ -97,6 +100,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 0,
|
"P1": 0,
|
||||||
"P2": 1,
|
"P2": 1,
|
||||||
"P3": 2,
|
"P3": 2,
|
||||||
@ -120,6 +124,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 0,
|
"P1": 0,
|
||||||
"P2": 1,
|
"P2": 1,
|
||||||
"P3": 2,
|
"P3": 2,
|
||||||
@ -143,6 +148,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 3,
|
"P1": 3,
|
||||||
"P2": 2,
|
"P2": 2,
|
||||||
"P3": 1,
|
"P3": 1,
|
||||||
@ -175,6 +181,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 2,
|
"P1": 2,
|
||||||
"P2": 3,
|
"P2": 3,
|
||||||
"P3": 4,
|
"P3": 4,
|
||||||
@ -182,6 +189,7 @@
|
|||||||
"Textures": "FloorTopBorder"
|
"Textures": "FloorTopBorder"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 3,
|
"P1": 3,
|
||||||
"P2": 2,
|
"P2": 2,
|
||||||
"P3": 1,
|
"P3": 1,
|
||||||
@ -220,6 +228,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 0,
|
"P1": 0,
|
||||||
"P2": 1,
|
"P2": 1,
|
||||||
"P3": 2,
|
"P3": 2,
|
||||||
@ -243,6 +252,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 3,
|
"P1": 3,
|
||||||
"P2": 2,
|
"P2": 2,
|
||||||
"P3": 1,
|
"P3": 1,
|
||||||
@ -266,6 +276,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 3,
|
"P1": 3,
|
||||||
"P2": 2,
|
"P2": 2,
|
||||||
"P3": 1,
|
"P3": 1,
|
||||||
@ -289,6 +300,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 0,
|
"P1": 0,
|
||||||
"P2": 1,
|
"P2": 1,
|
||||||
"P3": 2,
|
"P3": 2,
|
||||||
@ -312,6 +324,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 0,
|
"P1": 0,
|
||||||
"P2": 1,
|
"P2": 1,
|
||||||
"P3": 2,
|
"P3": 2,
|
||||||
@ -335,6 +348,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 3,
|
"P1": 3,
|
||||||
"P2": 2,
|
"P2": 2,
|
||||||
"P3": 1,
|
"P3": 1,
|
||||||
@ -367,6 +381,7 @@
|
|||||||
],
|
],
|
||||||
"Faces": [
|
"Faces": [
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 2,
|
"P1": 2,
|
||||||
"P2": 3,
|
"P2": 3,
|
||||||
"P3": 4,
|
"P3": 4,
|
||||||
@ -374,6 +389,7 @@
|
|||||||
"Textures": "FloorTopBorder"
|
"Textures": "FloorTopBorder"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"Type": "RECTANGLE",
|
||||||
"P1": 3,
|
"P1": 3,
|
||||||
"P2": 2,
|
"P2": 2,
|
||||||
"P3": 1,
|
"P3": 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user