Skip to content

Commit 6831d83

Browse files
committed
V0.5. "be_normal" facecorner attribute support. Hello custom normals!
1 parent 2991c90 commit 6831d83

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

BEngine-Py/BEVersion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = 0.4
1+
VERSION = 0.5

BEngine-Py/Utils/BEUtils.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
BENGINE_INSTANCE = "be_instance"
2222
BENGINE_MATERIAL = "be_material"
2323
BENGINE_COLOR = "be_color"
24+
BENGINE_NORMAL = "be_normal"
2425

2526
TYPE_GN = "GeometryNodeTree"
2627
TYPE_SV = "SverchCustomTreeType"
@@ -890,19 +891,25 @@ def MeshToJSONData(process_obj):
890891
# np_tris_loops.shape = (len(process_obj.data.loop_triangles), 3)
891892
# mesh_dict["Loops"] = np_tris_loops.tolist()
892893

893-
# calc split nomrals
894-
process_obj.data.calc_normals_split()
894+
# Get Normals
895+
if BENGINE_NORMAL in process_obj.data.attributes.keys():
896+
if process_obj.data.attributes[BENGINE_NORMAL].domain == 'CORNER':
897+
np_normals = np.zeros(len(process_obj.data.attributes[BENGINE_NORMAL].data) * 3, dtype=np.float32)
898+
process_obj.data.attributes[BENGINE_NORMAL].data.foreach_get('vector', np_normals)
899+
np_normals.shape = (len(process_obj.data.attributes[BENGINE_NORMAL].data), 3)
900+
else:
901+
print("Attribute " + BENGINE_NORMAL + " must have FACECORNER domain!!!")
902+
np_normals = GetMeshNormalsNumpy(process_obj)
903+
else:
904+
np_normals = GetMeshNormalsNumpy(process_obj)
895905

896-
# GET NORMALS
897-
np_normals = np.zeros(len(process_obj.data.loops) * 3, dtype=np.float32)
898-
process_obj.data.loops.foreach_get("normal", np_normals)
899-
np_normals.shape = (len(process_obj.data.loops), 3)
900906
mesh_dict["Normals"] = np_normals.tolist()
901907

902908
# GET UVS, Colors, Materials
903909
uvs_dict = {}
904910
np_col_attrib = None
905911

912+
# Get Attributes
906913
for attrib_name in process_obj.data.attributes.keys():
907914
if attrib_name in UV_NAMES:
908915

@@ -926,7 +933,7 @@ def MeshToJSONData(process_obj):
926933
uvs_dict[attrib_name] = np_uv_attrib.tolist()
927934

928935
else:
929-
print("Attribute " + attrib_name + "must have FACECORNER domain!!!")
936+
print("Attribute " + attrib_name + " must have FACECORNER domain!!!")
930937

931938
elif attrib_name == BENGINE_COLOR:
932939

@@ -939,7 +946,7 @@ def MeshToJSONData(process_obj):
939946
np_col_attrib.shape = (len(process_obj.data.attributes[attrib_name].data), 4)
940947
mesh_dict["VertexColors"] = np_col_attrib.tolist()
941948
else:
942-
print("Attribute " + attrib_name + "must have FACECORNER domain!!!")
949+
print("Attribute " + attrib_name + " must have FACECORNER domain!!!")
943950

944951
# Setup bengine_material Value
945952
elif attrib_name == BENGINE_MATERIAL:
@@ -948,14 +955,26 @@ def MeshToJSONData(process_obj):
948955
process_obj.data.attributes[attrib_name].data.foreach_get('value', np_mat_attrib)
949956
mesh_dict["Materials"] = np_mat_attrib.tolist()
950957
else:
951-
print("Attribute " + attrib_name + "must have FACE domain!!!")
958+
print("Attribute " + attrib_name + " must have FACE domain!!!")
952959

953960
if uvs_dict:
954961
mesh_dict["UVs"] = uvs_dict
955962

956963
return mesh_dict
957964

958965

966+
def GetMeshNormalsNumpy(process_obj):
967+
# Calc Split Nomrals
968+
process_obj.data.calc_normals_split()
969+
970+
# GET NORMALS
971+
np_normals = np.zeros(len(process_obj.data.loops) * 3, dtype=np.float32)
972+
process_obj.data.loops.foreach_get("normal", np_normals)
973+
np_normals.shape = (len(process_obj.data.loops), 3)
974+
975+
return np_normals
976+
977+
959978
def SetRotationFromJSON(obj, js_euler, engine_type: str):
960979
if engine_type == "Unity":
961980
# Set Rotation

0 commit comments

Comments
 (0)