1
Fork 0

Add preset material, pull more variables into the template

This commit is contained in:
Dan Reeves 2021-04-18 08:01:01 +01:00
parent acc2dd9da0
commit d2c7fc7811
3 changed files with 49 additions and 12 deletions

Binary file not shown.

View file

@ -13,7 +13,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
bl_info = {
"name": "Bitsquid Engine",
@ -35,6 +35,7 @@ if "bpy" in locals():
import bpy
from bpy.app.handlers import persistent
from bpy.types import (
Panel,
Operator,
@ -158,8 +159,8 @@ class MATERIAL_OT_bitsquid_export(Operator):
return bpy.data.is_saved and context.active_object is not None
def execute(self, context):
material = context.active_material
return unit_export.save(self, context, material)
material = context.material
return material_export.save(self, context, material)
class MATERIAL_PT_bitsquid(Panel):
@ -213,6 +214,26 @@ def unregister():
for cls in reversed(classes):
unregister_class(cls)
def import_template():
cwd = os.path.dirname(os.path.realpath(__file__))
blendfile = cwd + "\\BitsquidPBR.blend"
section = "\\Material\\"
object = "Stingray Standard"
filepath = blendfile + section + object
directory = blendfile + section
filename = object
bpy.ops.wm.append(
filepath=filepath,
filename=filename,
directory=directory)
@persistent
def load_handler(dummy):
import_template()
bpy.app.handlers.load_post.append(load_handler)
if __name__ == "__main__":
register()

View file

@ -29,30 +29,30 @@ variables = {
base_color = {
type = "vector3"
value = [
1
0.333333333333333
0
{{ base_color[0] }}
{{ base_color[1] }}
{{ base_color[2] }}
]
}
emissive = {
type = "vector3"
value = [
0
0
0
{{ emissive[0] }}
{{ emissive[1] }}
{{ emissive[2] }}
]
}
emissive_intensity = {
type = "scalar"
value = 1
value = {{ emissive_intensity }}
}
metallic = {
type = "scalar"
value = 0
value = {{ metallic }}
}
roughness = {
type = "scalar"
value = 0.91
value = {{ roughness }}
}
use_ao_map = {
type = "scalar"
@ -102,7 +102,23 @@ def save(self, context, material):
namespace = {
'material': material,
'base_color': (1, 1, 1),
'roughness': 0.0,
'metallic': 0.0,
'emissive': (0, 0, 0),
'emissive_intensity': 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
except:
print("Couldn't find Stingray Standard nodes")
content = step.Template(template, strip=False).expand(namespace)
with open(filepath, "w", encoding="utf8", newline="\n") as f: