Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-addons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-addons
Commits
a650e83e
Commit
a650e83e
authored
7 years ago
by
Kalle-Samuli Riihikoski
Browse files
Options
Downloads
Patches
Plain Diff
blender 2.8 update
parent
2a0d3baf
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
io_coat3D/__init__.py
+18
-8
18 additions, 8 deletions
io_coat3D/__init__.py
io_coat3D/coat.py
+197
-236
197 additions, 236 deletions
io_coat3D/coat.py
io_coat3D/tex.py
+135
-4
135 additions, 4 deletions
io_coat3D/tex.py
with
350 additions
and
248 deletions
io_coat3D/__init__.py
+
18
−
8
View file @
a650e83e
...
@@ -20,7 +20,7 @@ bl_info = {
...
@@ -20,7 +20,7 @@ bl_info = {
"
name
"
:
"
3D-Coat Applink
"
,
"
name
"
:
"
3D-Coat Applink
"
,
"
author
"
:
"
Kalle-Samuli Riihikoski (haikalle)
"
,
"
author
"
:
"
Kalle-Samuli Riihikoski (haikalle)
"
,
"
version
"
:
(
3
,
5
,
22
),
"
version
"
:
(
3
,
5
,
22
),
"
blender
"
:
(
2
,
59
,
0
),
"
blender
"
:
(
2
,
8
,
0
),
"
location
"
:
"
Scene > 3D-Coat Applink
"
,
"
location
"
:
"
Scene > 3D-Coat Applink
"
,
"
description
"
:
"
Transfer data between 3D-Coat/Blender
"
,
"
description
"
:
"
Transfer data between 3D-Coat/Blender
"
,
"
warning
"
:
""
,
"
warning
"
:
""
,
...
@@ -59,9 +59,24 @@ def register():
...
@@ -59,9 +59,24 @@ def register():
objpath
=
StringProperty
(
objpath
=
StringProperty
(
name
=
"
Object_Path
"
name
=
"
Object_Path
"
)
)
applink_address
=
StringProperty
(
name
=
"
Object_Applink_address
"
)
applink_name
=
StringProperty
(
applink_name
=
StringProperty
(
name
=
"
Object_Applink_
name
"
name
=
"
Applink object
name
"
)
)
applink_group
=
StringProperty
(
name
=
"
Applink group
"
)
applink_skip
=
StringProperty
(
name
=
"
Object_Applink_Update
"
,
default
=
"
False
"
)
applink_firsttime
=
BoolProperty
(
name
=
"
FirstTime
"
,
description
=
"
FirstTime
"
,
default
=
True
)
coatpath
=
StringProperty
(
coatpath
=
StringProperty
(
name
=
"
Coat_Path
"
name
=
"
Coat_Path
"
)
)
...
@@ -216,12 +231,7 @@ def register():
...
@@ -216,12 +231,7 @@ def register():
)
)
# copy location
# copy location
cursor
=
FloatVectorProperty
(
name
=
"
Cursor
"
,
description
=
"
Location
"
,
subtype
=
"
XYZ
"
,
default
=
(
0.0
,
0.0
,
0.0
)
)
loca
=
FloatVectorProperty
(
loca
=
FloatVectorProperty
(
name
=
"
location
"
,
name
=
"
location
"
,
description
=
"
Location
"
,
description
=
"
Location
"
,
...
...
This diff is collapsed.
Click to expand it.
io_coat3D/coat.py
+
197
−
236
View file @
a650e83e
...
@@ -21,6 +21,7 @@ import bpy
...
@@ -21,6 +21,7 @@ import bpy
from
bpy.props
import
*
from
bpy.props
import
*
from
io_coat3D
import
tex
from
io_coat3D
import
tex
import
os
import
os
import
ntpath
bpy
.
coat3D
=
dict
()
bpy
.
coat3D
=
dict
()
...
@@ -133,9 +134,8 @@ class SCENE_PT_Main(ObjectButtonsPanel,bpy.types.Panel):
...
@@ -133,9 +134,8 @@ class SCENE_PT_Main(ObjectButtonsPanel,bpy.types.Panel):
import_no
=
0
import_no
=
0
coat
=
bpy
.
coat3D
coat
=
bpy
.
coat3D
coat3D
=
bpy
.
context
.
scene
.
coat3D
coat3D
=
bpy
.
context
.
scene
.
coat3D
if
(
bpy
.
context
.
scene
.
objects
.
active
):
if
(
bpy
.
context
.
active_object
):
coa
=
bpy
.
context
.
scene
.
objects
.
active
.
coat3D
coa
=
bpy
.
context
.
active_object
.
coat3D
if
(
bpy
.
coat3D
[
'
status
'
]
==
0
and
not
(
os
.
path
.
isdir
(
coat3D
.
exchangedir
))):
if
(
bpy
.
coat3D
[
'
status
'
]
==
0
and
not
(
os
.
path
.
isdir
(
coat3D
.
exchangedir
))):
bpy
.
coat3D
[
'
active_coat
'
]
=
set_exchange_folder
()
bpy
.
coat3D
[
'
active_coat
'
]
=
set_exchange_folder
()
...
@@ -147,8 +147,6 @@ class SCENE_PT_Main(ObjectButtonsPanel,bpy.types.Panel):
...
@@ -147,8 +147,6 @@ class SCENE_PT_Main(ObjectButtonsPanel,bpy.types.Panel):
row
.
prop
(
coat3D
,
"
exchangedir
"
,
text
=
""
)
row
.
prop
(
coat3D
,
"
exchangedir
"
,
text
=
""
)
else
:
else
:
#Here you add your GUI
#Here you add your GUI
row
=
layout
.
row
()
row
=
layout
.
row
()
row
.
prop
(
coat3D
,
"
type
"
,
text
=
""
)
row
.
prop
(
coat3D
,
"
type
"
,
text
=
""
)
...
@@ -157,18 +155,9 @@ class SCENE_PT_Main(ObjectButtonsPanel,bpy.types.Panel):
...
@@ -157,18 +155,9 @@ class SCENE_PT_Main(ObjectButtonsPanel,bpy.types.Panel):
colR
=
row
.
column
()
colR
=
row
.
column
()
colR
.
operator
(
"
export_applink.pilgway_3d_coat
"
,
text
=
"
Transfer
"
)
colR
.
operator
(
"
export_applink.pilgway_3d_coat
"
,
text
=
"
Transfer
"
)
colL
.
operator
(
"
import_applink.pilgway_3d_coat
"
,
text
=
"
Update
"
)
colL
.
operator
(
"
import_applink.pilgway_3d_coat
"
,
text
=
"
Update
"
)
class
SCENE_OT_export
(
bpy
.
types
.
Operator
):
class
SCENE_OT_export
(
bpy
.
types
.
Operator
):
bl_idname
=
"
export_applink.pilgway_3d_coat
"
bl_idname
=
"
export_applink.pilgway_3d_coat
"
bl_label
=
"
Export your custom property
"
bl_label
=
"
Export your custom property
"
...
@@ -180,8 +169,7 @@ class SCENE_OT_export(bpy.types.Operator):
...
@@ -180,8 +169,7 @@ class SCENE_OT_export(bpy.types.Operator):
coat3D
=
bpy
.
context
.
scene
.
coat3D
coat3D
=
bpy
.
context
.
scene
.
coat3D
scene
=
context
.
scene
scene
=
context
.
scene
activeobj
=
bpy
.
context
.
active_object
.
name
activeobj
=
bpy
.
context
.
active_object
.
name
obj
=
scene
.
objects
[
activeobj
]
coa
=
bpy
.
context
.
active_object
.
coat3D
coa
=
bpy
.
context
.
scene
.
objects
.
active
.
coat3D
coat3D
.
exchangedir
=
set_exchange_folder
()
coat3D
.
exchangedir
=
set_exchange_folder
()
export_ok
=
False
export_ok
=
False
...
@@ -206,44 +194,28 @@ class SCENE_OT_export(bpy.types.Operator):
...
@@ -206,44 +194,28 @@ class SCENE_OT_export(bpy.types.Operator):
looking
=
True
looking
=
True
object_index
=
0
object_index
=
0
if
(
coa
.
applink_
name
and
os
.
path
.
isfile
(
coa
.
applink_
name
)):
if
(
coa
.
applink_
address
and
os
.
path
.
isfile
(
coa
.
applink_
address
)):
checkname
=
coa
.
applink_
name
checkname
=
coa
.
applink_
address
else
:
else
:
while
(
looking
==
True
):
while
(
looking
==
True
):
checkname
=
folder_objects
+
os
.
sep
+
activeobj
checkname
=
folder_objects
+
os
.
sep
+
activeobj
checkname
=
(
"
%s%.2d.
obj
"
%
(
checkname
,
object_index
))
checkname
=
(
"
%s%.2d.
dae
"
%
(
checkname
,
object_index
))
if
(
os
.
path
.
isfile
(
checkname
)):
if
(
os
.
path
.
isfile
(
checkname
)):
object_index
+=
1
object_index
+=
1
else
:
else
:
looking
=
False
looking
=
False
coa
.
applink_name
=
checkname
coa
.
applink_name
=
(
"
%s%.2d
"
%
(
activeobj
,
object_index
))
coa
.
applink_address
=
checkname
for
objekti
in
bpy
.
context
.
selected_objects
:
coat3D
.
cursor_loc
=
obj
.
location
if
(
objekti
.
material_slots
.
keys
()
==
[]):
coat3D
.
cursor_orginal
=
bpy
.
context
.
scene
.
cursor_location
bpy
.
ops
.
material
.
new
()
objekti
.
data
.
materials
.
append
(
bpy
.
data
.
materials
[
-
1
])
coa
.
loc
=
obj
.
location
coa
.
rot
=
obj
.
rotation_euler
coa
.
sca
=
obj
.
scale
coa
.
dime
=
obj
.
dimensions
obj
.
location
=
(
0
,
0
,
0
)
obj
.
rotation_euler
=
(
0
,
0
,
0
)
bpy
.
ops
.
object
.
transform_apply
(
scale
=
True
)
bpy
.
ops
.
export_scene
.
obj
(
filepath
=
coa
.
applink_name
,
use_selection
=
True
,
use_mesh_modifiers
=
False
,
use_blen_objects
=
True
,
use_materials
=
True
,
keep_vertex_order
=
True
,
axis_forward
=
'
-Z
'
,
axis_up
=
'
Y
'
)
obj
.
location
=
coa
.
loc
bpy
.
ops
.
object
.
origin_set
(
type
=
'
ORIGIN_GEOMETRY
'
)
obj
.
rotation_euler
=
coa
.
rot
bpy
.
ops
.
wm
.
collada_export
(
filepath
=
coa
.
applink_address
,
selected
=
True
,
bpy
.
context
.
scene
.
cursor_location
=
coat3D
.
cursor_loc
apply_modifiers
=
False
,
triangulate
=
False
)
bpy
.
context
.
scene
.
cursor_location
=
coat3D
.
cursor_orginal
file
=
open
(
importfile
,
"
w
"
)
file
=
open
(
importfile
,
"
w
"
)
file
.
write
(
"
%s
"
%
(
checkname
))
file
.
write
(
"
%s
"
%
(
checkname
))
...
@@ -251,9 +223,15 @@ class SCENE_OT_export(bpy.types.Operator):
...
@@ -251,9 +223,15 @@ class SCENE_OT_export(bpy.types.Operator):
file
.
write
(
"
\n
[%s]
"
%
(
coat3D
.
type
))
file
.
write
(
"
\n
[%s]
"
%
(
coat3D
.
type
))
file
.
write
(
"
\n
[TexOutput:%s]
"
%
(
folder_textures
))
file
.
write
(
"
\n
[TexOutput:%s]
"
%
(
folder_textures
))
file
.
close
()
file
.
close
()
group_index
=
-
1.0
coa
.
objecttime
=
str
(
os
.
path
.
getmtime
(
coa
.
applink_name
))
for
objekti
in
bpy
.
context
.
selected_objects
:
objekti
.
coat3D
.
applink_group
=
''
.
join
(
str
(
bpy
.
context
.
selected_objects
))
objekti
.
coat3D
.
applink_address
=
coa
.
applink_address
objekti
.
coat3D
.
applink_name
=
coa
.
applink_name
objekti
.
coat3D
.
applink_firsttime
=
True
#coa.objecttime = str(os.path.getmtime(coa.applink_address))
return
{
'
FINISHED
'
}
return
{
'
FINISHED
'
}
...
@@ -265,12 +243,9 @@ class SCENE_OT_import(bpy.types.Operator):
...
@@ -265,12 +243,9 @@ class SCENE_OT_import(bpy.types.Operator):
bl_options
=
{
'
UNDO
'
}
bl_options
=
{
'
UNDO
'
}
def
invoke
(
self
,
context
,
event
):
def
invoke
(
self
,
context
,
event
):
scene
=
context
.
scene
coat3D
=
bpy
.
context
.
scene
.
coat3D
coat3D
=
bpy
.
context
.
scene
.
coat3D
coat
=
bpy
.
coat3D
coat
=
bpy
.
coat3D
test
=
bpy
.
context
.
selected_objects
act_first
=
bpy
.
context
.
scene
.
objects
.
active
bpy
.
context
.
scene
.
game_settings
.
material_mode
=
'
GLSL
'
coat3D
.
exchangedir
=
set_exchange_folder
()
coat3D
.
exchangedir
=
set_exchange_folder
()
folder_objects
,
folder_textures
=
set_working_folders
()
folder_objects
,
folder_textures
=
set_working_folders
()
...
@@ -280,220 +255,206 @@ class SCENE_OT_import(bpy.types.Operator):
...
@@ -280,220 +255,206 @@ class SCENE_OT_import(bpy.types.Operator):
path3b_now
=
coat3D
.
exchangedir
path3b_now
=
coat3D
.
exchangedir
path3b_now
+=
(
'
last_saved_3b_file.txt
'
)
path3b_now
+=
(
'
last_saved_3b_file.txt
'
)
Blender_export
+=
(
'
%sexport.txt
'
%
(
os
.
sep
))
Blender_export
+=
(
'
%sexport.txt
'
%
(
os
.
sep
))
new_applink_
name
=
'
False
'
new_applink_
address
=
'
False
'
new_object
=
False
new_object
=
False
if
(
os
.
path
.
isfile
(
Blender_export
)):
if
(
os
.
path
.
isfile
(
Blender_export
)):
obj_pathh
=
open
(
Blender_export
)
obj_pathh
=
open
(
Blender_export
)
new_object
=
True
new_object
=
True
for
line
in
obj_pathh
:
for
line
in
obj_pathh
:
new_applink_
name
=
line
new_applink_
address
=
line
break
break
obj_pathh
.
close
()
obj_pathh
.
close
()
for
scene_objects
in
bpy
.
context
.
scene
.
objects
:
for
scene_objects
in
bpy
.
context
.
scene
.
objects
:
if
(
scene_objects
.
type
==
'
MESH
'
):
if
(
scene_objects
.
type
==
'
MESH
'
):
if
(
scene_objects
.
coat3D
.
applink_
name
==
new_applink_
name
):
if
(
scene_objects
.
coat3D
.
applink_
address
==
new_applink_
address
):
new_object
=
False
new_object
=
False
for
act_name
in
test
:
if
(
new_object
==
False
):
coa
=
act_name
.
coat3D
path_object
=
coa
.
applink_name
#Blender -> 3DC -> Blender workflow
if
act_name
.
type
==
'
MESH
'
and
os
.
path
.
isfile
(
path_object
):
multires_on
=
False
for
objekti
in
bpy
.
context
.
scene
.
objects
:
activeobj
=
act_name
.
name
obj_coat
=
objekti
.
coat3D
mat_list
=
[]
scene
.
objects
[
activeobj
].
select
=
True
if
(
obj_coat
.
applink_address
!=
''
and
os
.
path
.
isfile
(
obj_coat
.
applink_address
)
and
obj_coat
.
applink_skip
==
'
False
'
):
objekti
=
scene
.
objects
[
activeobj
]
obj_coat
.
applink_skip
=
'
True
'
coat3D
.
loca
=
objekti
.
location
objekti
.
select_set
(
'
SELECT
'
)
coat3D
.
rota
=
objekti
.
rotation_euler
exportfile
=
coat3D
.
exchangedir
coat3D
.
dime
=
objekti
.
scale
path3b_n
=
coat3D
.
exchangedir
path3b_n
+=
(
'
last_saved_3b_file.txt
'
)
exportfile
+=
(
'
%sexport.txt
'
%
(
os
.
sep
))
if
(
os
.
path
.
isfile
(
exportfile
)):
#See if there is multres modifier.
export_file
=
open
(
exportfile
)
for
modifiers
in
objekti
.
modifiers
:
for
line
in
export_file
:
if
modifiers
.
type
==
'
MULTIRES
'
and
(
modifiers
.
total_levels
>
0
):
if
line
.
rfind
(
'
.3b
'
):
if
(
not
(
coat3D
.
importlevel
)):
objekti
.
coat3D
.
coatpath
=
line
bpy
.
ops
.
object
.
multires_external_pack
()
coat
[
'
active_coat
'
]
=
line
multires
=
coat3D
.
exchangedir
export_file
.
close
()
multires
+=
(
'
%stemp.btx
'
%
(
os
.
sep
))
os
.
remove
(
exportfile
)
bpy
.
ops
.
object
.
multires_external_save
(
filepath
=
multires
)
#bpy.ops.object.multires_external_pack()
multires_on
=
True
obj_names
=
objekti
.
coat3D
.
applink_group
multires_name
=
modifiers
.
name
obj_names
=
obj_names
[
1
:
-
1
]
break
obj_list
=
obj_names
.
split
(
'
,
'
)
applinks
=
[]
mat_list
=
[]
for
app_obj
in
obj_list
:
pnimi
=
app_obj
.
lstrip
()
for
tobj
in
bpy
.
context
.
scene
.
collection
.
all_objects
:
if
(
pnimi
.
find
(
tobj
.
name
)
>
0
):
applinks
.
append
(
tobj
)
if
(
obj_coat
.
objecttime
!=
str
(
os
.
path
.
getmtime
(
obj_coat
.
applink_address
))):
materials_old
=
bpy
.
data
.
materials
.
keys
()
obj_coat
.
dime
=
objekti
.
dimensions
obj_coat
.
objecttime
=
str
(
os
.
path
.
getmtime
(
obj_coat
.
applink_address
))
bpy
.
ops
.
wm
.
collada_import
(
filepath
=
obj_coat
.
applink_address
)
bpy
.
ops
.
object
.
select_all
(
action
=
'
DESELECT
'
)
materials_new
=
bpy
.
data
.
materials
.
keys
()
new_ma
=
list
(
set
(
materials_new
).
difference
(
set
(
materials_old
)))
proxy_index
=
-
1
#bpy.data.materials.remove(bpy.data.materials[-1])
counter
=
1
del_list
=
[]
for
obe
in
applinks
:
counter
+=
1
obe
.
coat3D
.
applink_skip
=
'
True
'
if
(
obe
.
coat3D
.
applink_address
==
objekti
.
coat3D
.
applink_address
and
obe
.
type
==
'
MESH
'
):
use_smooth
=
obe
.
data
.
polygons
[
0
].
use_smooth
if
(
obe
.
material_slots
):
act_mat
=
obe
.
active_material
for
obj_mat
in
obe
.
material_slots
:
mat_list
.
append
(
obj_mat
.
material
)
#finds a object that was imported
find_name
=
obe
.
name
+
'
-mesh
'
for
allobjekti
in
bpy
.
context
.
scene
.
collection
.
all_objects
:
print
(
'
allobject
'
,
allobjekti
)
print
(
'
find_name
'
,
find_name
)
if
(
allobjekti
.
name
==
find_name
):
obj_proxy
=
allobjekti
del_list
.
append
(
allobjekti
)
break
if
(
del_list
==
[]):
find_name
=
obe
.
name
+
'
.001
'
for
allobjekti
in
bpy
.
context
.
scene
.
collection
.
all_objects
:
if
(
allobjekti
.
name
==
find_name
):
obj_proxy
=
allobjekti
del_list
.
append
(
allobjekti
)
break
bpy
.
ops
.
object
.
select_all
(
action
=
'
DESELECT
'
)
print
(
'
ja mitahan tassa
'
,
obj_proxy
)
obj_proxy
.
select_set
(
'
SELECT
'
)
bpy
.
ops
.
object
.
select_all
(
action
=
'
TOGGLE
'
)
if
(
coat3D
.
importlevel
):
obj_proxy
.
select
=
True
obj_proxy
.
modifiers
.
new
(
name
=
'
temp
'
,
type
=
'
MULTIRES
'
)
obe
.
select
=
True
bpy
.
ops
.
object
.
multires_reshape
(
modifier
=
multires_name
)
bpy
.
ops
.
object
.
select_all
(
action
=
'
TOGGLE
'
)
multires_on
=
False
else
:
#scene.objects.active = obj_proxy HACKKI
obj_proxy
.
select_set
(
'
SELECT
'
)
obj_data
=
obe
.
data
.
id_data
obe
.
data
=
obj_proxy
.
data
.
id_data
if
(
bpy
.
data
.
meshes
[
obj_data
.
name
].
users
==
0
):
obe
.
data
.
id_data
.
name
=
obj_data
.
name
bpy
.
data
.
meshes
.
remove
(
obj_data
)
objekti
.
select_set
(
'
SELECT
'
)
if
(
obe
.
coat3D
.
applink_firsttime
==
True
):
obe
.
scale
=
(
1
,
1
,
1
)
obe
.
coat3D
.
applink_firsttime
=
False
print
(
'
toimiiko
'
,
objekti
)
bpy
.
ops
.
object
.
origin_set
(
type
=
'
GEOMETRY_ORIGIN
'
)
proxy_index
-=
1
obe
.
material_slots
[
0
].
material
=
act_mat
bpy
.
ops
.
object
.
select_all
(
action
=
'
DESELECT
'
)
for
deleting
in
del_list
:
deleting
.
select_set
(
action
=
'
SELECT
'
)
bpy
.
ops
.
object
.
delete
()
mat_index
=
0
for
obe
in
applinks
:
bpy
.
data
.
materials
.
remove
(
bpy
.
data
.
materials
[
new_ma
[
mat_index
]])
mat_index
+=
1
if
(
use_smooth
):
for
data_mesh
in
obe
.
data
.
polygons
:
data_mesh
.
use_smooth
=
True
if
(
os
.
path
.
isfile
(
path3b_n
)):
path3b_fil
=
open
(
path3b_n
)
for
lin
in
path3b_fil
:
objekti
.
coat3D
.
path3b
=
lin
path3b_fil
.
close
()
os
.
remove
(
path3b_n
)
if
(
coat3D
.
importmesh
and
not
(
os
.
path
.
isfile
(
objekti
.
coat3D
.
applink_address
))):
coat3D
.
importmesh
=
False
for
obe
in
applinks
:
obe
.
select_set
(
'
SELECT
'
)
if
(
coat3D
.
importtextures
):
is_new
=
False
tex
.
matlab
(
mat_list
,
obe
,
bpy
.
context
.
scene
,
is_new
)
obe
.
select_set
(
'
DESELECT
'
)
for
objekti
in
bpy
.
context
.
scene
.
objects
:
objekti
.
coat3D
.
applink_skip
=
'
False
'
else
:
# 3DC -> Blender workflow
exportfile
=
coat3D
.
exchangedir
path3b_n
=
coat3D
.
exchangedir
path3b_n
+=
(
'
last_saved_3b_file.txt
'
)
exportfile
+=
(
'
%sexport.txt
'
%
(
os
.
sep
))
if
(
os
.
path
.
isfile
(
exportfile
)):
export_file
=
open
(
exportfile
)
for
line
in
export_file
:
if
line
.
rfind
(
'
.3b
'
):
objekti
.
coat3D
.
coatpath
=
line
coat
[
'
active_coat
'
]
=
line
export_file
.
close
()
os
.
remove
(
exportfile
)
if
(
len
(
objekti
.
material_slots
)
==
0
):
delete_material
=
False
else
:
delete_material
=
True
if
(
not
(
objekti
.
active_material
)
and
objekti
.
material_slots
):
act_mat_index
=
objekti
.
active_material_index
materials_old
=
bpy
.
data
.
materials
.
keys
()
bpy
.
ops
.
material
.
new
()
materials_new
=
bpy
.
data
.
materials
.
keys
()
new_ma
=
list
(
set
(
materials_new
).
difference
(
set
(
materials_old
)))
new_mat
=
new_ma
[
0
]
ki
=
bpy
.
data
.
materials
[
new_mat
]
objekti
.
material_slots
[
act_mat_index
].
material
=
ki
if
(
os
.
path
.
isfile
(
path_object
)
and
(
coa
.
objecttime
!=
str
(
os
.
path
.
getmtime
(
path_object
)))):
if
(
objekti
.
material_slots
):
act_mat_index
=
objekti
.
active_material_index
for
obj_mat
in
objekti
.
material_slots
:
mat_list
.
append
(
obj_mat
.
material
)
coa
.
dime
=
objekti
.
dimensions
coa
.
objecttime
=
str
(
os
.
path
.
getmtime
(
path_object
))
mtl
=
coa
.
applink_name
mtl
=
mtl
.
replace
(
'
.obj
'
,
'
.mtl
'
)
if
(
os
.
path
.
isfile
(
mtl
)):
os
.
remove
(
mtl
)
bpy
.
ops
.
import_scene
.
obj
(
filepath
=
path_object
,
axis_forward
=
'
-Z
'
,
axis_up
=
'
Y
'
,
use_image_search
=
False
)
obj_proxy
=
scene
.
objects
[
0
]
bpy
.
ops
.
object
.
select_all
(
action
=
'
TOGGLE
'
)
obj_proxy
.
select
=
True
bpy
.
ops
.
object
.
transform_apply
(
rotation
=
True
)
proxy_mat
=
obj_proxy
.
material_slots
[
0
].
material
if
(
delete_material
):
while
(
list
(
obj_proxy
.
data
.
materials
)
!=
[]):
proxy_mat
=
obj_proxy
.
material_slots
[
0
].
material
obj_proxy
.
data
.
materials
.
pop
(
0
,
1
)
proxy_mat
.
user_clear
()
bpy
.
data
.
materials
.
remove
(
proxy_mat
)
bpy
.
ops
.
object
.
select_all
(
action
=
'
TOGGLE
'
)
if
(
coat3D
.
importlevel
):
obj_proxy
.
select
=
True
obj_proxy
.
modifiers
.
new
(
name
=
'
temp
'
,
type
=
'
MULTIRES
'
)
objekti
.
select
=
True
bpy
.
ops
.
object
.
multires_reshape
(
modifier
=
multires_name
)
bpy
.
ops
.
object
.
select_all
(
action
=
'
TOGGLE
'
)
multires_on
=
False
else
:
scene
.
objects
.
active
=
obj_proxy
obj_data
=
objekti
.
data
.
id_data
objekti
.
data
=
obj_proxy
.
data
.
id_data
if
(
bpy
.
data
.
meshes
[
obj_data
.
name
].
users
==
0
):
objekti
.
data
.
id_data
.
name
=
obj_data
.
name
bpy
.
data
.
meshes
.
remove
(
obj_data
)
obj_proxy
.
select
=
True
bpy
.
ops
.
object
.
delete
()
objekti
.
select
=
True
objekti
.
scale
=
coat3D
.
dime
bpy
.
context
.
scene
.
objects
.
active
=
objekti
if
(
os
.
path
.
isfile
(
path3b_n
)):
path3b_fil
=
open
(
path3b_n
)
for
lin
in
path3b_fil
:
objekti
.
coat3D
.
path3b
=
lin
path3b_fil
.
close
()
os
.
remove
(
path3b_n
)
if
(
coat3D
.
importmesh
and
not
(
os
.
path
.
isfile
(
path_object
))):
coat3D
.
importmesh
=
False
if
(
mat_list
and
coat3D
.
importmesh
):
for
mat_one
in
mat_list
:
objekti
.
data
.
materials
.
append
(
mat_one
)
objekti
.
active_material_index
=
act_mat_index
if
(
mat_list
):
for
obj_mate
in
objekti
.
material_slots
:
if
(
hasattr
(
obj_mate
.
material
,
'
texture_slots
'
)):
for
tex_slot
in
obj_mate
.
material
.
texture_slots
:
if
(
hasattr
(
tex_slot
,
'
texture
'
)):
if
(
tex_slot
.
texture
.
type
==
'
IMAGE
'
):
if
tex_slot
.
texture
.
image
is
not
None
:
tex_slot
.
texture
.
image
.
reload
()
if
(
coat3D
.
importtextures
):
export
=
''
tex
.
gettex
(
mat_list
,
objekti
,
scene
,
export
)
if
(
multires_on
):
temp_file
=
coat3D
.
exchangedir
temp_file
+=
(
'
%stemp2.btx
'
%
(
os
.
sep
))
if
(
objekti
.
modifiers
[
multires_name
].
levels
==
0
):
objekti
.
modifiers
[
multires_name
].
levels
=
1
bpy
.
ops
.
object
.
multires_external_save
(
filepath
=
temp_file
)
objekti
.
modifiers
[
multires_name
].
filepath
=
multires
objekti
.
modifiers
[
multires_name
].
levels
=
0
else
:
bpy
.
ops
.
object
.
multires_external_save
(
filepath
=
temp_file
)
objekti
.
modifiers
[
multires_name
].
filepath
=
multires
#bpy.ops.object.multires_external_pack()
bpy
.
ops
.
object
.
shade_smooth
()
for
act_name
in
test
:
act_name
.
select
=
True
bpy
.
context
.
scene
.
objects
.
active
=
act_first
if
(
new_object
==
True
):
coat3D
=
bpy
.
context
.
scene
.
coat3D
coat3D
=
bpy
.
context
.
scene
.
coat3D
scene
=
context
.
scene
scene
=
context
.
scene
Blender_folder
=
(
"
%s%sBlender
"
%
(
coat3D
.
exchangedir
,
os
.
sep
))
Blender_folder
=
(
"
%s%sBlender
"
%
(
coat3D
.
exchangedir
,
os
.
sep
))
Blender_export
=
Blender_folder
Blender_export
=
Blender_folder
path3b_now
=
coat3D
.
exchangedir
path3b_now
=
coat3D
.
exchangedir
path3b_now
+=
(
'
last_saved_3b_file.txt
'
)
path3b_now
+=
(
'
last_saved_3b_file.txt
'
)
Blender_export
+=
(
'
%sexport.txt
'
%
(
os
.
sep
))
Blender_export
+=
(
'
%sexport.txt
'
%
(
os
.
sep
))
mat_list
=
[]
mat_list
=
[]
obj_path
=
''
new_applink_address
=
new_applink_address
.
replace
(
'
.obj
'
,
'
.dae
'
)
bpy
.
ops
.
wm
.
collada_import
(
filepath
=
new_applink_address
)
export
=
new_applink_name
new_obj
=
bpy
.
context
.
collection
.
objects
[
-
1
]
mod_time
=
os
.
path
.
getmtime
(
new_applink_name
)
new_obj
.
coat3D
.
applink_address
=
new_applink_address
mtl_list
=
new_applink_name
.
replace
(
'
.obj
'
,
'
.mtl
'
)
splittext
=
ntpath
.
basename
(
new_applink_address
)
if
(
os
.
path
.
isfile
(
mtl_list
)):
new_obj
.
coat3D
.
applink_name
=
splittext
.
split
(
'
.
'
)[
0
]
os
.
remove
(
mtl_list
)
new_obj
.
coat3D
.
applink_group
=
''
.
join
(
str
(
new_obj
))
bpy
.
ops
.
import_scene
.
obj
(
filepath
=
new_applink_name
,
axis_forward
=
'
-Z
'
,
axis_up
=
'
Y
'
)
bpy
.
ops
.
object
.
transform_apply
(
rotation
=
True
)
new_obj
=
scene
.
objects
[
0
]
new_obj
.
coat3D
.
applink_name
=
obj_path
scene
.
objects
[
0
].
coat3D
.
applink_name
=
export
#objectdir muutettava
os
.
remove
(
Blender_export
)
os
.
remove
(
Blender_export
)
new_obj
.
select_set
(
'
SELECT
'
)
bpy
.
ops
.
object
.
origin_set
(
type
=
'
GEOMETRY_ORIGIN
'
)
bpy
.
context
.
scene
.
objects
.
active
=
new_obj
bpy
.
ops
.
object
.
shade_smooth
()
Blender_tex
=
(
"
%s%stextures.txt
"
%
(
coat3D
.
exchangedir
,
os
.
sep
))
mat_list
.
append
(
new_obj
.
material_slots
[
0
].
material
)
mat_list
.
append
(
new_obj
.
material_slots
[
0
].
material
)
tex
.
gettex
(
mat_list
,
new_obj
,
scene
,
export
)
is_new
=
True
tex
.
matlab
(
mat_list
,
new_obj
,
bpy
.
context
.
scene
,
is_new
)
return
{
'
FINISHED
'
}
return
{
'
FINISHED
'
}
...
...
This diff is collapsed.
Click to expand it.
io_coat3D/tex.py
+
135
−
4
View file @
a650e83e
...
@@ -19,8 +19,9 @@
...
@@ -19,8 +19,9 @@
import
bpy
import
bpy
import
os
import
os
import
re
def
find_index
(
objekti
):
def
find_index
(
objekti
):
luku
=
0
luku
=
0
for
tex
in
objekti
.
active_material
.
texture_slots
:
for
tex
in
objekti
.
active_material
.
texture_slots
:
if
(
not
(
hasattr
(
tex
,
'
texture
'
))):
if
(
not
(
hasattr
(
tex
,
'
texture
'
))):
...
@@ -28,10 +29,140 @@ def find_index(objekti):
...
@@ -28,10 +29,140 @@ def find_index(objekti):
luku
=
luku
+
1
luku
=
luku
+
1
return
luku
return
luku
def
gettex
(
mat_list
,
objekti
,
scene
,
export
):
def
readtexturefolder
(
objekti
,
is_new
):
#read textures from texture file
coat3D
=
bpy
.
context
.
scene
.
coat3D
obj_coat
=
objekti
.
coat3D
texcoat
=
{}
texcoat
[
'
color
'
]
=
[]
texcoat
[
'
metalness
'
]
=
[]
texcoat
[
'
rough
'
]
=
[]
texcoat
[
'
nmap
'
]
=
[]
texcoat
[
'
disp
'
]
=
[]
if
(
is_new
==
True
):
files_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
objekti
.
coat3D
.
applink_address
))
else
:
files_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
objekti
.
coat3D
.
applink_address
))
files_dir
=
files_dir
.
replace
(
'
3DC2Blender
'
+
os
.
sep
+
'
Objects
'
,
'
3DC2Blender
'
+
os
.
sep
+
'
Textures
'
)
files
=
os
.
listdir
(
files_dir
)
materiaali_muutos
=
objekti
.
active_material
.
name
uusin_mat
=
materiaali_muutos
.
replace
(
'
Material.
'
,
'
Material_
'
)
for
i
in
files
:
if
(
i
.
startswith
(
obj_coat
.
applink_name
+
'
_
'
+
uusin_mat
)):
koko_osoite
=
files_dir
+
os
.
sep
+
i
listed
=
re
.
split
(
r
'
[_.]
'
,
i
)
tex_name
=
listed
[
-
2
]
texcoat
[
tex_name
].
append
(
koko_osoite
)
createnodes
(
objekti
,
texcoat
)
def
checkmaterial
(
mat_list
,
objekti
):
#check how many materials object has
mat_list
=
[]
for
obj_mate
in
objekti
.
material_slots
:
if
(
obj_mate
.
material
.
use_nodes
==
False
):
obj_mate
.
material
.
use_nodes
=
True
def
createnodes
(
objekti
,
texcoat
):
#luo nodes palikat ja linkittaa tekstuurit niihin
bring_color
=
True
#naiden tarkoitus on tsekata onko tarvetta luoda uusi node vai riittaako paivitys
bring_metalness
=
True
bring_roughness
=
True
bring_normal
=
True
bring_disp
=
True
act_material
=
objekti
.
active_material
if
(
objekti
.
active_material
.
use_nodes
==
False
):
objekti
.
active_material
.
use_nodes
=
True
#ensimmaiseksi kaydaan kaikki image nodet lapi ja tarkistetaan onko nimi 3DC alkunen jos on niin reload
for
node
in
act_material
.
node_tree
.
nodes
:
if
(
node
.
type
==
'
TEX_IMAGE
'
):
if
(
node
.
name
==
'
3DC_color
'
):
bring_color
=
False
node
.
image
.
reload
()
elif
(
node
.
name
==
'
3DC_metalness
'
):
bring_metalness
=
False
node
.
image
.
reload
()
elif
(
node
.
name
==
'
3DC_roughness
'
):
bring_roughness
=
False
node
.
image
.
reload
()
elif
(
node
.
name
==
'
3DC_normal
'
):
bring_normal
=
False
node
.
image
.
reload
()
#seuraavaksi lahdemme rakentamaan node tree. Lahdetaan Material Outputista rakentaa
main_mat
=
act_material
.
node_tree
.
nodes
[
'
Material Output
'
]
if
(
main_mat
.
inputs
[
'
Surface
'
].
is_linked
==
True
):
glue_mat
=
main_mat
.
inputs
[
'
Surface
'
].
links
[
0
].
from_node
#Color
if
(
bring_color
==
True
and
glue_mat
.
inputs
.
find
(
'
Base Color
'
)
!=
-
1
and
texcoat
[
'
color
'
]
!=
[]):
node
=
act_material
.
node_tree
.
nodes
.
new
(
'
ShaderNodeTexImage
'
)
node
.
location
=
-
400
,
400
node
.
name
=
'
3DC_color
'
if
(
texcoat
[
'
color
'
]):
node
.
image
=
bpy
.
data
.
images
.
load
(
texcoat
[
'
color
'
][
0
])
input_color
=
glue_mat
.
inputs
.
find
(
'
Base Color
'
)
act_material
.
node_tree
.
links
.
new
(
node
.
outputs
[
0
],
glue_mat
.
inputs
[
input_color
])
#Metalness
if
(
bring_metalness
==
True
and
glue_mat
.
inputs
.
find
(
'
Metallic
'
)
!=
-
1
and
texcoat
[
'
metalness
'
]
!=
[]):
node
=
act_material
.
node_tree
.
nodes
.
new
(
'
ShaderNodeTexImage
'
)
node
.
location
=
-
600
,
200
node
.
name
=
'
3DC_metalness
'
if
(
texcoat
[
'
metalness
'
]):
node
.
image
=
bpy
.
data
.
images
.
load
(
texcoat
[
'
metalness
'
][
0
])
node
.
color_space
=
'
NONE
'
input_color
=
glue_mat
.
inputs
.
find
(
'
Metallic
'
)
act_material
.
node_tree
.
links
.
new
(
node
.
outputs
[
0
],
glue_mat
.
inputs
[
input_color
])
#Roughness
if
(
bring_roughness
==
True
and
glue_mat
.
inputs
.
find
(
'
Roughness
'
)
!=
-
1
and
texcoat
[
'
rough
'
]
!=
[]):
node
=
act_material
.
node_tree
.
nodes
.
new
(
'
ShaderNodeTexImage
'
)
node
.
location
=
-
550
,
0
node
.
name
=
'
3DC_roughness
'
if
(
texcoat
[
'
rough
'
]):
node
.
image
=
bpy
.
data
.
images
.
load
(
texcoat
[
'
rough
'
][
0
])
node
.
color_space
=
'
NONE
'
input_color
=
glue_mat
.
inputs
.
find
(
'
Roughness
'
)
act_material
.
node_tree
.
links
.
new
(
node
.
outputs
[
0
],
glue_mat
.
inputs
[
input_color
])
#Normal map
if
(
bring_normal
==
True
and
glue_mat
.
inputs
.
find
(
'
Normal
'
)
!=
-
1
and
texcoat
[
'
nmap
'
]
!=
[]):
node
=
act_material
.
node_tree
.
nodes
.
new
(
'
ShaderNodeTexImage
'
)
normal_node
=
act_material
.
node_tree
.
nodes
.
new
(
'
ShaderNodeNormalMap
'
)
node
.
location
=
-
600
,
-
270
normal_node
.
location
=
-
300
,
-
170
node
.
name
=
'
3DC_normal
'
if
(
texcoat
[
'
nmap
'
]):
node
.
image
=
bpy
.
data
.
images
.
load
(
texcoat
[
'
nmap
'
][
0
])
node
.
color_space
=
'
NONE
'
input_color
=
glue_mat
.
inputs
.
find
(
'
Normal
'
)
act_material
.
node_tree
.
links
.
new
(
node
.
outputs
[
0
],
normal_node
.
inputs
[
1
])
act_material
.
node_tree
.
links
.
new
(
normal_node
.
outputs
[
0
],
glue_mat
.
inputs
[
input_color
])
bpy
.
ops
.
object
.
editmode_toggle
()
#HACKKI joka saa tekstuurit nakymaan heti
bpy
.
ops
.
object
.
editmode_toggle
()
def
matlab
(
mat_list
,
objekti
,
scene
,
is_new
):
#checkmaterial(mat_list, objekti)
readtexturefolder
(
objekti
,
is_new
)
"""
print(
'
tassa tietoo
'
)
print(mat_list,objekti,scene,export)
coat3D = bpy.context.scene.coat3D
coat3D = bpy.context.scene.coat3D
coa = objekti.coat3D
coa = objekti.coat3D
print(coat3D,coa)
if(bpy.context.scene.render.engine ==
'
VRAY_RENDER
'
or bpy.context.scene.render.engine ==
'
VRAY_RENDER_PREVIEW
'
):
if(bpy.context.scene.render.engine ==
'
VRAY_RENDER
'
or bpy.context.scene.render.engine ==
'
VRAY_RENDER_PREVIEW
'
):
vray = True
vray = True
...
@@ -47,7 +178,7 @@ def gettex(mat_list, objekti, scene,export):
...
@@ -47,7 +178,7 @@ def gettex(mat_list, objekti, scene,export):
bring_spec = 1
bring_spec = 1
bring_normal = 1
bring_normal = 1
bring_disp = 1
bring_disp = 1
texcoat = {}
texcoat = {}
texcoat[
'
color
'
] = []
texcoat[
'
color
'
] = []
texcoat[
'
specular
'
] = []
texcoat[
'
specular
'
] = []
...
@@ -331,5 +462,5 @@ def gettex(mat_list, objekti, scene,export):
...
@@ -331,5 +462,5 @@ def gettex(mat_list, objekti, scene,export):
if(objekti.data.uv_textures.active):
if(objekti.data.uv_textures.active):
objekti.modifiers[
'
Displace
'
].texture_coords =
'
UV
'
objekti.modifiers[
'
Displace
'
].texture_coords =
'
UV
'
objekti.modifiers[
'
Displace
'
].uv_layer = objekti.data.uv_textures.active.name
objekti.modifiers[
'
Displace
'
].uv_layer = objekti.data.uv_textures.active.name
"""
return
(
'
FINISHED
'
)
return
(
'
FINISHED
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment