Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKalle-Samuli Riihikoski <haikalle@gmail.com>2018-08-28 17:38:09 +0300
committerKalle-Samuli Riihikoski <haikalle@gmail.com>2018-08-28 17:38:09 +0300
commit2c7e3137a1c2b4c74b102aa18c7fa23af26b48e9 (patch)
tree38122b38654e350b346a855060f2072bdb033681 /io_coat3D
parentfc59c46c1a50dd4da1841e09e4a074f6f03911a6 (diff)
Fixed if different objects has same material names
Diffstat (limited to 'io_coat3D')
-rw-r--r--io_coat3D/__init__.py93
-rw-r--r--io_coat3D/tex.py11
2 files changed, 94 insertions, 10 deletions
diff --git a/io_coat3D/__init__.py b/io_coat3D/__init__.py
index 9a2e4bd0..f1dab798 100644
--- a/io_coat3D/__init__.py
+++ b/io_coat3D/__init__.py
@@ -223,15 +223,15 @@ class SCENE_OT_export(bpy.types.Operator):
bl_options = {'UNDO'}
def invoke(self, context, event):
- '''
+
for mesh in bpy.data.meshes:
- if (mesh.users == 0):
+ if (mesh.users == 0 and mesh.coat3D.name == '3DC'):
bpy.data.meshes.remove(mesh)
for material in bpy.data.materials:
- if (material.users == 0):
+ if (material.users == 1 and material.coat3D.name == '3DC'):
bpy.data.materials.remove(material)
- '''
+
export_ok = False
coat3D = bpy.context.scene.coat3D
@@ -304,6 +304,7 @@ class SCENE_OT_export(bpy.types.Operator):
objekti.coat3D.applink_name = coa.applink_name
objekti.coat3D.applink_firsttime = True
objekti.coat3D.objecttime = str(os.path.getmtime(objekti.coat3D.applink_address))
+ objekti.data.coat3D.name = '3DC'
if(objekti.material_slots.keys() != []):
for material in objekti.material_slots:
@@ -323,15 +324,24 @@ class SCENE_OT_import(bpy.types.Operator):
bl_options = {'UNDO'}
def invoke(self, context, event):
- '''
+
for mesh in bpy.data.meshes:
- if(mesh.users == 0):
+ if(mesh.users == 0 and mesh.coat3D.name == '3DC'):
bpy.data.meshes.remove(mesh)
for material in bpy.data.materials:
- if (material.users == 0):
+ img_list = []
+ if (material.users == 1 and material.coat3D.name == '3DC'):
+ if material.use_nodes == True:
+ for node in material.node_tree.nodes:
+ if node.type == 'TEX_IMAGE' and node.name.startswith('3DC'):
+ img_list.append(node.image)
+ if img_list != []:
+ for del_img in img_list:
+ bpy.data.images.remove(bpy.data.images[del_img])
+
bpy.data.materials.remove(material)
- '''
+
coat3D = bpy.context.scene.coat3D
coat = bpy.coat3D
coat3D.exchangedir = set_exchange_folder()
@@ -406,6 +416,9 @@ class SCENE_OT_import(bpy.types.Operator):
diff_mat = [i for i in new_materials if i not in old_materials]
diff_objects = [i for i in new_objects if i not in old_objects]
diff_images = [i for i in new_images if i not in old_images]
+
+ for mark_mesh in diff_objects:
+ bpy.data.objects[mark_mesh].data.coat3D.name = '3DC'
for c_index in diff_mat:
bpy.data.materials.remove(bpy.data.materials[c_index])
for i in diff_images:
@@ -423,9 +436,46 @@ class SCENE_OT_import(bpy.types.Operator):
find_name = objekti.data.name + '-mesh'
find_name = find_name.replace('.', '_')
else:
- find_name = objekti.data.name + '.001'
+
+
+ new_name = objekti.data.name
+ print('Data nimi', objekti.data.name)
+ name_boxs = new_name.split('.')
+ if len(name_boxs) > 1:
+ if len(name_boxs[-1]) == 3:
+ luku = int(name_boxs[-1])
+ luku +=1
+ uusi_nimi = ("%s.%.3d" % (new_name[:-4], luku))
+ find_name = uusi_nimi
+ else:
+ print('tuullekko tienna')
+ find_name = objekti.data.name
+ tosi = True
+ luku = 1
+ find_name = ("%s.%.3d" % (objekti.data.name, luku))
+ loyty = False
+ while tosi:
+ print('etsitaan', find_name)
+ for obj in bpy.data.meshes:
+ if (obj.name == find_name):
+ loyty = True
+ break
+ if(loyty == True):
+ luku += 1
+ find_name = ("%s.%.3d" % (objekti.data.name, luku))
+ loyty = False
+ else:
+ find_name = ("%s.%.3d" % (objekti.data.name, luku-1))
+ tosi = False
+
+
+
+
+
+
for proxy_objects in diff_objects:
+ print('ovatko samoja',bpy.data.objects[proxy_objects].data.name,find_name)
if (bpy.data.objects[proxy_objects].data.name == find_name):
obj_proxy = bpy.data.objects[proxy_objects]
break
@@ -545,8 +595,26 @@ class SCENE_OT_import(bpy.types.Operator):
mat_list = []
nimi = ''
+ old_materials = bpy.data.materials.keys()
+ old_objects = bpy.data.objects.keys()
+
bpy.ops.wm.collada_import(filepath=new_applink_address)
+ new_materials = bpy.data.materials.keys()
+ new_objects = bpy.data.objects.keys()
+
+ diff_mat = [i for i in new_materials if i not in old_materials]
+ diff_objects = [i for i in new_objects if i not in old_objects]
+
+ for mark_mesh in diff_mat:
+ bpy.data.materials[mark_mesh].coat3D.name = '3DC'
+ bpy.data.materials[mark_mesh].use_fake_user = True
+ laskuri = 0
+ for c_index in diff_objects:
+ bpy.data.objects[c_index].data.coat3D.name = '3DC'
+ bpy.data.objects[c_index].material_slots[0].material = bpy.data.materials[diff_mat[laskuri]]
+ laskuri += 1
+
bpy.ops.object.select_all(action='DESELECT')
for new_obj in bpy.context.collection.objects:
@@ -867,6 +935,11 @@ class MeshCoat3D(PropertyGroup):
name="ApplinkAddress",
subtype="APPLINK_ADDRESS",
)
+class MaterialCoat3D(PropertyGroup):
+ name: StringProperty(
+ name="ApplinkAddress",
+ subtype="APPLINK_ADDRESS",
+ )
classes = (
@@ -881,6 +954,7 @@ classes = (
ObjectCoat3D,
SceneCoat3D,
MeshCoat3D,
+ MaterialCoat3D,
)
def register():
@@ -896,6 +970,7 @@ def register():
bpy.types.Object.coat3D = PointerProperty(type=ObjectCoat3D)
bpy.types.Scene.coat3D = PointerProperty(type=SceneCoat3D)
bpy.types.Mesh.coat3D = PointerProperty(type=MeshCoat3D)
+ bpy.types.Material.coat3D = PointerProperty(type=MaterialCoat3D)
kc = bpy.context.window_manager.keyconfigs.addon
diff --git a/io_coat3D/tex.py b/io_coat3D/tex.py
index b682c8df..59e41a61 100644
--- a/io_coat3D/tex.py
+++ b/io_coat3D/tex.py
@@ -46,11 +46,19 @@ def readtexturefolder(objekti,is_new): #read textures from texture file
files = os.listdir(files_dir)
materiaali_muutos = objekti.active_material.name
uusin_mat = materiaali_muutos.replace('Material.','Material_')
+ print('tassa pitaisi olla jotain outoo')
+ print(obj_coat.applink_name + '_' + uusin_mat)
+ new_name = (obj_coat.applink_name + '_' + uusin_mat)
+ name_boxs = new_name.split('.')
+ if len(name_boxs) > 1:
+ if len(name_boxs[-1]) == 3:
+ new_name = new_name[:-4]
for i in files:
- if(i.startswith(obj_coat.applink_name + '_' + uusin_mat)):
+ if(i.startswith(new_name)):
koko_osoite = files_dir + os.sep + i
listed = re.split(r'[_.]', i)
tex_name = listed[-2]
+ print('koko osoite', koko_osoite)
texcoat[tex_name].append(koko_osoite)
createnodes(objekti, texcoat)
@@ -77,6 +85,7 @@ def createnodes(objekti,texcoat): #luo nodes palikat ja linkittaa tekstuurit nii
for node in act_material.node_tree.nodes:
if(node.type == 'TEX_IMAGE'):
+ print('hhheeetkinen')
if(node.name == '3DC_color'):
bring_color = False
node.image.reload()