Skip to content

Commit 670a6b0

Browse files
committed
set attribute as split norm
1 parent 7124bf6 commit 670a6b0

File tree

6 files changed

+65
-3
lines changed

6 files changed

+65
-3
lines changed

__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
classes = [
2626
SIMLOADER_obj_property,
2727
SIMLOADER_scene_property,
28+
SIMLOADER_mesh_property,
2829
SIMLOADER_OT_load,
2930
SIMLOADER_OT_edit,
3031
SIMLOADER_OT_resetpt,
@@ -36,6 +37,8 @@
3637
SIMLOADER_Settings,
3738
SIMLOADER_Templates,
3839
SIMLOADER_UL_Att_List,
40+
SIMLOADER_OT_set_as_split_norm,
41+
SIMLOADER_OT_remove_split_norm,
3942
]
4043

4144

@@ -46,6 +49,7 @@ def register():
4649
bpy.types.TEXT_MT_templates.append(draw_template)
4750
bpy.types.Scene.SIMLOADER = bpy.props.PointerProperty(type=SIMLOADER_scene_property)
4851
bpy.types.Object.SIMLOADER = bpy.props.PointerProperty(type=SIMLOADER_obj_property)
52+
bpy.types.Mesh.SIMLOADER = bpy.props.PointerProperty(type=SIMLOADER_mesh_property)
4953

5054

5155
def unregister():

simloader/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .operators import SIMLOADER_OT_load, SIMLOADER_OT_edit, SIMLOADER_OT_resetpt, SIMLOADER_OT_resetmesh, SIMLOADER_OT_resetins
2-
from .properties import SIMLOADER_scene_property, SIMLOADER_obj_property
1+
from .operators import SIMLOADER_OT_load, SIMLOADER_OT_edit, SIMLOADER_OT_resetpt, SIMLOADER_OT_resetmesh, SIMLOADER_OT_resetins,SIMLOADER_OT_set_as_split_norm,SIMLOADER_OT_remove_split_norm
2+
from .properties import SIMLOADER_scene_property, SIMLOADER_obj_property,SIMLOADER_mesh_property
33
from .panels import SIMLOADER_UL_Obj_List, SIMLOADER_List_Panel, SIMLOADER_Settings, SIMLOADER_Import, SIMLOADER_Templates, SIMLOADER_UL_Att_List, draw_template
44
from .messanger import subscribe_to_selected, unsubscribe_to_selected
55
import bpy
@@ -55,4 +55,7 @@ def SIMLOADER_initilize(scene):
5555
"SIMLOADER_OT_resetins",
5656
"draw_template",
5757
"unsubscribe_to_selected",
58+
"SIMLOADER_OT_set_as_split_norm",
59+
"SIMLOADER_mesh_property",
60+
"SIMLOADER_OT_remove_split_norm",
5861
]

simloader/importer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ def update_mesh(meshio_mesh, mesh):
129129
name_string = 'vector'
130130

131131
attribute.data.foreach_set(name_string, v.ravel())
132+
133+
134+
# set as split norm
135+
if mesh.SIMLOADER.split_norm_att_name and mesh.SIMLOADER.split_norm_att_name ==k:
136+
mesh.use_auto_smooth = True
137+
mesh.normals_split_custom_set_from_vertices(v)
138+
132139

133140

134141
def create_obj(fileseq, use_relaitve, transform_matrix=Matrix([[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 0], [0, 0, 0, 1]])):

simloader/operators.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import traceback
55
from .utils import show_message_box
66
from .importer import create_obj
7+
import numpy as np
78

89

910
# Here are load and delete operations
@@ -181,3 +182,38 @@ def execute(self, context):
181182

182183
bpy.ops.object.modifier_move_to_index(modifier=gn.name, index=0)
183184
return {"FINISHED"}
185+
186+
class SIMLOADER_OT_set_as_split_norm(bpy.types.Operator):
187+
'''
188+
This operator set the vertex attribute as vertex split normals
189+
'''
190+
bl_label = "Set as Split Norm per Vertex"
191+
bl_idname = "simloader.setsplitnorm"
192+
bl_options = {"UNDO"}
193+
def execute(self, context):
194+
sim_loader = context.scene.SIMLOADER
195+
obj = bpy.data.objects[sim_loader.selected_obj_num]
196+
mesh = obj.data
197+
attr_index = sim_loader.selected_attribute_num
198+
if attr_index>=len(mesh.attributes):
199+
show_message_box("Please select the attribute")
200+
return {"CANCELLED"}
201+
mesh.SIMLOADER.split_norm_att_name = mesh.attributes[attr_index].name
202+
203+
return {"FINISHED"}
204+
205+
class SIMLOADER_OT_remove_split_norm(bpy.types.Operator):
206+
'''
207+
This operator remove the vertex attribute as vertex split normals
208+
'''
209+
bl_label = "Remove Split Norm per Vertex"
210+
bl_idname = "simloader.removesplitnorm"
211+
bl_options = {"UNDO"}
212+
def execute(self, context):
213+
sim_loader = context.scene.SIMLOADER
214+
obj = bpy.data.objects[sim_loader.selected_obj_num]
215+
mesh = obj.data
216+
if mesh.SIMLOADER.split_norm_att_name:
217+
mesh.SIMLOADER.split_norm_att_name = ""
218+
219+
return {"FINISHED"}

simloader/panels.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ def draw_item(self, context, layout, data, item, icon, active_data, active_propn
3131

3232
class SIMLOADER_UL_Att_List(bpy.types.UIList):
3333
'''
34-
This controls the list of imported sequneces.
34+
This controls the list of attributes available for this sequence
3535
'''
3636
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
3737
if item:
3838
layout.enabled = False
3939
layout.prop(item, "name", text='Name ', emboss=False)
40+
obj = bpy.data.objects[context.scene.SIMLOADER.selected_obj_num]
41+
mesh = obj.data
42+
if mesh.SIMLOADER.split_norm_att_name and mesh.SIMLOADER.split_norm_att_name ==item.name:
43+
layout.label(text="using as split norm")
44+
4045
else:
4146
# actually, I guess this line of code won't be executed?
4247
layout.label(text="", translate=False, icon_value=icon)
@@ -121,6 +126,8 @@ def draw(self, context):
121126
box = layout.box()
122127
row = box.row()
123128
row.template_list("SIMLOADER_UL_Att_List", "", obj.data, "attributes", sim_loader, "selected_attribute_num", rows=2)
129+
box.operator("SIMLOADER.setsplitnorm")
130+
box.operator("SIMLOADER.removesplitnorm",text="remove split norm")
124131

125132
# advance settings
126133
layout.label(text="Advance Settings")

simloader/properties.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,8 @@ class SIMLOADER_obj_property(bpy.types.PropertyGroup):
4242
script_name: bpy.props.StringProperty()
4343
use_relative: bpy.props.BoolProperty(default=False)
4444
pattern: bpy.props.StringProperty()
45+
46+
47+
# set this property for mesh, not object (maybe change later?)
48+
class SIMLOADER_mesh_property(bpy.types.PropertyGroup):
49+
split_norm_att_name : bpy.props.StringProperty(default="")

0 commit comments

Comments
 (0)