Skip to content

Commit

Permalink
Tower of Babel changes
Browse files Browse the repository at this point in the history
- more to get imposters on instances
- color picker for particle hair base color
  • Loading branch information
Palmer-JC committed Jul 7, 2017
1 parent 98a32e5 commit 519548e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 25 deletions.
Expand Up @@ -33,6 +33,7 @@ def define_animations(self, object, supportsRotation, supportsPosition, supports
frameOffset = 0

currentAction = object.animation_data.action
currentFrame = bpy.context.scene.frame_current
for action in bpy.data.actions:
# get the range / assigning the action to the object
animationRange = AnimationRange.actionPrep(object, action, False, frameOffset)
Expand All @@ -54,6 +55,7 @@ def define_animations(self, object, supportsRotation, supportsPosition, supports
frameOffset = animationRange.frame_end

object.animation_data.action = currentAction
bpy.context.scene.frame_set(currentFrame)
#Set Animations
self.animations = []
if supportsRotation and len(rotAnimation.frames) > 0:
Expand Down
17 changes: 12 additions & 5 deletions QueuedInterpolation/Blender/src/tower-of-babel/mesh.py
Expand Up @@ -807,7 +807,7 @@ def writeMakeInstances(self, file_handler, var, indent):
file_handler.write(indent + 'var instance;\n')
for instance in self.instances:
file_handler.write(indent + 'instance = ' + var + '.createInstance("' + instance.name + '");\n')
writePosRotScale(file_handler, instance, 'instance', indent)
writePosRotScale(file_handler, instance, 'instance', indent, True)
file_handler.write(indent + 'if (positionOffset) instance.position.addInPlace(positionOffset);\n')
file_handler.write(indent + 'instance.checkCollisions = ' + format_bool(self.checkCollisions) + ';\n')
if self.animationsPresent:
Expand Down Expand Up @@ -887,7 +887,7 @@ def mesh_node_common_script(file_handler, typescript_file_handler, meshOrNode, i
return baseClass
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# module level since called from Mesh & Node, and also for instances
def writePosRotScale(file_handler, object, var, indent):
def writePosRotScale(file_handler, object, var, indent, isInstance = False):
# these need to be written prior to freezing
# this also needs to be called in parent, prior to children instancing, so freeze works for them too
# remember switching y with z at the same time
Expand All @@ -909,9 +909,10 @@ def writePosRotScale(file_handler, object, var, indent):
file_handler.write(indent + var + '.freezeWorldMatrix();\n')

if hasattr(object, 'physicsImpostor'):
file_handler.write(indent + 'if (!scene.isPhysicsEnabled()) {\n')
file_handler.write(indent + '\tscene.enablePhysics();\n')
file_handler.write(indent + '}\n')
if not isInstance:
file_handler.write(indent + 'if (!scene.isPhysicsEnabled()) {\n')
file_handler.write(indent + '\tscene.enablePhysics();\n')
file_handler.write(indent + '}\n')
file_handler.write(indent + var + '.physicsImpostor = new _B.PhysicsImpostor(' + var + ', ' +
format_int(object.physicsImpostor) +
', { mass: ' + format_f(object.physicsMass) +
Expand All @@ -936,6 +937,12 @@ def __init__(self, instancedMesh, rotation, rotationQuaternion):
self.rotationQuaternion = rotationQuaternion
self.scaling = instancedMesh.scaling
self.freezeWorldMatrix = instancedMesh.freezeWorldMatrix

if hasattr(instancedMesh, 'physicsImpostor'):
self.physicsImpostor = instancedMesh.physicsImpostor
self.physicsMass = instancedMesh.physicsMass
self.physicsFriction = instancedMesh.physicsFriction
self.physicsRestitution = instancedMesh.physicsRestitution
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def to_scene_file(self, file_handler):
file_handler.write('{')
Expand Down
60 changes: 41 additions & 19 deletions QueuedInterpolation/Blender/src/tower-of-babel/particle_hair.py
Expand Up @@ -19,13 +19,11 @@ def __init__(self, particle_sys, mesh, bjsMesh, exporter):

# allow the parent mesh to declare this child correctly in .d.ts file
self.userSuppliedBaseClass = 'QI.Hair'

# since materials of mesh have already been processed, just need to assign it here
bjsMaterial = exporter.getMaterial( particle_sys.settings.material_slot, True)
if bjsMaterial is not None and hasattr(bjsMaterial, 'diffuse'):
self.color = bjsMaterial.diffuse
else:
self.color = Color((1, 1, 1))

# grab the custom properties
self.boneName = particle_sys.settings.boneName
self.stiffness = particle_sys.settings.stiffness
self.baseColor = particle_sys.settings.baseColor

# find the modifier name & temporarily convert it
for mod in [m for m in mesh.modifiers if m.type == 'PARTICLE_SYSTEM']:
Expand Down Expand Up @@ -120,16 +118,16 @@ def to_script_file(self, file_handler, typescript_file_handler, kids, indent, ex
file_handler.write(indent2 + 'ret.castShadows = ' + format_bool(self.bjsMesh.castShadows) + ';\n')
file_handler.write(indent2 + 'ret.skeleton = parent.skeleton;\n\n')

file_handler.write(indent2 + 'ret.color = new _B.Color3(' + format_color(self.color) + ');\n')
file_handler.write(indent2 + 'ret.color = new _B.Color3(' + format_color(self.baseColor) + ');\n')

file_handler.write(indent2 + 'var strandNumVerts = [' + format_array(self.strandNumVerts, indent2) + '];\n')
file_handler.write(indent2 + 'var rootRelativePositions = [' + format_array(self.rootRelativePositions, indent2) + '];\n')
file_handler.write(indent2 + 'ret.assemble(strandNumVerts, rootRelativePositions, ' + format_int(self.longestStrand) + ');\n')
file_handler.write(indent2 + 'ret.assemble(strandNumVerts, rootRelativePositions, ' + format_int(self.longestStrand) + ', ' + format_f(self.stiffness) + ', "' + self.boneName + '");\n')
file_handler.write(indent2 + 'return ret;\n')
file_handler.write(indent + '}\n')
#===============================================================================

bpy.types.ParticleSettings.bone = bpy.props.StringProperty(
bpy.types.ParticleSettings.boneName = bpy.props.StringProperty(
name='Bone',
description='',
default = ''
Expand All @@ -138,25 +136,49 @@ def to_script_file(self, file_handler, typescript_file_handler, kids, indent, ex
bpy.types.ParticleSettings.stiffness = bpy.props.FloatProperty(
name='Stiffness',
description='',
default = 0.3
default = 1.0,
min = 0.1,
max = 1.0
)

bpy.types.ParticleSettings.dissolveAnlge = bpy.props.FloatProperty(
name='Dissolve Angle',
description='Used to do a limited dissolve to remove some vertices',
default = 1.0,
min = 0.1,
max = 1.0
)

bpy.types.ParticleSettings.baseColor = bpy.props.FloatVectorProperty(
name='Base Color',
description='Used to generate vertex colors randomly near this.',
subtype='COLOR',
default=[0.0,0.0,0.0]
)

#===============================================================================
class HairPanel(bpy.types.Panel):
bl_label = get_title()
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = 'particles'
bl_context = 'particle'

@classmethod
def poll(cls, context):
hair = context.world
#print(ob.data)
return ob is not None and isinstance(ob, bpy.types.ParticleSettings)

mesh = context.object
if mesh is None or len(mesh.particle_systems) == 0: return False

index = mesh.particle_systems.active_index
return mesh.particle_systems[index].settings.type == 'HAIR'

def draw(self, context):
ob = context.particle_settings
layout.prop(ob, 'bone')
layout = self.layout

mesh = context.object
index = mesh.particle_systems.active_index

layout.prop(ob, 'stiffness')
hair = mesh.particle_systems[index].settings
layout.prop(hair, 'boneName')
layout.prop(hair, 'stiffness')
layout.prop(hair, 'baseColor')

Expand Up @@ -188,7 +188,6 @@ def draw(self, context):
index = mesh.active_material_index
material = mesh.material_slots[index].material

scene = context.scene
box = layout.box()
box.prop(material, 'usePNG')
box.prop(material, 'longestSideSize')
Expand Down
Binary file modified QueuedInterpolation/Blender/towerOfBabel.5.3.zip
Binary file not shown.

0 comments on commit 519548e

Please sign in to comment.