Instanced rendering
This commit is contained in:
parent
4b964e39eb
commit
acd38c6cbf
38
blender/props.py
Executable file
38
blender/props.py
Executable file
|
@ -0,0 +1,38 @@
|
|||
import shutil
|
||||
import bpy
|
||||
import os
|
||||
import json
|
||||
from bpy.types import Menu, Panel, UIList
|
||||
from bpy.props import *
|
||||
|
||||
def cb_scene_update(context):
|
||||
edit_obj = bpy.context.edit_object
|
||||
if edit_obj is not None and edit_obj.is_updated_data is True:
|
||||
edit_obj.geometry_cached = False
|
||||
|
||||
def initObjectProperties():
|
||||
bpy.types.Object.geometry_cached = bpy.props.BoolProperty(name="Geometry cached", default=False)
|
||||
bpy.types.Object.instanced_children = bpy.props.BoolProperty(name="Instanced children", default=False)
|
||||
bpy.types.Material.export_tangents = bpy.props.BoolProperty(name="Export tangents", default=False)
|
||||
bpy.app.handlers.scene_update_post.append(cb_scene_update)
|
||||
#bpy.app.handlers.scene_update_post.remove(cb_scene_update)
|
||||
|
||||
initObjectProperties()
|
||||
|
||||
|
||||
# Menu in tools region
|
||||
class ToolsPropsPanel(bpy.types.Panel):
|
||||
bl_label = "Cycles Props"
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "object"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
obj = bpy.context.object
|
||||
|
||||
if obj.type == 'MESH':
|
||||
layout.prop(obj, 'instanced_children')
|
||||
|
||||
# Registration
|
||||
bpy.utils.register_module(__name__)
|
|
@ -1122,8 +1122,9 @@ class LueExporter(bpy.types.Operator, ExportHelper):
|
|||
if (not bone.parent):
|
||||
self.ProcessBone(bone)
|
||||
|
||||
for subnode in node.children:
|
||||
self.ProcessNode(subnode)
|
||||
if node.type != 'MESH' or node.instanced_children == False:
|
||||
for subnode in node.children:
|
||||
self.ProcessNode(subnode)
|
||||
|
||||
|
||||
def ProcessSkinnedMeshes(self):
|
||||
|
@ -1273,12 +1274,6 @@ class LueExporter(bpy.types.Operator, ExportHelper):
|
|||
else:
|
||||
parento.nodes.append(o)
|
||||
|
||||
if not hasattr(o, 'nodes'):
|
||||
o.nodes = []
|
||||
for subnode in node.children:
|
||||
if (subnode.parent_type != "BONE"):
|
||||
self.ExportNode(subnode, scene, None, o)
|
||||
|
||||
# Export traits
|
||||
# TODO: export only for geometry nodes and nodes
|
||||
o.traits = []
|
||||
|
@ -1321,6 +1316,13 @@ class LueExporter(bpy.types.Operator, ExportHelper):
|
|||
":" + str(rb.friction)
|
||||
o.traits.append(x)
|
||||
|
||||
if not hasattr(o, 'nodes'):
|
||||
o.nodes = []
|
||||
if node.type != 'MESH' or node.instanced_children == False:
|
||||
for subnode in node.children:
|
||||
if (subnode.parent_type != "BONE"):
|
||||
self.ExportNode(subnode, scene, None, o)
|
||||
|
||||
|
||||
|
||||
def ExportSkin(self, node, armature, exportVertexArray, om):
|
||||
|
@ -1431,6 +1433,21 @@ class LueExporter(bpy.types.Operator, ExportHelper):
|
|||
|
||||
index = self.filepath.rfind('/')
|
||||
fp = self.filepath[:(index+1)] + 'geom_' + oid + '.json'
|
||||
|
||||
# Check if geometry is using instanced rendering
|
||||
is_instanced = False
|
||||
for n in objectRef[1]["nodeTable"]:
|
||||
if n.instanced_children == True:
|
||||
is_instanced = True
|
||||
# TODO: cache instanced geometry
|
||||
node.geometry_cached = False
|
||||
# Save offset data
|
||||
instance_offsets = []
|
||||
for sn in n.children:
|
||||
instance_offsets.append(sn.location.x - n.location.x)
|
||||
instance_offsets.append(sn.location.y - n.location.y)
|
||||
instance_offsets.append(sn.location.z - n.location.z)
|
||||
break
|
||||
|
||||
# No export necessary
|
||||
if node.geometry_cached == True and os.path.exists(fp):
|
||||
|
@ -1719,11 +1736,18 @@ class LueExporter(bpy.types.Operator, ExportHelper):
|
|||
|
||||
mesh.update()
|
||||
|
||||
# Save offset data for instanced rendering
|
||||
|
||||
if is_instanced == True:
|
||||
om.instance_offsets = instance_offsets
|
||||
|
||||
# Delete the new mesh that we made earlier.
|
||||
|
||||
bpy.data.meshes.remove(exportMesh)
|
||||
o.mesh = om
|
||||
|
||||
|
||||
|
||||
# One geometry data per file
|
||||
geom_obj = Object()
|
||||
geom_obj.geometry_resources = [o]
|
||||
|
|
|
@ -141,19 +141,9 @@ class MY_UL_TraitList(bpy.types.UIList):
|
|||
layout.label("", icon = custom_icon)
|
||||
bpy.utils.register_class(MY_UL_TraitList)
|
||||
|
||||
def cb_scene_update(context): # For exporter cache TODO: move to separate file
|
||||
edit_obj = bpy.context.edit_object
|
||||
if edit_obj is not None and edit_obj.is_updated_data is True:
|
||||
edit_obj.geometry_cached = False
|
||||
|
||||
def initObjectProperties():
|
||||
bpy.types.Object.my_traitlist = bpy.props.CollectionProperty(type = ListTraitItem)
|
||||
bpy.types.Object.traitlist_index = bpy.props.IntProperty(name = "Index for my_list", default = 0)
|
||||
|
||||
bpy.types.Object.geometry_cached = bpy.props.BoolProperty(name="Geometry cached", default=False)
|
||||
bpy.types.Material.export_tangents = bpy.props.BoolProperty(name="Export tangents", default=False)
|
||||
bpy.app.handlers.scene_update_post.append(cb_scene_update)
|
||||
#bpy.app.handlers.scene_update_post.remove(cb_scene_update)
|
||||
|
||||
initObjectProperties()
|
||||
|
||||
|
|
Loading…
Reference in a new issue