Skip to content

Commit

Permalink
V0.5. "be_normal" facecorner attribute support. Hello custom normals!
Browse files Browse the repository at this point in the history
  • Loading branch information
mifth committed Jan 14, 2023
1 parent 2991c90 commit 6831d83
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion BEngine-Py/BEVersion.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = 0.4
VERSION = 0.5
37 changes: 28 additions & 9 deletions BEngine-Py/Utils/BEUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
BENGINE_INSTANCE = "be_instance"
BENGINE_MATERIAL = "be_material"
BENGINE_COLOR = "be_color"
BENGINE_NORMAL = "be_normal"

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

# calc split nomrals
process_obj.data.calc_normals_split()
# Get Normals
if BENGINE_NORMAL in process_obj.data.attributes.keys():
if process_obj.data.attributes[BENGINE_NORMAL].domain == 'CORNER':
np_normals = np.zeros(len(process_obj.data.attributes[BENGINE_NORMAL].data) * 3, dtype=np.float32)
process_obj.data.attributes[BENGINE_NORMAL].data.foreach_get('vector', np_normals)
np_normals.shape = (len(process_obj.data.attributes[BENGINE_NORMAL].data), 3)
else:
print("Attribute " + BENGINE_NORMAL + " must have FACECORNER domain!!!")
np_normals = GetMeshNormalsNumpy(process_obj)
else:
np_normals = GetMeshNormalsNumpy(process_obj)

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

# GET UVS, Colors, Materials
uvs_dict = {}
np_col_attrib = None

# Get Attributes
for attrib_name in process_obj.data.attributes.keys():
if attrib_name in UV_NAMES:

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

else:
print("Attribute " + attrib_name + "must have FACECORNER domain!!!")
print("Attribute " + attrib_name + " must have FACECORNER domain!!!")

elif attrib_name == BENGINE_COLOR:

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

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

if uvs_dict:
mesh_dict["UVs"] = uvs_dict

return mesh_dict


def GetMeshNormalsNumpy(process_obj):
# Calc Split Nomrals
process_obj.data.calc_normals_split()

# GET NORMALS
np_normals = np.zeros(len(process_obj.data.loops) * 3, dtype=np.float32)
process_obj.data.loops.foreach_get("normal", np_normals)
np_normals.shape = (len(process_obj.data.loops), 3)

return np_normals


def SetRotationFromJSON(obj, js_euler, engine_type: str):
if engine_type == "Unity":
# Set Rotation
Expand Down

0 comments on commit 6831d83

Please sign in to comment.