Merge branch 'improved-material-support-1' into 'master'
Add preset material, pull more variables into the template See merge request lschwiderski/bitsquid-blender-tools!1
This commit is contained in:
commit
8579bc146d
3 changed files with 70 additions and 18 deletions
|
@ -13,7 +13,7 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
import os
|
||||||
|
|
||||||
bl_info = {
|
bl_info = {
|
||||||
"name": "Bitsquid Engine",
|
"name": "Bitsquid Engine",
|
||||||
|
@ -35,6 +35,7 @@ if "bpy" in locals():
|
||||||
|
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
|
from bpy.app.handlers import persistent
|
||||||
from bpy.types import (
|
from bpy.types import (
|
||||||
Panel,
|
Panel,
|
||||||
Operator,
|
Operator,
|
||||||
|
@ -158,8 +159,8 @@ class MATERIAL_OT_bitsquid_export(Operator):
|
||||||
return bpy.data.is_saved and context.active_object is not None
|
return bpy.data.is_saved and context.active_object is not None
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
material = context.active_material
|
material = context.material
|
||||||
return unit_export.save(self, context, material)
|
return material_export.save(self, context, material)
|
||||||
|
|
||||||
|
|
||||||
class MATERIAL_PT_bitsquid(Panel):
|
class MATERIAL_PT_bitsquid(Panel):
|
||||||
|
@ -195,6 +196,25 @@ classes = [
|
||||||
MATERIAL_OT_bitsquid_export,
|
MATERIAL_OT_bitsquid_export,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def import_template():
|
||||||
|
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
resources_dir = "resources"
|
||||||
|
blendfile = "BitsquidPBR.blend"
|
||||||
|
section = "Material"
|
||||||
|
object = "Stingray Standard"
|
||||||
|
|
||||||
|
filepath = os.path.join(cwd, resources_dir, blendfile, section, object)
|
||||||
|
directory = os.path.join(cwd, resources_dir, blendfile, section)
|
||||||
|
filename = object
|
||||||
|
|
||||||
|
bpy.ops.wm.append(
|
||||||
|
filepath=filepath,
|
||||||
|
filename=filename,
|
||||||
|
directory=directory)
|
||||||
|
|
||||||
|
@persistent
|
||||||
|
def load_handler(dummy):
|
||||||
|
import_template()
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
from bpy.utils import register_class
|
from bpy.utils import register_class
|
||||||
|
@ -205,6 +225,7 @@ def register():
|
||||||
bpy.types.Object.bitsquid = PointerProperty(type=BitsquidObjectSettings)
|
bpy.types.Object.bitsquid = PointerProperty(type=BitsquidObjectSettings)
|
||||||
bpy.types.Material.bitsquid = PointerProperty(type=BitsquidMaterialSettings)
|
bpy.types.Material.bitsquid = PointerProperty(type=BitsquidMaterialSettings)
|
||||||
|
|
||||||
|
bpy.app.handlers.load_post.append(load_handler)
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
del bpy.types.Scene.bitsquid
|
del bpy.types.Scene.bitsquid
|
||||||
|
@ -213,6 +234,7 @@ def unregister():
|
||||||
for cls in reversed(classes):
|
for cls in reversed(classes):
|
||||||
unregister_class(cls)
|
unregister_class(cls)
|
||||||
|
|
||||||
|
bpy.app.handlers.load_post.remove(load_handler)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
register()
|
register()
|
||||||
|
|
|
@ -29,54 +29,54 @@ variables = {
|
||||||
base_color = {
|
base_color = {
|
||||||
type = "vector3"
|
type = "vector3"
|
||||||
value = [
|
value = [
|
||||||
1
|
{{ base_color[0] }}
|
||||||
0.333333333333333
|
{{ base_color[1] }}
|
||||||
0
|
{{ base_color[2] }}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
emissive = {
|
emissive = {
|
||||||
type = "vector3"
|
type = "vector3"
|
||||||
value = [
|
value = [
|
||||||
0
|
{{ emissive[0] }}
|
||||||
0
|
{{ emissive[1] }}
|
||||||
0
|
{{ emissive[2] }}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
emissive_intensity = {
|
emissive_intensity = {
|
||||||
type = "scalar"
|
type = "scalar"
|
||||||
value = 1
|
value = {{ emissive_intensity }}
|
||||||
}
|
}
|
||||||
metallic = {
|
metallic = {
|
||||||
type = "scalar"
|
type = "scalar"
|
||||||
value = 0
|
value = {{ metallic }}
|
||||||
}
|
}
|
||||||
roughness = {
|
roughness = {
|
||||||
type = "scalar"
|
type = "scalar"
|
||||||
value = 0.91
|
value = {{ roughness }}
|
||||||
}
|
}
|
||||||
use_ao_map = {
|
use_ao_map = {
|
||||||
type = "scalar"
|
type = "scalar"
|
||||||
value = 0
|
value = {{ use_ao_map }}
|
||||||
}
|
}
|
||||||
use_color_map = {
|
use_color_map = {
|
||||||
type = "scalar"
|
type = "scalar"
|
||||||
value = 0
|
value = {{ use_color_map }}
|
||||||
}
|
}
|
||||||
use_emissive_map = {
|
use_emissive_map = {
|
||||||
type = "scalar"
|
type = "scalar"
|
||||||
value = 0
|
value = {{ use_emissive_map }}
|
||||||
}
|
}
|
||||||
use_metallic_map = {
|
use_metallic_map = {
|
||||||
type = "scalar"
|
type = "scalar"
|
||||||
value = 0
|
value = {{ use_metallic_map }}
|
||||||
}
|
}
|
||||||
use_normal_map = {
|
use_normal_map = {
|
||||||
type = "scalar"
|
type = "scalar"
|
||||||
value = 0
|
value = {{ use_normal_map }}
|
||||||
}
|
}
|
||||||
use_roughness_map = {
|
use_roughness_map = {
|
||||||
type = "scalar"
|
type = "scalar"
|
||||||
value = 0
|
value = {{ use_roughness_map }}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,37 @@ def save(self, context, material):
|
||||||
|
|
||||||
namespace = {
|
namespace = {
|
||||||
'material': material,
|
'material': material,
|
||||||
|
|
||||||
|
'base_color': (1, 1, 1),
|
||||||
|
'roughness': 0.0,
|
||||||
|
'metallic': 0.0,
|
||||||
|
'emissive': (0, 0, 0),
|
||||||
|
'emissive_intensity': 0,
|
||||||
|
|
||||||
|
'use_color_map': 0,
|
||||||
|
'use_roughness_map': 0,
|
||||||
|
'use_metallic_map': 0,
|
||||||
|
'use_emissive_map': 0,
|
||||||
|
'use_ao_map': 0,
|
||||||
|
'use_normal_map': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nodes = material.node_tree.nodes
|
||||||
|
try:
|
||||||
|
namespace['base_color'] = nodes["Base Color"].outputs[0].default_value
|
||||||
|
namespace['roughness'] = nodes["Roughness"].outputs[0].default_value
|
||||||
|
namespace['metallic'] = nodes["Metallic"].outputs[0].default_value
|
||||||
|
namespace['emissive'] = nodes["Emissive"].outputs[0].default_value
|
||||||
|
namespace['emissive_intensity'] = nodes["Emissive Intensity"].outputs[0].default_value
|
||||||
|
namespace['use_color_map'] = nodes["Use Color Map"].outputs[0].default_value
|
||||||
|
namespace['use_roughness_map'] = nodes["Use Roughness Map"].outputs[0].default_value
|
||||||
|
namespace['use_metallic_map'] = nodes["Use Metallic Map"].outputs[0].default_value
|
||||||
|
namespace['use_emissive_map'] = nodes["Use Emissive Map"].outputs[0].default_value
|
||||||
|
namespace['use_ao_map'] = nodes["Use AO Map"].outputs[0].default_value
|
||||||
|
namespace['use_normal_map'] = nodes["Use Normal Map"].outputs[0].default_value
|
||||||
|
except:
|
||||||
|
self.report({'WARNING'}, "Couldn't find Stingray Standard nodes")
|
||||||
|
|
||||||
content = step.Template(template, strip=False).expand(namespace)
|
content = step.Template(template, strip=False).expand(namespace)
|
||||||
|
|
||||||
with open(filepath, "w", encoding="utf8", newline="\n") as f:
|
with open(filepath, "w", encoding="utf8", newline="\n") as f:
|
||||||
|
|
BIN
addons/bitsquid/resources/BitsquidPBR.blend
Normal file
BIN
addons/bitsquid/resources/BitsquidPBR.blend
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue