Improve assets references
This commit is contained in:
parent
e4d811c22f
commit
83f8a82247
|
@ -1899,8 +1899,9 @@ class ArmoryExporter(bpy.types.Operator, ExportHelper):
|
|||
self.particleSystemArray = {}
|
||||
self.boneParentArray = {}
|
||||
|
||||
# Store used shaders in this scene
|
||||
# Store used shaders and assets in this scene
|
||||
ArmoryExporter.shader_references = []
|
||||
ArmoryExporter.asset_references = []
|
||||
ArmoryExporter.exportAllFlag = not self.option_export_selection
|
||||
ArmoryExporter.sampleAnimationFlag = self.option_sample_animation
|
||||
ArmoryExporter.option_geometry_only = self.option_geometry_only
|
||||
|
@ -1991,9 +1992,17 @@ class ArmoryExporter(bpy.types.Operator, ExportHelper):
|
|||
ArmoryExporter.option_minimize = False
|
||||
|
||||
# Only one pipeline for scene for now
|
||||
# Used for material shader export
|
||||
# Used for material shader export and khafile
|
||||
if (len(bpy.data.cameras) > 0):
|
||||
ArmoryExporter.pipeline_pass = bpy.data.cameras[0].pipeline_pass
|
||||
ArmoryExporter.pipeline_id = bpy.data.cameras[0].pipeline_id
|
||||
# Gather passes, not very elegant
|
||||
ArmoryExporter.pipeline_passes = []
|
||||
for node_group in bpy.data.node_groups:
|
||||
if node_group.name == bpy.data.cameras[0].pipeline_path:
|
||||
for node in node_group.nodes:
|
||||
if node.bl_idname == 'DrawGeometryNodeType':
|
||||
ArmoryExporter.pipeline_passes.append(node.inputs[1].default_value) # Context
|
||||
break
|
||||
|
||||
def cb_export_node(self, node, o):
|
||||
#return
|
||||
|
@ -2080,7 +2089,7 @@ class ArmoryExporter(bpy.types.Operator, ExportHelper):
|
|||
o.contexts = []
|
||||
|
||||
c = Object()
|
||||
c.id = ArmoryExporter.pipeline_pass
|
||||
c.id = ArmoryExporter.pipeline_id
|
||||
c.bind_constants = []
|
||||
|
||||
const = Object()
|
||||
|
@ -2173,9 +2182,12 @@ class ArmoryExporter(bpy.types.Operator, ExportHelper):
|
|||
ext = ''
|
||||
for d in defs:
|
||||
ext += d
|
||||
shader_name = ArmoryExporter.pipeline_pass + ext
|
||||
o.shader = shader_name + '/' + shader_name
|
||||
ArmoryExporter.shader_references.append(shader_name)
|
||||
ArmoryExporter.asset_references.append('compiled/ShaderResources/' + ArmoryExporter.pipeline_id + '/' + ArmoryExporter.pipeline_id + ext + '.json')
|
||||
# Process all passes from pipeline
|
||||
for pipe_pass in ArmoryExporter.pipeline_passes:
|
||||
shader_name = pipe_pass + ext
|
||||
o.shader = shader_name + '/' + shader_name
|
||||
ArmoryExporter.shader_references.append('compiled/Shaders/' + ArmoryExporter.pipeline_id + '/' + shader_name)
|
||||
else:
|
||||
# TODO: gather defs from vertex data when custom shader is used
|
||||
o.shader = material.custom_shader_name
|
||||
|
|
|
@ -302,7 +302,8 @@ def buildNode(res, node, node_group):
|
|||
|
||||
elif node.bl_idname == 'DrawQuadNodeType':
|
||||
stage.command = 'draw_quad'
|
||||
stage.params.append(node.inputs[1].default_value) # Material context
|
||||
material_context = node.inputs[1].default_value
|
||||
stage.params.append(material_context)
|
||||
|
||||
elif node.bl_idname == 'DrawWorldNodeType':
|
||||
stage.command = 'draw_quad'
|
||||
|
|
|
@ -19,7 +19,7 @@ class Object:
|
|||
# return json.dumps(self, default=lambda o: o.__dict__, separators=(',',':'))
|
||||
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
|
||||
|
||||
def buildNodeTrees():
|
||||
def buildNodeTrees(shader_references, asset_references):
|
||||
s = bpy.data.filepath.split(os.path.sep)
|
||||
s.pop()
|
||||
fp = os.path.sep.join(s)
|
||||
|
@ -31,9 +31,9 @@ def buildNodeTrees():
|
|||
|
||||
# Export world nodes
|
||||
for world in bpy.data.worlds:
|
||||
buildNodeTree(world.name, world.node_tree)
|
||||
buildNodeTree(world.name, world.node_tree, shader_references, asset_references)
|
||||
|
||||
def buildNodeTree(world_name, node_group):
|
||||
def buildNodeTree(world_name, node_group, shader_references, asset_references):
|
||||
output = Object()
|
||||
res = Object()
|
||||
output.material_resources = [res]
|
||||
|
@ -54,8 +54,12 @@ def buildNodeTree(world_name, node_group):
|
|||
texture.id = 'envmap'
|
||||
texture.name = ''
|
||||
for node in node_group.nodes:
|
||||
# Env map included
|
||||
if node.bl_idname == 'ShaderNodeTexEnvironment': # Just look for env texture for now
|
||||
texture.name = node.image.name.rsplit('.', 1)[0] # Remove extension
|
||||
# Add resources to khafie
|
||||
asset_references.append('compiled/ShaderResources/env_map/env_map.json')
|
||||
shader_references.append('compiled/Shaders/env_map/env_map')
|
||||
|
||||
with open(path + material_name + '.json', 'w') as f:
|
||||
f.write(output.to_JSON())
|
||||
|
|
|
@ -15,272 +15,275 @@ import nodes_world
|
|||
from armory import ArmoryExporter
|
||||
|
||||
def defaultSettings():
|
||||
wrd = bpy.data.worlds[0]
|
||||
wrd['CGVersion'] = "16.1.0"
|
||||
wrd['CGProjectTarget'] = 0
|
||||
wrd['CGProjectName'] = "cycles_game"
|
||||
wrd['CGProjectPackage'] = "game"
|
||||
wrd['CGProjectWidth'] = 1136
|
||||
wrd['CGProjectHeight'] = 640
|
||||
wrd['CGProjectScene'] = bpy.data.scenes[0].name
|
||||
wrd['CGAA'] = 1
|
||||
wrd['CGPhysics'] = 0
|
||||
wrd['CGMinimize'] = (True)
|
||||
# Make sure we are using cycles
|
||||
if bpy.data.scenes[0].render.engine == 'BLENDER_RENDER':
|
||||
for scene in bpy.data.scenes:
|
||||
scene.render.engine = 'CYCLES'
|
||||
wrd = bpy.data.worlds[0]
|
||||
wrd['CGVersion'] = "16.1.0"
|
||||
wrd['CGProjectTarget'] = 0
|
||||
wrd['CGProjectName'] = "cycles_game"
|
||||
wrd['CGProjectPackage'] = "game"
|
||||
wrd['CGProjectWidth'] = 1136
|
||||
wrd['CGProjectHeight'] = 640
|
||||
wrd['CGProjectScene'] = bpy.data.scenes[0].name
|
||||
wrd['CGAA'] = 1
|
||||
wrd['CGPhysics'] = 0
|
||||
wrd['CGMinimize'] = (True)
|
||||
# Make sure we are using cycles
|
||||
if bpy.data.scenes[0].render.engine == 'BLENDER_RENDER':
|
||||
for scene in bpy.data.scenes:
|
||||
scene.render.engine = 'CYCLES'
|
||||
|
||||
# Store properties in the world object
|
||||
def initWorldProperties():
|
||||
bpy.types.World.CGVersion = StringProperty(name = "CGVersion")
|
||||
bpy.types.World.CGProjectTarget = EnumProperty(
|
||||
items = [('HTML5', 'HTML5', 'HTML5'),
|
||||
('Windows', 'Windows', 'Windows'),
|
||||
('OSX', 'OSX', 'OSX'),
|
||||
('Linux', 'Linux', 'Linux'),
|
||||
('iOS', 'iOS', 'iOS'),
|
||||
('Android', 'Android', 'Android')],
|
||||
name = "Target")
|
||||
bpy.types.World.CGProjectName = StringProperty(name = "Name")
|
||||
bpy.types.World.CGProjectPackage = StringProperty(name = "Package")
|
||||
bpy.types.World.CGProjectWidth = IntProperty(name = "Width")
|
||||
bpy.types.World.CGProjectHeight = IntProperty(name = "Height")
|
||||
bpy.types.World.CGProjectScene = StringProperty(name = "Scene")
|
||||
bpy.types.World.CGAA = EnumProperty(
|
||||
items = [('Disabled', 'Disabled', 'Disabled'),
|
||||
('16X', '16X', '16X')],
|
||||
name = "Anti-aliasing")
|
||||
bpy.types.World.CGPhysics = EnumProperty(
|
||||
items = [('Disabled', 'Disabled', 'Disabled'),
|
||||
('Bullet', 'Bullet', 'Bullet')],
|
||||
name = "Physics")
|
||||
bpy.types.World.CGMinimize = BoolProperty(name = "Minimize")
|
||||
bpy.types.World.CGVersion = StringProperty(name = "CGVersion")
|
||||
bpy.types.World.CGProjectTarget = EnumProperty(
|
||||
items = [('HTML5', 'HTML5', 'HTML5'),
|
||||
('Windows', 'Windows', 'Windows'),
|
||||
('OSX', 'OSX', 'OSX'),
|
||||
('Linux', 'Linux', 'Linux'),
|
||||
('iOS', 'iOS', 'iOS'),
|
||||
('Android', 'Android', 'Android')],
|
||||
name = "Target")
|
||||
bpy.types.World.CGProjectName = StringProperty(name = "Name")
|
||||
bpy.types.World.CGProjectPackage = StringProperty(name = "Package")
|
||||
bpy.types.World.CGProjectWidth = IntProperty(name = "Width")
|
||||
bpy.types.World.CGProjectHeight = IntProperty(name = "Height")
|
||||
bpy.types.World.CGProjectScene = StringProperty(name = "Scene")
|
||||
bpy.types.World.CGAA = EnumProperty(
|
||||
items = [('Disabled', 'Disabled', 'Disabled'),
|
||||
('16X', '16X', '16X')],
|
||||
name = "Anti-aliasing")
|
||||
bpy.types.World.CGPhysics = EnumProperty(
|
||||
items = [('Disabled', 'Disabled', 'Disabled'),
|
||||
('Bullet', 'Bullet', 'Bullet')],
|
||||
name = "Physics")
|
||||
bpy.types.World.CGMinimize = BoolProperty(name = "Minimize")
|
||||
|
||||
# Default settings
|
||||
if not 'CGVersion' in bpy.data.worlds[0]:
|
||||
defaultSettings()
|
||||
# Default settings
|
||||
if not 'CGVersion' in bpy.data.worlds[0]:
|
||||
defaultSettings()
|
||||
|
||||
# Use material nodes
|
||||
for mat in bpy.data.materials:
|
||||
bpy.ops.cycles.use_shading_nodes({"material":mat})
|
||||
# Use world nodes
|
||||
for wrd in bpy.data.worlds:
|
||||
bpy.ops.cycles.use_shading_nodes({"world":wrd})
|
||||
|
||||
return
|
||||
# Use material nodes
|
||||
for mat in bpy.data.materials:
|
||||
bpy.ops.cycles.use_shading_nodes({"material":mat})
|
||||
# Use world nodes
|
||||
for wrd in bpy.data.worlds:
|
||||
bpy.ops.cycles.use_shading_nodes({"world":wrd})
|
||||
|
||||
return
|
||||
|
||||
# Info panel play
|
||||
def draw_play_item(self, context):
|
||||
layout = self.layout
|
||||
layout.operator("cg.play")
|
||||
layout = self.layout
|
||||
layout.operator("cg.play")
|
||||
|
||||
# Menu in render region
|
||||
class ToolsPanel(bpy.types.Panel):
|
||||
bl_label = "Cycles Game"
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "render"
|
||||
bl_label = "Cycles Game"
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "render"
|
||||
|
||||
# Info panel play
|
||||
#bpy.types.INFO_HT_header.prepend(draw_play_item)
|
||||
bpy.types.VIEW3D_HT_header.append(draw_play_item)
|
||||
# Info panel play
|
||||
#bpy.types.INFO_HT_header.prepend(draw_play_item)
|
||||
bpy.types.VIEW3D_HT_header.append(draw_play_item)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
wrd = bpy.data.worlds[0]
|
||||
layout.prop(wrd, 'CGProjectName')
|
||||
layout.prop(wrd, 'CGProjectPackage')
|
||||
row = layout.row()
|
||||
row.prop(wrd, 'CGProjectWidth')
|
||||
row.prop(wrd, 'CGProjectHeight')
|
||||
layout.prop_search(wrd, "CGProjectScene", bpy.data, "scenes", "Scene")
|
||||
layout.prop(wrd, 'CGProjectTarget')
|
||||
layout.operator("cg.build")
|
||||
row = layout.row(align=True)
|
||||
row.alignment = 'EXPAND'
|
||||
row.operator("cg.folder")
|
||||
row.operator("cg.clean")
|
||||
layout.prop(wrd, 'CGAA')
|
||||
layout.prop(wrd, 'CGPhysics')
|
||||
layout.prop(wrd, 'CGMinimize')
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
wrd = bpy.data.worlds[0]
|
||||
layout.prop(wrd, 'CGProjectName')
|
||||
layout.prop(wrd, 'CGProjectPackage')
|
||||
row = layout.row()
|
||||
row.prop(wrd, 'CGProjectWidth')
|
||||
row.prop(wrd, 'CGProjectHeight')
|
||||
layout.prop_search(wrd, "CGProjectScene", bpy.data, "scenes", "Scene")
|
||||
layout.prop(wrd, 'CGProjectTarget')
|
||||
layout.operator("cg.build")
|
||||
row = layout.row(align=True)
|
||||
row.alignment = 'EXPAND'
|
||||
row.operator("cg.folder")
|
||||
row.operator("cg.clean")
|
||||
layout.prop(wrd, 'CGAA')
|
||||
layout.prop(wrd, 'CGPhysics')
|
||||
layout.prop(wrd, 'CGMinimize')
|
||||
|
||||
class Object:
|
||||
def to_JSON(self):
|
||||
if bpy.data.worlds[0]['CGMinimize'] == True:
|
||||
return json.dumps(self, default=lambda o: o.__dict__, separators=(',',':'))
|
||||
else:
|
||||
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
|
||||
def to_JSON(self):
|
||||
if bpy.data.worlds[0]['CGMinimize'] == True:
|
||||
return json.dumps(self, default=lambda o: o.__dict__, separators=(',',':'))
|
||||
else:
|
||||
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=4)
|
||||
|
||||
# Convert Blender data into game data
|
||||
# Transform Blender data into game data
|
||||
def exportGameData():
|
||||
# TODO: Set armatures to center of world so skin transform is zero
|
||||
armatures = []
|
||||
for o in bpy.data.objects:
|
||||
if o.type == 'ARMATURE':
|
||||
a = Object()
|
||||
a.armature = o
|
||||
a.x = o.location.x
|
||||
a.y = o.location.y
|
||||
a.z = o.location.z
|
||||
armatures.append(a)
|
||||
o.location.x = 0
|
||||
o.location.y = 0
|
||||
o.location.z = 0
|
||||
shader_references = []
|
||||
asset_references = []
|
||||
|
||||
# Build nodes # TODO: only if needed
|
||||
nodes_logic.buildNodeTrees()
|
||||
nodes_pipeline.buildNodeTrees()
|
||||
nodes_world.buildNodeTrees(shader_references, asset_references) # TODO: Have to build nodes everytime to collect env map resources, should be cached
|
||||
|
||||
# Export scene data
|
||||
shader_references = []
|
||||
for scene in bpy.data.scenes:
|
||||
if scene.name[0] != '.': # Skip hidden scenes
|
||||
bpy.ops.export_scene.armory({"scene":scene}, filepath='Assets/generated/' + scene.name + '.json')
|
||||
shader_references += ArmoryExporter.shader_references
|
||||
# TODO: Set armatures to center of world so skin transform is zero
|
||||
armatures = []
|
||||
for o in bpy.data.objects:
|
||||
if o.type == 'ARMATURE':
|
||||
a = Object()
|
||||
a.armature = o
|
||||
a.x = o.location.x
|
||||
a.y = o.location.y
|
||||
a.z = o.location.z
|
||||
armatures.append(a)
|
||||
o.location.x = 0
|
||||
o.location.y = 0
|
||||
o.location.z = 0
|
||||
|
||||
# Move armatures back
|
||||
for a in armatures:
|
||||
a.armature.location.x = a.x
|
||||
a.armature.location.y = a.y
|
||||
a.armature.location.z = a.z
|
||||
|
||||
# Write khafile.js
|
||||
write_data.write_khafilejs(shader_references)
|
||||
# Export scene data
|
||||
for scene in bpy.data.scenes:
|
||||
if scene.name[0] != '.': # Skip hidden scenes
|
||||
bpy.ops.export_scene.armory({"scene":scene}, filepath='Assets/generated/' + scene.name + '.json')
|
||||
shader_references += ArmoryExporter.shader_references
|
||||
asset_references += ArmoryExporter.asset_references
|
||||
|
||||
# Write Main.hx
|
||||
write_data.write_main()
|
||||
# Move armatures back
|
||||
for a in armatures:
|
||||
a.armature.location.x = a.x
|
||||
a.armature.location.y = a.y
|
||||
a.armature.location.z = a.z
|
||||
|
||||
# Write khafile.js
|
||||
write_data.write_khafilejs(shader_references, asset_references)
|
||||
|
||||
# Write Main.hx
|
||||
write_data.write_main()
|
||||
|
||||
def buildProject(self, build_type=0):
|
||||
# Save blend
|
||||
bpy.ops.wm.save_mainfile()
|
||||
# Save blend
|
||||
bpy.ops.wm.save_mainfile()
|
||||
|
||||
# Save scripts
|
||||
#area = bpy.context.area
|
||||
#old_type = area.type
|
||||
#area.type = 'TEXT_EDITOR'
|
||||
#for text in bpy.data.texts:
|
||||
#area.spaces[0].text = text
|
||||
#bpy.ops.text.save()
|
||||
##bpy.ops.text.save()
|
||||
#area.type = old_type
|
||||
# Save scripts
|
||||
#area = bpy.context.area
|
||||
#old_type = area.type
|
||||
#area.type = 'TEXT_EDITOR'
|
||||
#for text in bpy.data.texts:
|
||||
#area.spaces[0].text = text
|
||||
#bpy.ops.text.save()
|
||||
##bpy.ops.text.save()
|
||||
#area.type = old_type
|
||||
|
||||
# Set dir
|
||||
s = bpy.data.filepath.split(os.path.sep)
|
||||
name = s.pop()
|
||||
name = name.split(".")
|
||||
name = name[0]
|
||||
fp = os.path.sep.join(s)
|
||||
os.chdir(fp)
|
||||
|
||||
# Auto-build nodes # TODO: only if needed
|
||||
nodes_logic.buildNodeTrees()
|
||||
nodes_pipeline.buildNodeTrees()
|
||||
nodes_world.buildNodeTrees()
|
||||
|
||||
# Set dir
|
||||
s = bpy.data.filepath.split(os.path.sep)
|
||||
name = s.pop()
|
||||
name = name.split(".")
|
||||
name = name[0]
|
||||
fp = os.path.sep.join(s)
|
||||
os.chdir(fp)
|
||||
# Export
|
||||
exportGameData()
|
||||
|
||||
# Set build command
|
||||
if (bpy.data.worlds[0]['CGProjectTarget'] == 0):
|
||||
bashCommand = "-t html5"
|
||||
elif (bpy.data.worlds[0]['CGProjectTarget'] == 1):
|
||||
bashCommand = "-t windows"
|
||||
elif (bpy.data.worlds[0]['CGProjectTarget'] == 2):
|
||||
bashCommand = "-t osx"
|
||||
elif (bpy.data.worlds[0]['CGProjectTarget'] == 3):
|
||||
bashCommand = "-t linux"
|
||||
elif (bpy.data.worlds[0]['CGProjectTarget'] == 4):
|
||||
bashCommand = "-t ios"
|
||||
elif (bpy.data.worlds[0]['CGProjectTarget'] == 5):
|
||||
bashCommand = "-t android-native"
|
||||
|
||||
# Build
|
||||
haxelib_path = "haxelib"
|
||||
if platform.system() == 'Darwin':
|
||||
haxelib_path = "/usr/local/bin/haxelib"
|
||||
|
||||
# Export
|
||||
exportGameData()
|
||||
|
||||
# Set build command
|
||||
if (bpy.data.worlds[0]['CGProjectTarget'] == 0):
|
||||
bashCommand = "-t html5"
|
||||
elif (bpy.data.worlds[0]['CGProjectTarget'] == 1):
|
||||
bashCommand = "-t windows"
|
||||
elif (bpy.data.worlds[0]['CGProjectTarget'] == 2):
|
||||
bashCommand = "-t osx"
|
||||
elif (bpy.data.worlds[0]['CGProjectTarget'] == 3):
|
||||
bashCommand = "-t linux"
|
||||
elif (bpy.data.worlds[0]['CGProjectTarget'] == 4):
|
||||
bashCommand = "-t ios"
|
||||
elif (bpy.data.worlds[0]['CGProjectTarget'] == 5):
|
||||
bashCommand = "-t android-native"
|
||||
|
||||
# Build
|
||||
haxelib_path = "haxelib"
|
||||
if platform.system() == 'Darwin':
|
||||
haxelib_path = "/usr/local/bin/haxelib"
|
||||
prefix = haxelib_path + " run kha "
|
||||
|
||||
prefix = haxelib_path + " run kha "
|
||||
output = subprocess.check_output([haxelib_path + " path cyclesgame"], shell=True)
|
||||
output = str(output).split("\\n")[0].split("'")[1]
|
||||
scripts_path = output[:-8] + "blender/"
|
||||
|
||||
output = subprocess.check_output([haxelib_path + " path cyclesgame"], shell=True)
|
||||
output = str(output).split("\\n")[0].split("'")[1]
|
||||
scripts_path = output[:-8] + "blender/"
|
||||
|
||||
blender_path = bpy.app.binary_path
|
||||
blend_path = bpy.data.filepath
|
||||
p = subprocess.Popen([blender_path, blend_path, '-b', '-P', scripts_path + 'lib/build.py', '--', bashCommand, str(build_type), str(bpy.data.worlds[0]['CGProjectTarget'])])
|
||||
#p = subprocess.Popen([blender_path, blend_path, '-b', '-P', scripts_path + 'lib/build.py', '--', prefix + bashCommand, str(build_type), str(bpy.data.worlds[0]['CGProjectTarget'])])
|
||||
atexit.register(p.terminate)
|
||||
|
||||
self.report({'INFO'}, "Building, see console...")
|
||||
blender_path = bpy.app.binary_path
|
||||
blend_path = bpy.data.filepath
|
||||
p = subprocess.Popen([blender_path, blend_path, '-b', '-P', scripts_path + 'lib/build.py', '--', bashCommand, str(build_type), str(bpy.data.worlds[0]['CGProjectTarget'])])
|
||||
#p = subprocess.Popen([blender_path, blend_path, '-b', '-P', scripts_path + 'lib/build.py', '--', prefix + bashCommand, str(build_type), str(bpy.data.worlds[0]['CGProjectTarget'])])
|
||||
atexit.register(p.terminate)
|
||||
|
||||
self.report({'INFO'}, "Building, see console...")
|
||||
|
||||
def cleanProject(self):
|
||||
# Set dir
|
||||
s = bpy.data.filepath.split(os.path.sep)
|
||||
name = s.pop()
|
||||
name = name.split(".")
|
||||
name = name[0]
|
||||
fp = os.path.sep.join(s)
|
||||
os.chdir(fp)
|
||||
|
||||
# Remove build data
|
||||
if os.path.isdir("build"):
|
||||
shutil.rmtree('build')
|
||||
# Set dir
|
||||
s = bpy.data.filepath.split(os.path.sep)
|
||||
name = s.pop()
|
||||
name = name.split(".")
|
||||
name = name[0]
|
||||
fp = os.path.sep.join(s)
|
||||
os.chdir(fp)
|
||||
|
||||
# Remove build data
|
||||
if os.path.isdir("build"):
|
||||
shutil.rmtree('build')
|
||||
|
||||
# Remove generated data
|
||||
if os.path.isdir("Assets/generated"):
|
||||
shutil.rmtree('Assets/generated')
|
||||
# Remove generated data
|
||||
if os.path.isdir("Assets/generated"):
|
||||
shutil.rmtree('Assets/generated')
|
||||
|
||||
# Remove compiled nodes
|
||||
nodes_path = "Sources/" + bpy.data.worlds[0].CGProjectPackage.replace(".", "/") + "/node/"
|
||||
if os.path.isdir(nodes_path):
|
||||
shutil.rmtree(nodes_path)
|
||||
# Remove compiled nodes
|
||||
nodes_path = "Sources/" + bpy.data.worlds[0].CGProjectPackage.replace(".", "/") + "/node/"
|
||||
if os.path.isdir(nodes_path):
|
||||
shutil.rmtree(nodes_path)
|
||||
|
||||
self.report({'INFO'}, "Done")
|
||||
self.report({'INFO'}, "Done")
|
||||
|
||||
# Play
|
||||
class OBJECT_OT_PLAYButton(bpy.types.Operator):
|
||||
bl_idname = "cg.play"
|
||||
bl_label = "Play"
|
||||
bl_idname = "cg.play"
|
||||
bl_label = "Play"
|
||||
|
||||
def execute(self, context):
|
||||
buildProject(self, 1)
|
||||
return{'FINISHED'}
|
||||
def execute(self, context):
|
||||
buildProject(self, 1)
|
||||
return{'FINISHED'}
|
||||
|
||||
# Build
|
||||
class OBJECT_OT_BUILDButton(bpy.types.Operator):
|
||||
bl_idname = "cg.build"
|
||||
bl_label = "Build"
|
||||
bl_idname = "cg.build"
|
||||
bl_label = "Build"
|
||||
|
||||
def execute(self, context):
|
||||
buildProject(self, 0)
|
||||
return{'FINISHED'}
|
||||
def execute(self, context):
|
||||
buildProject(self, 0)
|
||||
return{'FINISHED'}
|
||||
|
||||
# Open project folder
|
||||
class OBJECT_OT_FOLDERButton(bpy.types.Operator):
|
||||
bl_idname = "cg.folder"
|
||||
bl_label = "Folder"
|
||||
bl_idname = "cg.folder"
|
||||
bl_label = "Folder"
|
||||
|
||||
def execute(self, context):
|
||||
s = bpy.data.filepath.split(os.path.sep)
|
||||
name = s.pop()
|
||||
name = name.split(".")
|
||||
name = name[0]
|
||||
fp = os.path.sep.join(s)
|
||||
|
||||
webbrowser.open('file://' + fp)
|
||||
return{'FINISHED'}
|
||||
|
||||
def execute(self, context):
|
||||
s = bpy.data.filepath.split(os.path.sep)
|
||||
name = s.pop()
|
||||
name = name.split(".")
|
||||
name = name[0]
|
||||
fp = os.path.sep.join(s)
|
||||
|
||||
webbrowser.open('file://' + fp)
|
||||
return{'FINISHED'}
|
||||
|
||||
# Clean project
|
||||
class OBJECT_OT_CLEANButton(bpy.types.Operator):
|
||||
bl_idname = "cg.clean"
|
||||
bl_label = "Clean"
|
||||
bl_idname = "cg.clean"
|
||||
bl_label = "Clean"
|
||||
|
||||
def execute(self, context):
|
||||
cleanProject(self)
|
||||
return{'FINISHED'}
|
||||
def execute(self, context):
|
||||
cleanProject(self)
|
||||
return{'FINISHED'}
|
||||
|
||||
# Registration
|
||||
def register():
|
||||
bpy.utils.register_module(__name__)
|
||||
# Store properties in world
|
||||
initWorldProperties()
|
||||
bpy.utils.register_module(__name__)
|
||||
# Store properties in world
|
||||
initWorldProperties()
|
||||
|
||||
def unregister():
|
||||
bpy.utils.unregister_module(__name__)
|
||||
bpy.utils.unregister_module(__name__)
|
||||
|
|
|
@ -23,7 +23,7 @@ def initProperties():
|
|||
bpy.types.Camera.frustum_culling = bpy.props.BoolProperty(name="Frustum Culling", default=False)
|
||||
bpy.types.Camera.sort_front_to_back = bpy.props.BoolProperty(name="Sort Front to Back", default=False)
|
||||
bpy.types.Camera.pipeline_path = bpy.props.StringProperty(name="Pipeline Path", default="forward_pipeline")
|
||||
bpy.types.Camera.pipeline_pass = bpy.props.StringProperty(name="Pipeline Pass", default="forward")
|
||||
bpy.types.Camera.pipeline_id = bpy.props.StringProperty(name="Pipeline ID", default="forward")
|
||||
# For material
|
||||
bpy.types.Material.lighting_bool = bpy.props.BoolProperty(name="Lighting", default=True)
|
||||
bpy.types.Material.receive_shadow = bpy.props.BoolProperty(name="Receive Shadow", default=True)
|
||||
|
@ -63,7 +63,7 @@ class DataPropsPanel(bpy.types.Panel):
|
|||
layout.prop(obj.data, 'frustum_culling')
|
||||
layout.prop(obj.data, 'sort_front_to_back')
|
||||
layout.prop_search(obj.data, "pipeline_path", bpy.data, "node_groups")
|
||||
layout.prop(obj.data, 'pipeline_pass')
|
||||
layout.prop(obj.data, 'pipeline_id')
|
||||
layout.operator("cg.reset_pipelines")
|
||||
elif obj.type == 'MESH':
|
||||
layout.prop(obj.data, 'static_usage')
|
||||
|
|
|
@ -2,10 +2,11 @@ import bpy
|
|||
import os
|
||||
|
||||
# Write khafile.js
|
||||
def write_khafilejs(shader_references):
|
||||
def write_khafilejs(shader_references, asset_references):
|
||||
|
||||
# Merge duplicates and sort
|
||||
shader_references = sorted(list(set(shader_references)))
|
||||
asset_references = sorted(list(set(asset_references)))
|
||||
|
||||
with open('khafile.js', 'w') as f:
|
||||
f.write(
|
||||
|
@ -19,24 +20,12 @@ project.addAssets('Assets/**');
|
|||
project.addLibrary('cyclesgame');
|
||||
""")
|
||||
|
||||
for ref in shader_references:
|
||||
# ArmoryExporter.pipeline_pass instead of split
|
||||
base_name = ref.split('_', 1)[0] + "/"
|
||||
f.write("project.addAssets('compiled/ShaderResources/" + base_name + "" + ref + ".json');\n")
|
||||
f.write("project.addShaders('compiled/Shaders/" + base_name + "" + ref + ".frag.glsl');\n")
|
||||
f.write("project.addShaders('compiled/Shaders/" + base_name + "" + ref + ".vert.glsl');\n")
|
||||
# TODO: properly include all shader contexts
|
||||
defsarr = ref.split('_', 1) # Get shader defs and append to shadowmap shader name
|
||||
defs = ''
|
||||
if len(defsarr) > 1:
|
||||
defs = '_' + defsarr[1]
|
||||
f.write("project.addShaders('compiled/Shaders/" + base_name + "" + 'shadowmap' + defs + ".frag.glsl');\n")
|
||||
f.write("project.addShaders('compiled/Shaders/" + base_name + "" + 'shadowmap' + defs + ".vert.glsl');\n")
|
||||
|
||||
# TODO: include env map only when used by world nodes
|
||||
f.write("project.addAssets('compiled/ShaderResources/env_map/env_map.json');\n")
|
||||
f.write("project.addShaders('compiled/Shaders/env_map/env_map.frag.glsl');\n")
|
||||
f.write("project.addShaders('compiled/Shaders/env_map/env_map.vert.glsl');\n")
|
||||
for ref in shader_references: # Shaders
|
||||
f.write("project.addShaders('" + ref + ".frag.glsl');\n")
|
||||
f.write("project.addShaders('" + ref + ".vert.glsl');\n")
|
||||
|
||||
for ref in asset_references: # Assets
|
||||
f.write("project.addAssets('" + ref + "');\n")
|
||||
|
||||
if bpy.data.worlds[0]['CGPhysics'] != 0:
|
||||
f.write("\nproject.addDefine('WITH_PHYSICS')\n")
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
var project = new Project('cycles_library');
|
||||
|
||||
//project.addSources('Sources');
|
||||
//project.addShaders('Sources/Shaders/**');
|
||||
//project.addAssets('Assets/**');
|
||||
|
||||
return project;
|
Loading…
Reference in a new issue