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
c87ee4d4
Commit
c87ee4d4
authored
6 years ago
by
Kalle-Samuli Riihikoski
Browse files
Options
Downloads
Patches
Plain Diff
updating the script to work the latest 2.8
parent
9ca218bf
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
io_coat3D/__init__.py
+839
-229
839 additions, 229 deletions
io_coat3D/__init__.py
io_coat3D/coat.py
+0
-626
0 additions, 626 deletions
io_coat3D/coat.py
io_coat3D/tex.py
+138
-4
138 additions, 4 deletions
io_coat3D/tex.py
with
977 additions
and
859 deletions
io_coat3D/__init__.py
+
839
−
229
View file @
c87ee4d4
...
...
@@ -20,7 +20,7 @@ bl_info = {
"
name
"
:
"
3D-Coat Applink
"
,
"
author
"
:
"
Kalle-Samuli Riihikoski (haikalle)
"
,
"
version
"
:
(
3
,
5
,
22
),
"
blender
"
:
(
2
,
59
,
0
),
"
blender
"
:
(
2
,
80
,
0
),
"
location
"
:
"
Scene > 3D-Coat Applink
"
,
"
description
"
:
"
Transfer data between 3D-Coat/Blender
"
,
"
warning
"
:
""
,
...
...
@@ -35,9 +35,14 @@ if "bpy" in locals():
importlib
.
reload
(
coat
)
importlib
.
reload
(
tex
)
else
:
from
.
import
coat
from
.
import
tex
from
io_coat3D
import
tex
import
os
import
ntpath
import
re
import
time
import
bpy
from
bpy.types
import
PropertyGroup
from
bpy.props
import
(
...
...
@@ -49,244 +54,849 @@ from bpy.props import (
)
bpy
.
coat3D
=
dict
()
bpy
.
coat3D
[
'
active_coat
'
]
=
''
bpy
.
coat3D
[
'
status
'
]
=
0
def
set_exchange_folder
():
platform
=
os
.
sys
.
platform
coat3D
=
bpy
.
context
.
scene
.
coat3D
Blender_export
=
""
if
(
platform
==
'
win32
'
):
exchange
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
Documents
'
+
os
.
sep
+
'
3D-CoatV4
'
+
os
.
sep
+
'
Exchange
'
if
not
(
os
.
path
.
isdir
(
exchange
)):
exchange
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
Documents
'
+
os
.
sep
+
'
3D-CoatV3
'
+
os
.
sep
+
'
Exchange
'
else
:
exchange
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
3D-CoatV4
'
+
os
.
sep
+
'
Exchange
'
if
not
(
os
.
path
.
isdir
(
exchange
)):
exchange
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
3D-CoatV3
'
+
os
.
sep
+
'
Exchange
'
if
(
not
(
os
.
path
.
isdir
(
exchange
))):
exchange
=
coat3D
.
exchangedir
if
(
os
.
path
.
isdir
(
exchange
)):
bpy
.
coat3D
[
'
status
'
]
=
1
if
(
platform
==
'
win32
'
):
exchange_path
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
Documents
'
+
os
.
sep
+
'
3DC2Blender
'
+
os
.
sep
+
'
Exchange_folder.txt
'
applink_folder
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
Documents
'
+
os
.
sep
+
'
3DC2Blender
'
if
(
not
(
os
.
path
.
isdir
(
applink_folder
))):
os
.
makedirs
(
applink_folder
)
else
:
exchange_path
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
Documents
'
+
os
.
sep
+
'
3DC2Blender
'
+
os
.
sep
+
'
Exchange_folder.txt
'
applink_folder
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
Documents
'
+
os
.
sep
+
'
3DC2Blender
'
if
(
not
(
os
.
path
.
isdir
(
applink_folder
))):
os
.
makedirs
(
applink_folder
)
file
=
open
(
exchange_path
,
"
w
"
)
file
.
write
(
"
%s
"
%
(
coat3D
.
exchangedir
))
file
.
close
()
else
:
if
(
platform
==
'
win32
'
):
exchange_path
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
Documents
'
+
os
.
sep
+
'
3DC2Blender
'
+
os
.
sep
+
'
Exchange_folder.txt
'
else
:
exchange_path
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
3DC2Blender
'
+
os
.
sep
+
'
Exchange_folder.txt
'
if
(
os
.
path
.
isfile
(
exchange_path
)):
ex_path
=
''
ex_pathh
=
open
(
exchange_path
)
for
line
in
ex_pathh
:
ex_path
=
line
break
ex_pathh
.
close
()
if
(
os
.
path
.
isdir
(
ex_path
)
and
ex_path
.
rfind
(
'
Exchange
'
)
>=
0
):
exchange
=
ex_path
bpy
.
coat3D
[
'
status
'
]
=
1
else
:
bpy
.
coat3D
[
'
status
'
]
=
0
else
:
bpy
.
coat3D
[
'
status
'
]
=
0
if
(
bpy
.
coat3D
[
'
status
'
]
==
1
):
Blender_folder
=
(
"
%s%sBlender
"
%
(
exchange
,
os
.
sep
))
Blender_export
=
Blender_folder
path3b_now
=
exchange
path3b_now
+=
(
'
last_saved_3b_file.txt
'
)
Blender_export
+=
(
'
%sexport.txt
'
%
(
os
.
sep
))
if
(
not
(
os
.
path
.
isdir
(
Blender_folder
))):
os
.
makedirs
(
Blender_folder
)
Blender_folder
=
os
.
path
.
join
(
Blender_folder
,
"
run.txt
"
)
file
=
open
(
Blender_folder
,
"
w
"
)
file
.
close
()
return
exchange
def
set_working_folders
():
platform
=
os
.
sys
.
platform
coat3D
=
bpy
.
context
.
scene
.
coat3D
if
(
platform
==
'
win32
'
):
if
(
bpy
.
data
.
filepath
==
''
):
folder_objects
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
Documents
'
+
os
.
sep
+
'
3DC2Blender
'
+
os
.
sep
+
'
Objects
'
folder_textures
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
Documents
'
+
os
.
sep
+
'
3DC2Blender
'
+
os
.
sep
+
'
Textures
'
+
os
.
sep
else
:
folder_objects
=
os
.
path
.
dirname
(
bpy
.
data
.
filepath
)
+
os
.
sep
+
'
3DCApplink
'
+
os
.
sep
+
'
Objects
'
folder_textures
=
os
.
path
.
dirname
(
bpy
.
data
.
filepath
)
+
os
.
sep
+
'
3DCApplink
'
+
os
.
sep
+
'
Textures
'
+
os
.
sep
print
(
'
mitas sanoo
'
,
folder_objects
)
if
(
not
(
os
.
path
.
isdir
(
folder_objects
))):
os
.
makedirs
(
folder_objects
)
if
(
not
(
os
.
path
.
isdir
(
folder_textures
))):
os
.
makedirs
(
folder_textures
)
else
:
folder_objects
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
3DC2Blender
'
+
os
.
sep
+
'
Objects
'
folder_textures
=
os
.
path
.
expanduser
(
"
~
"
)
+
os
.
sep
+
'
3DC2Blender
'
+
os
.
sep
+
'
Textures
'
+
os
.
sep
if
(
not
(
os
.
path
.
isdir
(
folder_objects
))):
os
.
makedirs
(
folder_objects
)
if
(
not
(
os
.
path
.
isdir
(
folder_textures
))):
os
.
makedirs
(
folder_textures
)
return
folder_objects
,
folder_textures
class
ObjectButtonsPanel
():
bl_space_type
=
'
PROPERTIES
'
bl_region_type
=
'
WINDOW
'
bl_context
=
"
object
"
class
SCENE_PT_Main
(
ObjectButtonsPanel
,
bpy
.
types
.
Panel
):
bl_label
=
"
3D-Coat Applink
"
bl_space_type
=
"
PROPERTIES
"
bl_region_type
=
"
WINDOW
"
bl_context
=
"
scene
"
def
draw
(
self
,
context
):
layout
=
self
.
layout
scene
=
context
.
scene
me
=
context
.
scene
.
objects
mat_list
=
[]
import_no
=
0
coat
=
bpy
.
coat3D
coat3D
=
bpy
.
context
.
scene
.
coat3D
if
(
bpy
.
context
.
active_object
):
coa
=
bpy
.
context
.
active_object
.
coat3D
if
(
bpy
.
coat3D
[
'
status
'
]
==
0
and
not
(
os
.
path
.
isdir
(
coat3D
.
exchangedir
))):
bpy
.
coat3D
[
'
active_coat
'
]
=
set_exchange_folder
()
row
=
layout
.
row
()
row
.
label
(
text
=
"
Applink didn
'
t find your 3d-Coat/Excahnge folder.
"
)
row
=
layout
.
row
()
row
.
label
(
"
Please select it before using Applink.
"
)
row
=
layout
.
row
()
row
.
prop
(
coat3D
,
"
exchangedir
"
,
text
=
""
)
else
:
#Here you add your GUI
row
=
layout
.
row
()
row
.
prop
(
coat3D
,
"
type
"
,
text
=
""
)
row
=
layout
.
row
()
colL
=
row
.
column
()
colR
=
row
.
column
()
colR
.
operator
(
"
export_applink.pilgway_3d_coat
"
,
text
=
"
Transfer
"
)
colL
.
operator
(
"
import_applink.pilgway_3d_coat
"
,
text
=
"
Update
"
)
class
SCENE_OT_export
(
bpy
.
types
.
Operator
):
bl_idname
=
"
export_applink.pilgway_3d_coat
"
bl_label
=
"
Export your custom property
"
bl_description
=
"
Export your custom property
"
bl_options
=
{
'
UNDO
'
}
def
invoke
(
self
,
context
,
event
):
checkname
=
''
coat3D
=
bpy
.
context
.
scene
.
coat3D
scene
=
context
.
scene
activeobj
=
bpy
.
context
.
active_object
.
name
coa
=
bpy
.
context
.
active_object
.
coat3D
coat3D
.
exchangedir
=
set_exchange_folder
()
export_ok
=
False
folder_objects
,
folder_textures
=
set_working_folders
()
if
(
coat3D
.
exchange_found
==
False
):
return
{
'
FINISHED
'
}
if
(
bpy
.
context
.
selected_objects
==
[]):
return
{
'
FINISHED
'
}
else
:
for
objec
in
bpy
.
context
.
selected_objects
:
if
objec
.
type
==
'
MESH
'
:
export_ok
=
True
if
(
export_ok
==
False
):
return
{
'
FINISHED
'
}
importfile
=
coat3D
.
exchangedir
texturefile
=
coat3D
.
exchangedir
importfile
+=
(
'
%simport.txt
'
%
(
os
.
sep
))
texturefile
+=
(
'
%stextures.txt
'
%
(
os
.
sep
))
looking
=
True
object_index
=
0
if
(
coa
.
applink_address
and
os
.
path
.
isfile
(
coa
.
applink_address
)):
checkname
=
coa
.
applink_address
else
:
while
(
looking
==
True
):
checkname
=
folder_objects
+
os
.
sep
+
activeobj
checkname
=
(
"
%s%.2d.dae
"
%
(
checkname
,
object_index
))
if
(
os
.
path
.
isfile
(
checkname
)):
object_index
+=
1
else
:
looking
=
False
coa
.
applink_name
=
(
"
%s%.2d
"
%
(
activeobj
,
object_index
))
coa
.
applink_address
=
checkname
for
objekti
in
bpy
.
context
.
selected_objects
:
if
(
objekti
.
material_slots
.
keys
()
==
[]):
bpy
.
ops
.
material
.
new
()
objekti
.
data
.
materials
.
append
(
bpy
.
data
.
materials
[
-
1
])
bpy
.
ops
.
object
.
origin_set
(
type
=
'
ORIGIN_GEOMETRY
'
)
#bpy.ops.object.transforms_to_deltas(mode='ROT')
bpy
.
ops
.
wm
.
collada_export
(
filepath
=
coa
.
applink_address
,
selected
=
True
,
apply_modifiers
=
False
,
triangulate
=
False
)
file
=
open
(
importfile
,
"
w
"
)
file
.
write
(
"
%s
"
%
(
checkname
))
file
.
write
(
"
\n
%s
"
%
(
checkname
))
file
.
write
(
"
\n
[%s]
"
%
(
coat3D
.
type
))
file
.
write
(
"
\n
[TexOutput:%s]
"
%
(
folder_textures
))
file
.
close
()
group_index
=
-
1.0
for
objekti
in
bpy
.
context
.
selected_objects
:
nimi
=
''
for
koko
in
bpy
.
context
.
selected_objects
:
nimi
+=
koko
.
name
+
'
:::
'
objekti
.
coat3D
.
applink_group
=
nimi
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
'
}
class
SCENE_OT_import
(
bpy
.
types
.
Operator
):
bl_idname
=
"
import_applink.pilgway_3d_coat
"
bl_label
=
"
import your custom property
"
bl_description
=
"
import your custom property
"
bl_options
=
{
'
UNDO
'
}
def
invoke
(
self
,
context
,
event
):
coat3D
=
bpy
.
context
.
scene
.
coat3D
coat
=
bpy
.
coat3D
coat3D
.
exchangedir
=
set_exchange_folder
()
folder_objects
,
folder_textures
=
set_working_folders
()
Blender_folder
=
(
"
%s%sBlender
"
%
(
coat3D
.
exchangedir
,
os
.
sep
))
Blender_export
=
Blender_folder
path3b_now
=
coat3D
.
exchangedir
path3b_now
+=
(
'
last_saved_3b_file.txt
'
)
Blender_export
+=
(
'
%sexport.txt
'
%
(
os
.
sep
))
new_applink_address
=
'
False
'
new_object
=
False
if
(
os
.
path
.
isfile
(
Blender_export
)):
obj_pathh
=
open
(
Blender_export
)
new_object
=
True
for
line
in
obj_pathh
:
new_applink_address
=
line
break
obj_pathh
.
close
()
for
scene_objects
in
bpy
.
context
.
scene
.
objects
:
if
(
scene_objects
.
type
==
'
MESH
'
):
if
(
scene_objects
.
coat3D
.
applink_address
==
new_applink_address
):
new_object
=
False
if
(
new_object
==
False
):
#Blender -> 3DC -> Blender workflow
for
objekti
in
bpy
.
context
.
scene
.
objects
:
obj_coat
=
objekti
.
coat3D
if
(
obj_coat
.
applink_address
!=
''
and
os
.
path
.
isfile
(
obj_coat
.
applink_address
)
and
obj_coat
.
applink_skip
==
'
False
'
):
obj_coat
.
applink_skip
=
'
True
'
objekti
.
select_set
(
'
SELECT
'
)
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
)
obj_names
=
objekti
.
coat3D
.
applink_group
print
(
'
obj_names:
'
,
obj_names
)
obj_list
=
obj_names
.
split
(
'
:::
'
)
print
(
'
obj_list:
'
,
obj_list
)
applinks
=
[]
mat_list
=
[]
for
app_obj
in
obj_list
:
print
(
'
sisalla app_obj
'
)
pnimi
=
app_obj
.
lstrip
()
print
(
'
pnimi
'
,
pnimi
)
listed
=
re
.
split
(
r
'
[:::]
'
,
pnimi
)
print
(
'
listed:
'
,
listed
)
for
tobj
in
bpy
.
context
.
scene
.
collection
.
all_objects
:
if
(
tobj
.
name
==
app_obj
):
print
(
'
tobj:
'
,
tobj
)
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
=
[]
print
(
'
applinkki lista:
'
,
applinks
)
for
obe
in
applinks
:
print
(
'
kuka etsii:
'
,
obe
)
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
if
(
obe
.
coat3D
.
applink_export
==
False
):
find_name
=
obe
.
name
+
'
-mesh
'
find_name
=
find_name
.
replace
(
'
.
'
,
'
_
'
)
else
:
find_name
=
obe
.
name
+
'
.001
'
for
allobjekti
in
bpy
.
context
.
scene
.
collection
.
all_objects
:
print
(
'
allobject
'
,
allobjekti
)
print
(
'
find_name
'
,
find_name
)
counter
=
0
if
(
allobjekti
.
name
==
find_name
):
print
(
'
löyty:
'
,
allobjekti
)
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
):
print
(
'
ensimmainen
'
,
obe
)
obe
.
scale
=
(
1
,
1
,
1
)
obe
.
rotation_euler
=
(
0
,
0
,
0
)
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
if
(
use_smooth
):
for
data_mesh
in
obe
.
data
.
polygons
:
data_mesh
.
use_smooth
=
True
bpy
.
ops
.
object
.
select_all
(
action
=
'
DESELECT
'
)
print
(
'
tuholista
'
,
del_list
)
for
deleting
in
del_list
:
print
(
'
tuhotaan:
'
,
deleting
)
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
(
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
'
for
material
in
bpy
.
data
.
materials
:
if
material
.
use_nodes
==
True
:
for
node
in
material
.
node_tree
.
nodes
:
if
(
node
.
name
).
startswith
(
'
3DC
'
):
node
.
location
=
node
.
location
else
:
# 3DC -> Blender workflow
coat3D
=
bpy
.
context
.
scene
.
coat3D
scene
=
context
.
scene
Blender_folder
=
(
"
%s%sBlender
"
%
(
coat3D
.
exchangedir
,
os
.
sep
))
Blender_export
=
Blender_folder
path3b_now
=
coat3D
.
exchangedir
path3b_now
+=
(
'
last_saved_3b_file.txt
'
)
Blender_export
+=
(
'
%sexport.txt
'
%
(
os
.
sep
))
mat_list
=
[]
bpy
.
ops
.
wm
.
collada_import
(
filepath
=
new_applink_address
)
new_obj
=
bpy
.
context
.
collection
.
objects
[
-
1
]
new_obj
.
coat3D
.
applink_address
=
new_applink_address
print
(
'
addressi on:
'
,
new_applink_address
)
splittext
=
ntpath
.
basename
(
new_applink_address
)
new_obj
.
coat3D
.
applink_name
=
splittext
.
split
(
'
.
'
)[
0
]
new_obj
.
coat3D
.
applink_group
=
new_obj
.
name
new_obj
.
coat3D
.
applink_export
=
True
print
(
'
nimi on:
'
,
new_obj
.
coat3D
.
applink_name
)
os
.
remove
(
Blender_export
)
new_obj
.
select_set
(
'
SELECT
'
)
bpy
.
ops
.
object
.
origin_set
(
type
=
'
GEOMETRY_ORIGIN
'
)
#bpy.ops.object.transforms_to_deltas(mode='ROT')
new_obj
.
rotation_euler
=
(
0
,
0
,
0
)
mat_list
.
append
(
new_obj
.
material_slots
[
0
].
material
)
is_new
=
True
tex
.
matlab
(
mat_list
,
new_obj
,
bpy
.
context
.
scene
,
is_new
)
for
material
in
bpy
.
data
.
materials
:
if
material
.
use_nodes
==
True
:
for
node
in
material
.
node_tree
.
nodes
:
if
(
node
.
name
).
startswith
(
'
3DC
'
):
node
.
location
=
node
.
location
return
{
'
FINISHED
'
}
from
bpy
import
*
from
mathutils
import
Vector
,
Matrix
# 3D-Coat Dynamic Menu
class
VIEW3D_MT_Coat_Dynamic_Menu
(
bpy
.
types
.
Menu
):
bl_label
=
"
3D-Coat Applink Menu
"
def
draw
(
self
,
context
):
layout
=
self
.
layout
settings
=
context
.
tool_settings
layout
.
operator_context
=
'
INVOKE_REGION_WIN
'
coat3D
=
bpy
.
context
.
scene
.
coat3D
Blender_folder
=
(
"
%s%sBlender
"
%
(
coat3D
.
exchangedir
,
os
.
sep
))
Blender_export
=
Blender_folder
Blender_export
+=
(
'
%sexport.txt
'
%
(
os
.
sep
))
ob
=
context
if
ob
.
mode
==
'
OBJECT
'
:
if
(
bpy
.
context
.
selected_objects
):
for
ind_obj
in
bpy
.
context
.
selected_objects
:
if
(
ind_obj
.
type
==
'
MESH
'
):
layout
.
active
=
True
break
layout
.
active
=
False
if
(
layout
.
active
==
True
):
layout
.
operator
(
"
import_applink.pilgway_3d_coat
"
,
text
=
"
Import
"
)
layout
.
separator
()
layout
.
operator
(
"
export_applink.pilgway_3d_coat
"
,
text
=
"
Export
"
)
layout
.
separator
()
layout
.
menu
(
"
VIEW3D_MT_ImportMenu
"
)
layout
.
separator
()
layout
.
menu
(
"
VIEW3D_MT_ExportMenu
"
)
layout
.
separator
()
layout
.
menu
(
"
VIEW3D_MT_ExtraMenu
"
)
layout
.
separator
()
if
(
len
(
bpy
.
context
.
selected_objects
)
==
1
):
if
(
os
.
path
.
isfile
(
bpy
.
context
.
selected_objects
[
0
].
coat3D
.
path3b
)):
layout
.
operator
(
"
import_applink.pilgway_3d_coat_3b
"
,
text
=
"
Load 3b
"
)
layout
.
separator
()
if
(
os
.
path
.
isfile
(
Blender_export
)):
layout
.
operator
(
"
import3b_applink.pilgway_3d_coat
"
,
text
=
"
Bring from 3D-Coat
"
)
layout
.
separator
()
else
:
if
(
os
.
path
.
isfile
(
Blender_export
)):
layout
.
active
=
True
layout
.
operator
(
"
import3b_applink.pilgway_3d_coat
"
,
text
=
"
Bring from 3D-Coat
"
)
layout
.
separator
()
else
:
if
(
os
.
path
.
isfile
(
Blender_export
)):
layout
.
operator
(
"
import3b_applink.pilgway_3d_coat
"
,
text
=
"
Bring from 3D-Coat
"
)
layout
.
separator
()
class
VIEW3D_MT_ImportMenu
(
bpy
.
types
.
Menu
):
bl_label
=
"
Import Settings
"
def
draw
(
self
,
context
):
layout
=
self
.
layout
coat3D
=
bpy
.
context
.
scene
.
coat3D
settings
=
context
.
tool_settings
layout
.
operator_context
=
'
INVOKE_REGION_WIN
'
layout
.
prop
(
coat3D
,
"
importmesh
"
)
layout
.
prop
(
coat3D
,
"
importmod
"
)
layout
.
prop
(
coat3D
,
"
smooth_on
"
)
layout
.
prop
(
coat3D
,
"
importtextures
"
)
class
VIEW3D_MT_ExportMenu
(
bpy
.
types
.
Menu
):
bl_label
=
"
Export Settings
"
def
draw
(
self
,
context
):
layout
=
self
.
layout
coat3D
=
bpy
.
context
.
scene
.
coat3D
settings
=
context
.
tool_settings
layout
.
operator_context
=
'
INVOKE_REGION_WIN
'
layout
.
prop
(
coat3D
,
"
exportover
"
)
if
(
coat3D
.
exportover
):
layout
.
prop
(
coat3D
,
"
exportmod
"
)
class
VIEW3D_MT_ExtraMenu
(
bpy
.
types
.
Menu
):
bl_label
=
"
Extra
"
def
draw
(
self
,
context
):
layout
=
self
.
layout
coat3D
=
bpy
.
context
.
scene
.
coat3D
settings
=
context
.
tool_settings
layout
.
operator_context
=
'
INVOKE_REGION_WIN
'
layout
.
operator
(
"
import_applink.pilgway_3d_deltex
"
,
text
=
"
Delete all Textures
"
)
layout
.
separator
()
class
ObjectCoat3D
(
PropertyGroup
):
objpath
:
StringProperty
(
name
=
"
Object_Path
"
)
applink_address
:
StringProperty
(
name
=
"
Object_Applink_address
"
)
applink_name
:
StringProperty
(
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
)
applink_export
:
BoolProperty
(
name
=
"
FirstTime
"
,
description
=
"
Object is from 3d-ocat
"
,
default
=
False
)
coatpath
:
StringProperty
(
name
=
"
Coat_Path
"
)
objectdir
:
StringProperty
(
name
=
"
ObjectPath
"
,
subtype
=
"
FILE_PATH
"
)
objecttime
:
StringProperty
(
name
=
"
ObjectTime
"
,
subtype
=
"
FILE_PATH
"
)
texturefolder
:
StringProperty
(
name
=
"
Texture folder:
"
,
subtype
=
"
DIR_PATH
"
)
path3b
:
StringProperty
(
name
=
"
3B Path
"
,
subtype
=
"
FILE_PATH
"
)
export_on
:
BoolProperty
(
name
=
"
Export_On
"
,
description
=
"
Add Modifiers and export
"
,
default
=
False
)
dime
:
FloatVectorProperty
(
name
=
"
dime
"
,
description
=
"
Dimension
"
)
loc
:
FloatVectorProperty
(
name
=
"
Location
"
,
description
=
"
Location
"
)
rot
:
FloatVectorProperty
(
name
=
"
Rotation
"
,
description
=
"
Rotation
"
,
subtype
=
'
EULER
'
)
sca
:
FloatVectorProperty
(
name
=
"
Scale
"
,
description
=
"
Scale
"
)
class
SceneCoat3D
(
PropertyGroup
):
defaultfolder
:
StringProperty
(
name
=
"
FilePath
"
,
subtype
=
"
DIR_PATH
"
,
)
cursor_loc
:
FloatVectorProperty
(
name
=
"
Cursor_loc
"
,
description
=
"
location
"
)
exchangedir
:
StringProperty
(
name
=
"
FilePath
"
,
subtype
=
"
DIR_PATH
"
)
exchangefolder
:
StringProperty
(
name
=
"
FilePath
"
,
subtype
=
"
DIR_PATH
"
)
wasactive
:
StringProperty
(
name
=
"
Pass active object
"
,
)
import_box
:
BoolProperty
(
name
=
"
Import window
"
,
description
=
"
Allows to skip import dialog
"
,
default
=
True
)
exchange_found
:
BoolProperty
(
name
=
"
Exchange Found
"
,
description
=
"
Alert if Exchange folder is not found
"
,
default
=
True
)
export_box
:
BoolProperty
(
name
=
"
Export window
"
,
description
=
"
Allows to skip export dialog
"
,
default
=
True
)
export_color
:
BoolProperty
(
name
=
"
Export color
"
,
description
=
"
Export color texture
"
,
default
=
True
)
export_spec
:
BoolProperty
(
name
=
"
Export specular
"
,
description
=
"
Export specular texture
"
,
default
=
True
)
export_normal
:
BoolProperty
(
name
=
"
Export Normal
"
,
description
=
"
Export normal texture
"
,
default
=
True
)
export_disp
:
BoolProperty
(
name
=
"
Export Displacement
"
,
description
=
"
Export displacement texture
"
,
default
=
True
)
export_position
:
BoolProperty
(
name
=
"
Export Source Position
"
,
description
=
"
Export source position
"
,
default
=
True
)
export_zero_layer
:
BoolProperty
(
name
=
"
Export from Layer 0
"
,
description
=
"
Export mesh from Layer 0
"
,
default
=
True
)
export_coarse
:
BoolProperty
(
name
=
"
Export Coarse
"
,
description
=
"
Export Coarse
"
,
default
=
True
)
exportfile
:
BoolProperty
(
name
=
"
No Import File
"
,
description
=
"
Add Modifiers and export
"
,
default
=
False
)
importmod
:
BoolProperty
(
name
=
"
Remove Modifiers
"
,
description
=
"
Import and add modifiers
"
,
default
=
False
)
exportmod
:
BoolProperty
(
name
=
"
Modifiers
"
,
description
=
"
Export modifiers
"
,
default
=
False
)
export_pos
:
BoolProperty
(
name
=
"
Remember Position
"
,
description
=
"
Remember position
"
,
default
=
True
)
importtextures
:
BoolProperty
(
name
=
"
Bring Textures
"
,
description
=
"
Import Textures
"
,
default
=
True
)
importlevel
:
BoolProperty
(
name
=
"
Multires. Level
"
,
description
=
"
Bring Specific Multires Level
"
,
default
=
False
)
exportover
:
BoolProperty
(
name
=
"
Export Obj
"
,
description
=
"
Import Textures
"
,
default
=
False
)
importmesh
:
BoolProperty
(
name
=
"
Mesh
"
,
description
=
"
Import Mesh
"
,
default
=
True
)
# copy location
loca
:
FloatVectorProperty
(
name
=
"
location
"
,
description
=
"
Location
"
,
subtype
=
"
XYZ
"
,
default
=
(
0.0
,
0.0
,
0.0
)
)
rota
:
FloatVectorProperty
(
name
=
"
location
"
,
description
=
"
Location
"
,
subtype
=
"
EULER
"
,
default
=
(
0.0
,
0.0
,
0.0
)
)
scal
:
FloatVectorProperty
(
name
=
"
location
"
,
description
=
"
Location
"
,
subtype
=
"
XYZ
"
,
default
=
(
0.0
,
0.0
,
0.0
)
)
dime
:
FloatVectorProperty
(
name
=
"
dimension
"
,
description
=
"
Dimension
"
,
subtype
=
"
XYZ
"
,
default
=
(
0.0
,
0.0
,
0.0
)
)
type
:
EnumProperty
(
name
=
"
Export Type
"
,
description
=
"
Different Export Types
"
,
items
=
((
"
ppp
"
,
"
Per-Pixel Painting
"
,
""
),
(
"
mv
"
,
"
Microvertex Painting
"
,
""
),
(
"
ptex
"
,
"
Ptex Painting
"
,
""
),
(
"
uv
"
,
"
UV-Mapping
"
,
""
),
(
"
ref
"
,
"
Reference Mesh
"
,
""
),
(
"
retopo
"
,
"
Retopo mesh as new layer
"
,
""
),
(
"
vox
"
,
"
Mesh As Voxel Object
"
,
""
),
(
"
alpha
"
,
"
Mesh As New Pen Alpha
"
,
""
),
(
"
prim
"
,
"
Mesh As Voxel Primitive
"
,
""
),
(
"
curv
"
,
"
Mesh As a Curve Profile
"
,
""
),
(
"
autopo
"
,
"
Mesh For Auto-retopology
"
,
""
),
),
default
=
"
ppp
"
)
classes
=
(
#ObjectButtonsPanel,
SCENE_PT_Main
,
SCENE_OT_export
,
SCENE_OT_import
,
VIEW3D_MT_Coat_Dynamic_Menu
,
VIEW3D_MT_ImportMenu
,
VIEW3D_MT_ExportMenu
,
VIEW3D_MT_ExtraMenu
,
ObjectCoat3D
,
SceneCoat3D
,
)
def
register
():
bpy
.
coat3D
=
dict
()
bpy
.
coat3D
[
'
active_coat
'
]
=
''
bpy
.
coat3D
[
'
status
'
]
=
0
bpy
.
coat3D
[
'
kuva
'
]
=
1
class
ObjectCoat3D
(
PropertyGroup
):
objpath
=
StringProperty
(
name
=
"
Object_Path
"
)
applink_name
=
StringProperty
(
name
=
"
Object_Applink_name
"
)
coatpath
=
StringProperty
(
name
=
"
Coat_Path
"
)
objectdir
=
StringProperty
(
name
=
"
ObjectPath
"
,
subtype
=
"
FILE_PATH
"
)
objecttime
=
StringProperty
(
name
=
"
ObjectTime
"
,
subtype
=
"
FILE_PATH
"
)
texturefolder
=
StringProperty
(
name
=
"
Texture folder:
"
,
subtype
=
"
DIR_PATH
"
)
path3b
=
StringProperty
(
name
=
"
3B Path
"
,
subtype
=
"
FILE_PATH
"
)
export_on
=
BoolProperty
(
name
=
"
Export_On
"
,
description
=
"
Add Modifiers and export
"
,
default
=
False
)
dime
=
FloatVectorProperty
(
name
=
"
dime
"
,
description
=
"
Dimension
"
)
loc
=
FloatVectorProperty
(
name
=
"
Location
"
,
description
=
"
Location
"
)
rot
=
FloatVectorProperty
(
name
=
"
Rotation
"
,
description
=
"
Rotation
"
,
subtype
=
'
EULER
'
)
sca
=
FloatVectorProperty
(
name
=
"
Scale
"
,
description
=
"
Scale
"
)
class
SceneCoat3D
(
PropertyGroup
):
defaultfolder
=
StringProperty
(
name
=
"
FilePath
"
,
subtype
=
"
DIR_PATH
"
,
)
cursor_loc
=
FloatVectorProperty
(
name
=
"
Cursor_loc
"
,
description
=
"
location
"
)
exchangedir
=
StringProperty
(
name
=
"
FilePath
"
,
subtype
=
"
DIR_PATH
"
)
exchangefolder
=
StringProperty
(
name
=
"
FilePath
"
,
subtype
=
"
DIR_PATH
"
)
wasactive
=
StringProperty
(
name
=
"
Pass active object
"
,
)
import_box
=
BoolProperty
(
name
=
"
Import window
"
,
description
=
"
Allows to skip import dialog
"
,
default
=
True
)
exchange_found
=
BoolProperty
(
name
=
"
Exchange Found
"
,
description
=
"
Alert if Exchange folder is not found
"
,
default
=
True
)
export_box
=
BoolProperty
(
name
=
"
Export window
"
,
description
=
"
Allows to skip export dialog
"
,
default
=
True
)
export_color
=
BoolProperty
(
name
=
"
Export color
"
,
description
=
"
Export color texture
"
,
default
=
True
)
export_spec
=
BoolProperty
(
name
=
"
Export specular
"
,
description
=
"
Export specular texture
"
,
default
=
True
)
export_normal
=
BoolProperty
(
name
=
"
Export Normal
"
,
description
=
"
Export normal texture
"
,
default
=
True
)
export_disp
=
BoolProperty
(
name
=
"
Export Displacement
"
,
description
=
"
Export displacement texture
"
,
default
=
True
)
export_position
=
BoolProperty
(
name
=
"
Export Source Position
"
,
description
=
"
Export source position
"
,
default
=
True
)
export_zero_layer
=
BoolProperty
(
name
=
"
Export from Layer 0
"
,
description
=
"
Export mesh from Layer 0
"
,
default
=
True
)
export_coarse
=
BoolProperty
(
name
=
"
Export Coarse
"
,
description
=
"
Export Coarse
"
,
default
=
True
)
exportfile
=
BoolProperty
(
name
=
"
No Import File
"
,
description
=
"
Add Modifiers and export
"
,
default
=
False
)
importmod
=
BoolProperty
(
name
=
"
Remove Modifiers
"
,
description
=
"
Import and add modifiers
"
,
default
=
False
)
exportmod
=
BoolProperty
(
name
=
"
Modifiers
"
,
description
=
"
Export modifiers
"
,
default
=
False
)
export_pos
=
BoolProperty
(
name
=
"
Remember Position
"
,
description
=
"
Remember position
"
,
default
=
True
)
importtextures
=
BoolProperty
(
name
=
"
Bring Textures
"
,
description
=
"
Import Textures
"
,
default
=
True
)
importlevel
=
BoolProperty
(
name
=
"
Multires. Level
"
,
description
=
"
Bring Specific Multires Level
"
,
default
=
False
)
exportover
=
BoolProperty
(
name
=
"
Export Obj
"
,
description
=
"
Import Textures
"
,
default
=
False
)
importmesh
=
BoolProperty
(
name
=
"
Mesh
"
,
description
=
"
Import Mesh
"
,
default
=
True
)
# copy location
cursor
=
FloatVectorProperty
(
name
=
"
Cursor
"
,
description
=
"
Location
"
,
subtype
=
"
XYZ
"
,
default
=
(
0.0
,
0.0
,
0.0
)
)
loca
=
FloatVectorProperty
(
name
=
"
location
"
,
description
=
"
Location
"
,
subtype
=
"
XYZ
"
,
default
=
(
0.0
,
0.0
,
0.0
)
)
rota
=
FloatVectorProperty
(
name
=
"
location
"
,
description
=
"
Location
"
,
subtype
=
"
EULER
"
,
default
=
(
0.0
,
0.0
,
0.0
)
)
scal
=
FloatVectorProperty
(
name
=
"
location
"
,
description
=
"
Location
"
,
subtype
=
"
XYZ
"
,
default
=
(
0.0
,
0.0
,
0.0
)
)
dime
=
FloatVectorProperty
(
name
=
"
dimension
"
,
description
=
"
Dimension
"
,
subtype
=
"
XYZ
"
,
default
=
(
0.0
,
0.0
,
0.0
)
)
type
=
EnumProperty
(
name
=
"
Export Type
"
,
description
=
"
Different Export Types
"
,
items
=
((
"
ppp
"
,
"
Per-Pixel Painting
"
,
""
),
(
"
mv
"
,
"
Microvertex Painting
"
,
""
),
(
"
ptex
"
,
"
Ptex Painting
"
,
""
),
(
"
uv
"
,
"
UV-Mapping
"
,
""
),
(
"
ref
"
,
"
Reference Mesh
"
,
""
),
(
"
retopo
"
,
"
Retopo mesh as new layer
"
,
""
),
(
"
vox
"
,
"
Mesh As Voxel Object
"
,
""
),
(
"
alpha
"
,
"
Mesh As New Pen Alpha
"
,
""
),
(
"
prim
"
,
"
Mesh As Voxel Primitive
"
,
""
),
(
"
curv
"
,
"
Mesh As a Curve Profile
"
,
""
),
(
"
autopo
"
,
"
Mesh For Auto-retopology
"
,
""
),
),
default
=
"
ppp
"
)
bpy
.
utils
.
register_module
(
__name__
)
bpy
.
types
.
Object
.
coat3D
=
PointerProperty
(
name
=
"
Applink Variables
"
,
type
=
ObjectCoat3D
,
description
=
"
Applink variables
"
)
bpy
.
types
.
Scene
.
coat3D
=
PointerProperty
(
name
=
"
Applink Variables
"
,
type
=
SceneCoat3D
,
description
=
"
Applink variables
"
)
from
bpy.utils
import
register_class
for
cls
in
classes
:
register_class
(
cls
)
bpy
.
types
.
Object
.
coat3D
=
PointerProperty
(
type
=
ObjectCoat3D
)
bpy
.
types
.
Scene
.
coat3D
=
PointerProperty
(
type
=
SceneCoat3D
)
kc
=
bpy
.
context
.
window_manager
.
keyconfigs
.
addon
'''
if kc:
km = kc.keymaps.new(name=
'
3D View
'
, space_type=
'
VIEW_3D
'
)
kmi = km.keymap_items.new(
'
wm.call_menu2
'
,
'
Q
'
,
'
PRESS
'
)
kmi.properties.name =
"
VIEW3D_MT_Coat_Dynamic_Menu
"
'''
def
unregister
():
import
bpy
from
bpy.utils
import
unregister_class
del
bpy
.
types
.
Object
.
coat3D
del
bpy
.
types
.
Scene
.
coat3D
del
bpy
.
coat3D
bpy
.
utils
.
unregister_module
(
__name__
)
if
__name__
==
"
__main__
"
:
register
()
'''
kc = bpy.context.window_manager.keyconfigs.addon
if kc:
km = kc.keymapskeymaps[
'
3D View
'
]
for kmi in km.keymap_items:
if kmi.idname ==
''
:
if kmi.properties.name ==
"
VIEW3D_MT_Coat_Dynamic_Menu
"
:
km.keymap_items.remove(kmi)
break
'''
for
cls
in
reversed
(
classes
):
unregister_class
(
cls
)
This diff is collapsed.
Click to expand it.
io_coat3D/coat.py
deleted
100644 → 0
+
0
−
626
View file @
9ca218bf
This diff is collapsed.
Click to expand it.
io_coat3D/tex.py
+
138
−
4
View file @
c87ee4d4
...
...
@@ -19,8 +19,9 @@
import
bpy
import
os
import
re
def
find_index
(
objekti
):
luku
=
0
for
tex
in
objekti
.
active_material
.
texture_slots
:
if
(
not
(
hasattr
(
tex
,
'
texture
'
))):
...
...
@@ -28,10 +29,143 @@ def find_index(objekti):
luku
=
luku
+
1
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
:
if
(
bpy
.
data
.
filepath
==
''
):
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
'
)
else
:
files_dir
=
os
.
path
.
dirname
(
bpy
.
data
.
filepath
)
+
os
.
sep
+
'
3DCApplink
'
+
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
coa = objekti.coat3D
print(coat3D,coa)
if(bpy.context.scene.render.engine ==
'
VRAY_RENDER
'
or bpy.context.scene.render.engine ==
'
VRAY_RENDER_PREVIEW
'
):
vray = True
...
...
@@ -47,7 +181,7 @@ def gettex(mat_list, objekti, scene,export):
bring_spec = 1
bring_normal = 1
bring_disp = 1
texcoat = {}
texcoat[
'
color
'
] = []
texcoat[
'
specular
'
] = []
...
...
@@ -331,5 +465,5 @@ def gettex(mat_list, objekti, scene,export):
if(objekti.data.uv_textures.active):
objekti.modifiers[
'
Displace
'
].texture_coords =
'
UV
'
objekti.modifiers[
'
Displace
'
].uv_layer = objekti.data.uv_textures.active.name
"""
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