From 4bacb4b253c45919d9c5ceebc9cff8555cccd424 Mon Sep 17 00:00:00 2001 From: Simarilius-uk <29640139+Simarilius-uk@users.noreply.github.com> Date: Sun, 10 Nov 2024 23:36:27 +0000 Subject: [PATCH 1/3] 4.3 compat --- .../importers/attribute_import.py | 16 +- .../importers/import_with_materials.py | 6 +- i_scene_cp77_gltf/importers/sector_import.py | 3 +- i_scene_cp77_gltf/jsontool.py | 2 +- i_scene_cp77_gltf/material_types/hair.py | 6 +- i_scene_cp77_gltf/material_types/hologram.py | 56 +++---- .../meshdecalgradientmaprecolor.py | 6 +- i_scene_cp77_gltf/meshtools/__init__.py | 2 +- .../resources/scripts/Import_from_OS.py | 138 ++++++++++-------- 9 files changed, 142 insertions(+), 93 deletions(-) diff --git a/i_scene_cp77_gltf/importers/attribute_import.py b/i_scene_cp77_gltf/importers/attribute_import.py index 6c5ae92..c1b0706 100644 --- a/i_scene_cp77_gltf/importers/attribute_import.py +++ b/i_scene_cp77_gltf/importers/attribute_import.py @@ -1,8 +1,13 @@ import bpy from io_scene_gltf2.io.imp.gltf2_io_binary import BinaryData -from io_scene_gltf2.blender.imp.gltf2_blender_mesh import points_edges_tris -from io_scene_gltf2.blender.imp.gltf2_blender_mesh import squish +vers = bpy.app.version +if vers[0] == 4 and vers[1] < 3: + from io_scene_gltf2.blender.imp.gltf2_blender_mesh import points_edges_tris + from io_scene_gltf2.blender.imp.gltf2_blender_mesh import squish +else: + from io_scene_gltf2.blender.imp.mesh import points_edges_tris + from io_scene_gltf2.blender.imp.mesh import squish def rename_color_attribute(mesh, name_before, name_after): if mesh.color_attributes is None: @@ -39,6 +44,7 @@ def manage_garment_support(existingMeshes, gltf_importer_data): curMeshCount = curMeshCount + 1 + def add_vertex_color_attribute(accessor_name, attribute_name, gltf_importer_data, mesh, prim, indices): gltf_importer = gltf_importer_data if not accessor_name in prim.attributes: @@ -52,7 +58,11 @@ def add_vertex_color_attribute(accessor_name, attribute_name, gltf_importer_data if layer is None: print("WARNING: Vertex colors are ignored (maximum number of vertex color layers has been reached)") else: - mesh.color_attributes[layer.name].data.foreach_set('color', squish(cols)) + print(layer.name) + try: + mesh.color_attributes[layer.name].data.foreach_set('color', squish(cols)) + except: + print('something blew up setting gs attributes') def get_indices(gltf_importer_data, prim): gltf_importer = gltf_importer_data diff --git a/i_scene_cp77_gltf/importers/import_with_materials.py b/i_scene_cp77_gltf/importers/import_with_materials.py index 360eb8e..b2d44b4 100644 --- a/i_scene_cp77_gltf/importers/import_with_materials.py +++ b/i_scene_cp77_gltf/importers/import_with_materials.py @@ -3,7 +3,11 @@ import json import time from io_scene_gltf2.io.imp.gltf2_io_gltf import glTFImporter -from io_scene_gltf2.blender.imp.gltf2_blender_gltf import BlenderGlTF +vers = bpy.app.version +if vers[0] == 4 and vers[1] < 3: + from io_scene_gltf2.blender.imp.gltf2_blender_gltf import BlenderGlTF +else: + from io_scene_gltf2.blender.imp.blender_gltf import BlenderGlTF from ..main.setup import MaterialBuilder from ..main.bartmoss_functions import UV_by_bounds from .import_from_external import * diff --git a/i_scene_cp77_gltf/importers/sector_import.py b/i_scene_cp77_gltf/importers/sector_import.py index 4975e66..fd2d50c 100644 --- a/i_scene_cp77_gltf/importers/sector_import.py +++ b/i_scene_cp77_gltf/importers/sector_import.py @@ -1022,7 +1022,8 @@ def importSectors( filepath, with_mats, remap_depot, want_collisions, am_modding new['meshAppearance']=meshAppearance new['appearanceName']=meshAppearance if ntype=='worldClothMeshNode': - new['windImpulseEnabled']= inst['windImpulseEnabled'] + if 'windImpulseEnabled' in inst.keys(): + new['windImpulseEnabled']= inst['windImpulseEnabled'] if ntype=='worldRotatingMeshNode': new['rot_axis']=data['rotationAxis'] new['reverseDirection']=data['reverseDirection'] diff --git a/i_scene_cp77_gltf/jsontool.py b/i_scene_cp77_gltf/jsontool.py index 35f5629..6192368 100644 --- a/i_scene_cp77_gltf/jsontool.py +++ b/i_scene_cp77_gltf/jsontool.py @@ -21,7 +21,7 @@ def json_ver_validate(json_data): return False header = json_data['Header'] if "WolvenKitVersion" in header and "8.13" not in header["WolvenKitVersion"]: - if "8.14" not in header["WolvenKitVersion"]: + if "8.15" not in header["WolvenKitVersion"]: return False if "MaterialJsonVersion" in header: if "1." not in header["MaterialJsonVersion"]: diff --git a/i_scene_cp77_gltf/material_types/hair.py b/i_scene_cp77_gltf/material_types/hair.py index 8292cc8..10c7288 100644 --- a/i_scene_cp77_gltf/material_types/hair.py +++ b/i_scene_cp77_gltf/material_types/hair.py @@ -15,7 +15,11 @@ def create(self,hair,Mat): profile= profile["Data"]["RootChunk"] Mat.blend_method = 'HASHED' - Mat.shadow_method = 'HASHED' + vers = bpy.app.version + if vers[0] == 4 and vers[1] <= 2: + Mat.shadow_method = 'HASHED' + else: + print('set shadows to hashed how in 4.3?') CurMat = Mat.node_tree Ns=CurMat.nodes diff --git a/i_scene_cp77_gltf/material_types/hologram.py b/i_scene_cp77_gltf/material_types/hologram.py index 8d2aad5..5e26143 100644 --- a/i_scene_cp77_gltf/material_types/hologram.py +++ b/i_scene_cp77_gltf/material_types/hologram.py @@ -14,7 +14,11 @@ def __init__(self, BasePath,image_format, ProjPath): def create(self,Data,Mat): mat = Mat mat.use_nodes = True - mat.shadow_method = 'HASHED' + vers = bpy.app.version + if vers[0] == 4 and vers[1] <= 2: + Mat.shadow_method = 'HASHED' + else: + print('set shadows to hashed how in 4.3?') mat.blend_method = 'HASHED' sockets=bsdf_socket_names() @@ -161,55 +165,53 @@ def create(self,Data,Mat): principled_bsdf_001.distribution = 'GGX' principled_bsdf_001.subsurface_method = 'RANDOM_WALK_SKIN' #Metallic - principled_bsdf_001.inputs[1].default_value = 0.0 + principled_bsdf_001.inputs[loc('Metallic')].default_value = 0.0 #Roughness - principled_bsdf_001.inputs[2].default_value = 1.0 + principled_bsdf_001.inputs[loc('Roughness')].default_value = 1.0 #IOR - principled_bsdf_001.inputs[3].default_value = 1.4500000476837158 + principled_bsdf_001.inputs[loc('IOR')].default_value = 1.4500000476837158 #Normal - principled_bsdf_001.inputs[5].default_value = (0.0, 0.0, 0.0) - #Weight - principled_bsdf_001.inputs[6].default_value = 0.0 + principled_bsdf_001.inputs[loc('Normal')].default_value = (0.0, 0.0, 0.0) #Subsurface Weight - principled_bsdf_001.inputs[7].default_value = 0.0 + principled_bsdf_001.inputs[loc('Subsurface Weight')].default_value = 0.0 #Subsurface Radius - principled_bsdf_001.inputs[8].default_value = (1.0, 0.20000000298023224, 0.10000000149011612) + principled_bsdf_001.inputs[loc('Subsurface Radius')].default_value = (1.0, 0.20000000298023224, 0.10000000149011612) #Subsurface Scale - principled_bsdf_001.inputs[9].default_value = 0.05000000074505806 + principled_bsdf_001.inputs[loc('Subsurface Scale')].default_value = 0.05000000074505806 #Subsurface IOR - principled_bsdf_001.inputs[10].default_value = 1.399999976158142 + principled_bsdf_001.inputs[loc('Subsurface IOR')].default_value = 1.399999976158142 #Subsurface Anisotropy - principled_bsdf_001.inputs[11].default_value = 0.0 + principled_bsdf_001.inputs[loc('Subsurface Anisotropy')].default_value = 0.0 #Specular IOR Level - principled_bsdf_001.inputs[12].default_value = 0.0 + principled_bsdf_001.inputs[loc('Specular IOR Level')].default_value = 0.0 #Specular Tint - principled_bsdf_001.inputs[13].default_value = (1.0, 1.0, 1.0, 1.0) + principled_bsdf_001.inputs[loc('Specular Tint')].default_value = (1.0, 1.0, 1.0, 1.0) #Anisotropic - principled_bsdf_001.inputs[14].default_value = 0.0 + principled_bsdf_001.inputs[loc('Anisotropic')].default_value = 0.0 #Anisotropic Rotation - principled_bsdf_001.inputs[15].default_value = 0.0 + principled_bsdf_001.inputs[loc('Anisotropic Rotation')].default_value = 0.0 #Tangent - principled_bsdf_001.inputs[16].default_value = (0.0, 0.0, 0.0) + principled_bsdf_001.inputs[loc('Tangent')].default_value = (0.0, 0.0, 0.0) #Transmission Weight - principled_bsdf_001.inputs[17].default_value = 0.0 + principled_bsdf_001.inputs[loc('Transmission Weight')].default_value = 0.0 #Coat Weight - principled_bsdf_001.inputs[18].default_value = 0.0 + principled_bsdf_001.inputs[loc('Coat Weight')].default_value = 0.0 #Coat Roughness - principled_bsdf_001.inputs[19].default_value = 0.029999999329447746 + principled_bsdf_001.inputs[loc('Coat Roughness')].default_value = 0.029999999329447746 #Coat IOR - principled_bsdf_001.inputs[20].default_value = 1.5 + principled_bsdf_001.inputs[loc('Coat IOR')].default_value = 1.5 #Coat Tint - principled_bsdf_001.inputs[21].default_value = (1.0, 1.0, 1.0, 1.0) + principled_bsdf_001.inputs[loc('Coat Tint')].default_value = (1.0, 1.0, 1.0, 1.0) #Coat Normal - principled_bsdf_001.inputs[22].default_value = (0.0, 0.0, 0.0) + principled_bsdf_001.inputs[loc('Coat Normal')].default_value = (0.0, 0.0, 0.0) #Sheen Weight - principled_bsdf_001.inputs[23].default_value = 0.0 + principled_bsdf_001.inputs[loc('Sheen Weight')].default_value = 0.0 #Sheen Roughness - principled_bsdf_001.inputs[24].default_value = 0.5 + principled_bsdf_001.inputs[loc('Sheen Roughness')].default_value = 0.5 #Sheen Tint - principled_bsdf_001.inputs[25].default_value = (1.0, 1.0, 1.0, 1.0) + principled_bsdf_001.inputs[loc('Sheen Tint')].default_value = (1.0, 1.0, 1.0, 1.0) #Emission Strength - principled_bsdf_001.inputs[27].default_value = 30.0 + principled_bsdf_001.inputs[loc('Emission Strength')].default_value = 30.0 #node Mix Shader mix_shader_003 = holo_blue_002.nodes.new("ShaderNodeMixShader") diff --git a/i_scene_cp77_gltf/material_types/meshdecalgradientmaprecolor.py b/i_scene_cp77_gltf/material_types/meshdecalgradientmaprecolor.py index 4ae6853..eb31077 100644 --- a/i_scene_cp77_gltf/material_types/meshdecalgradientmaprecolor.py +++ b/i_scene_cp77_gltf/material_types/meshdecalgradientmaprecolor.py @@ -10,7 +10,11 @@ def __init__(self, BasePath,image_format, ProjPath): def create(self,Data,Mat): Mat.blend_method = 'HASHED' - Mat.shadow_method = 'HASHED' + vers = bpy.app.version + if vers[0] == 4 and vers[1] <= 2: + Mat.shadow_method = 'HASHED' + else: + print('set shadows to hashed how in 4.3?') CurMat = Mat.node_tree pBSDF = CurMat.nodes[loc('Principled BSDF')] sockets=bsdf_socket_names() diff --git a/i_scene_cp77_gltf/meshtools/__init__.py b/i_scene_cp77_gltf/meshtools/__init__.py index 592a14d..7ef919a 100644 --- a/i_scene_cp77_gltf/meshtools/__init__.py +++ b/i_scene_cp77_gltf/meshtools/__init__.py @@ -160,7 +160,7 @@ def invoke(self, context, event): def execute(self, context): # Call the trans_weights function with the provided arguments - result = trans_weights(self, context, vertInterop, bySubmesh) + result = trans_weights(self, context, False) return {"FINISHED"} def draw(self,context): diff --git a/i_scene_cp77_gltf/resources/scripts/Import_from_OS.py b/i_scene_cp77_gltf/resources/scripts/Import_from_OS.py index 9ec6011..0998af5 100644 --- a/i_scene_cp77_gltf/resources/scripts/Import_from_OS.py +++ b/i_scene_cp77_gltf/resources/scripts/Import_from_OS.py @@ -11,8 +11,9 @@ # # -project_path='C:\\CPMod\\notell' -GroupName='blender_group_1' + +project_path=r'C:\CPMod\corpo_apt' +GroupName='corpo_wall_test' with_mats=False import bpy @@ -24,6 +25,7 @@ D=bpy.data C=bpy.context coll_scene = C.scene.collection +shapes=["Box", "Capsule", "Sphere" ] def get_position(obj): pos = Vector((obj['spawnable']['position']['x'],obj['spawnable']['position']['y'],obj['spawnable']['position']['z'])) @@ -35,16 +37,14 @@ def get_position(obj): else: scale=(1,1,1) return pos,rot,scale - + def process_group(group,target_coll): for child in group['childs']: - if child['type']=='group': - coll_target=bpy.data.collections.new(child['name']) - target_coll.children.link(coll_target) - process_group(child,coll_target) - elif child['type']=='object': + if 'type' in child.keys() and child['type']=='object': process_object(child,target_coll) + elif 'type' in child.keys() and child['type']=='group': + process_group(child,target_coll) def process_object(obj,parent_coll): Masters=bpy.data.collections.get("MasterInstances") @@ -86,61 +86,85 @@ def process_object(obj,parent_coll): newobj.rotation_euler = rot newobj.scale = scale elif spawndata[-4:]=='.ent' : - app=obj['spawnable']['app'] - entpath=os.path.join(project_path,'source','raw', spawndata).replace('\\', os.sep)+'.json' - ent_groupname=os.path.basename(entpath).split('.')[0]+'_'+app - while len(ent_groupname) > 63: - ent_groupname = ent_groupname[:-1] - imported=False - if ent_groupname in Masters.children.keys(): - move_coll=Masters.children.get(ent_groupname) - imported=True - else: - try: - #print('Importing ',entpath, ' using app ',app) - incoll='MasterInstances' - bpy.ops.io_scene_gltf.cp77entity(with_mats, filepath=entpath, appearances=app, inColl=incoll) + if spawntype=="Entity Template": + app=obj['spawnable']['app'] + entpath=os.path.join(project_path,'source','raw', spawndata).replace('\\', os.sep)+'.json' + ent_groupname=os.path.basename(entpath).split('.')[0]+'_'+app + while len(ent_groupname) > 63: + ent_groupname = ent_groupname[:-1] + imported=False + if ent_groupname in Masters.children.keys(): move_coll=Masters.children.get(ent_groupname) imported=True - except: - print(traceback.print_exc()) - print(f"Failed during Entity import on {entpath} from app {app}") - if imported: - group=move_coll - if (group): - groupname=move_coll.name - #print('Group found for ',groupname) - new=bpy.data.collections.new(groupname) - parent_coll.children.link(new) - new['nodeType']='worldEntityNode' - new['debugName']=obj['name'] - new['entityTemplate']=spawndata - new['appearanceName']=obj['spawnable']['app'] - - pos,rot,scale=get_position(obj) - rot=rot.to_quaternion() - new['ent_rot']=rot - new['ent_pos']=pos - inst_trans_mat=Matrix.LocRotScale(pos,rot,scale) - for child in group.children: - newchild=bpy.data.collections.new(child.name) - new.children.link(newchild) - for old_obj in child.objects: + else: + try: + #print('Importing ',entpath, ' using app ',app) + incoll='MasterInstances' + bpy.ops.io_scene_gltf.cp77entity(with_mats, filepath=entpath, appearances=app, inColl=incoll) + move_coll=Masters.children.get(ent_groupname) + imported=True + except: + print(traceback.print_exc()) + print(f"Failed during Entity import on {entpath} from app {app}") + if imported: + group=move_coll + if (group): + groupname=move_coll.name + #print('Group found for ',groupname) + new=bpy.data.collections.new(groupname) + parent_coll.children.link(new) + new['nodeType']='worldEntityNode' + new['debugName']=obj['name'] + new['entityTemplate']=spawndata + new['appearanceName']=obj['spawnable']['app'] + + pos,rot,scale=get_position(obj) + rot=rot.to_quaternion() + new['ent_rot']=rot + new['ent_pos']=pos + inst_trans_mat=Matrix.LocRotScale(pos,rot,scale) + for child in group.children: + newchild=bpy.data.collections.new(child.name) + new.children.link(newchild) + for old_obj in child.objects: + obj=old_obj.copy() + obj.color = (0.567942, 0.0247339, 0.600028, 1) + newchild.objects.link(obj) + obj.matrix_local= inst_trans_mat @ obj.matrix_local + if 'Armature' in obj.name: + obj.hide_set(True) + for old_obj in group.objects: obj=old_obj.copy() obj.color = (0.567942, 0.0247339, 0.600028, 1) - newchild.objects.link(obj) + new.objects.link(obj) obj.matrix_local= inst_trans_mat @ obj.matrix_local if 'Armature' in obj.name: obj.hide_set(True) - for old_obj in group.objects: - obj=old_obj.copy() - obj.color = (0.567942, 0.0247339, 0.600028, 1) - new.objects.link(obj) - obj.matrix_local= inst_trans_mat @ obj.matrix_local - if 'Armature' in obj.name: - obj.hide_set(True) - if len(group.all_objects)>0: - new['matrix']=group.all_objects[0].matrix_world + if len(group.all_objects)>0: + new['matrix']=group.all_objects[0].matrix_world + elif spawntype=="Collision Shape": + # from entspawner code: o.shapeTypes = { "Box", "Capsule", "Sphere" } so 0=box, 1=capsule, 2 = sphere + ShapeType=shapes[obj['spawnable']['shape']] + if ShapeType=='Box' : + #print('Box Collision Node') + #pprint(act['Shapes']) + extents=obj['spawnable']['extents'] + position=obj['spawnable']['position'] + if ShapeType=='Box': + bpy.ops.mesh.primitive_cube_add(size=1, scale=(float(extents['x'])*2,float(extents['y'])*2,float(extents['z'])*2), + location=(float(position['x']),float(position['y']),float(position['z']))) + #location=(float(position['x'])+float(extents['x'])*2,float(position['y'])+float(extents['y'])*2,float(position['z'])+float(extents['z'])*2)) + crash=C.selected_objects[0] + crash.name=obj['name'] + par_coll=crash.users_collection[0] + par_coll.objects.unlink(crash) + coll_scene.objects.link(crash) + crash['ShapeType']=obj['spawnable']['shape'] + crash['matrix']=crash.matrix_world + rot=obj['spawnable']['rotation'] + crash.rotation_mode='XYZ' + crash.rotation_euler=(radians(rot['pitch']),radians(rot['roll']),radians(rot['yaw'])) + elif spawntype=='Decals': vert = [(-0.5, -0.5, 0.0), (0.5, -0.5, 0.0), (-0.5, 0.5, 0.0), (0.5,0.5, 0.0)] fac = [(0, 1, 3, 2)] @@ -154,7 +178,7 @@ def process_object(obj,parent_coll): o['debugName']=obj['name'] o['horizontalFlip']=obj['spawnable']['horizontalFlip'] o['verticalFlip']=obj['spawnable']['verticalFlip'] - o['alpha']=obj['spawnable']['alpha'] + o['alpha']=obj['spawna-ble']['alpha'] o['appearanceName']=obj['spawnable']['app'] parent_coll.objects.link(o) From 88af25fa565c48dc4f70682c06d102b3e8b60b84 Mon Sep 17 00:00:00 2001 From: Simarilius-uk <29640139+Simarilius-uk@users.noreply.github.com> Date: Mon, 11 Nov 2024 00:47:26 +0000 Subject: [PATCH 2/3] Fix for the weight transfer tool. --- i_scene_cp77_gltf/meshtools/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/i_scene_cp77_gltf/meshtools/__init__.py b/i_scene_cp77_gltf/meshtools/__init__.py index 7ef919a..50f901b 100644 --- a/i_scene_cp77_gltf/meshtools/__init__.py +++ b/i_scene_cp77_gltf/meshtools/__init__.py @@ -142,17 +142,15 @@ class CP77WeightTransfer(Operator): bl_idname = 'cp77.trans_weights' bl_label = "Cyberpunk 2077 Weight Transfer Tool" bl_description = "Transfer weights from source mesh to target mesh" - bl_options = {'REGISTER', 'UNDO'} - vertInterop: BoolProperty( name="Use Nearest Vert Interpolated", description="Sometimes gives better results when the default mode fails", default=False) - bySubmesh: BoolProperty( name="Transfer by Submesh Order", description="Because Mana Gets what Mana Wants :D", default=False) + bl_options = {'REGISTER', 'UNDO'} def invoke(self, context, event): @@ -160,7 +158,7 @@ def invoke(self, context, event): def execute(self, context): # Call the trans_weights function with the provided arguments - result = trans_weights(self, context, False) + result = trans_weights(self, context, self.properties.vertInterop ) #, self.properties.bySubmesh) return {"FINISHED"} def draw(self,context): From 668b0000a216177eba46087f003b7a9cee84e24c Mon Sep 17 00:00:00 2001 From: Simarilius-uk <29640139+Simarilius-uk@users.noreply.github.com> Date: Mon, 11 Nov 2024 00:58:04 +0000 Subject: [PATCH 3/3] typo fix --- i_scene_cp77_gltf/resources/scripts/Import_from_OS.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/i_scene_cp77_gltf/resources/scripts/Import_from_OS.py b/i_scene_cp77_gltf/resources/scripts/Import_from_OS.py index 0998af5..cd06e6c 100644 --- a/i_scene_cp77_gltf/resources/scripts/Import_from_OS.py +++ b/i_scene_cp77_gltf/resources/scripts/Import_from_OS.py @@ -178,7 +178,7 @@ def process_object(obj,parent_coll): o['debugName']=obj['name'] o['horizontalFlip']=obj['spawnable']['horizontalFlip'] o['verticalFlip']=obj['spawnable']['verticalFlip'] - o['alpha']=obj['spawna-ble']['alpha'] + o['alpha']=obj['spawnable']['alpha'] o['appearanceName']=obj['spawnable']['app'] parent_coll.objects.link(o)