Skip to main content
deleted 13 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

Another driver approach

Using the methods outlined in Left / Right Test Purely checks to see if camera is on left or right of an object, where local z is up and y is forward.

enter image description here
Result where shapekey is a simple 2x z scaling.

Copy the script below, paste in text editor and run script to register the driver.

import bpy

def drive_shapekey(name):
    cam = bpy.context.scene.camera
    obj = bpy.context.scene.objects.get(name)
    if not (cam and obj):
        print("Driver Error")
        return 0
    mw = obj.matrix_world
    loc = mw.translation.normalized()
    left = mw.to_3x3().transposed()[0] # normal to the plane 
    left = -left if left.x < 0 else left # flip claus    
    d = left.dot((cam.matrix_world.translation - loc).normalized())

    return abs(d)
    
bpy.app.driver_namespace["ds"] =  drive_shapekey

In the shape key of the object you wish to drive, type in

#ds("Cube")

the hash "#" signals to blender that this is a python driver expression.

enter image description here

to drive that shapekey based on the left or right-ness of the object named "Cube" to the scene's camera.

Another driver approach

Using the methods outlined in Left / Right Test Purely checks to see if camera is on left or right of an object, where local z is up and y is forward.

enter image description here
Result where shapekey is a simple 2x z scaling.

Copy the script below, paste in text editor and run script to register the driver.

import bpy

def drive_shapekey(name):
    cam = bpy.context.scene.camera
    obj = bpy.context.scene.objects.get(name)
    if not (cam and obj):
        print("Driver Error")
        return 0
    mw = obj.matrix_world
    loc = mw.translation.normalized()
    left = mw.to_3x3().transposed()[0] # normal to the plane 
    left = -left if left.x < 0 else left # flip claus    
    d = left.dot((cam.matrix_world.translation - loc).normalized())

    return abs(d)
    
bpy.app.driver_namespace["ds"] =  drive_shapekey

In the shape key of the object you wish to drive, type in

#ds("Cube")

the hash "#" signals to blender that this is a python driver expression.

enter image description here

to drive that shapekey based on the left or right-ness of the object named "Cube" to the scene's camera.

Another driver approach

Using the methods outlined in Left / Right Test Purely checks to see if camera is on left or right of an object, where local z is up and y is forward.

enter image description here
Result where shapekey is a simple 2x z scaling.

Copy the script below, paste in text editor and run script to register the driver.

import bpy

def drive_shapekey(name):
    cam = bpy.context.scene.camera
    obj = bpy.context.scene.objects.get(name)
    if not (cam and obj):
        print("Driver Error")
        return 0
    mw = obj.matrix_world
    loc = mw.translation
    left = mw.to_3x3().transposed()[0] # normal to the plane 
    left = -left if left.x < 0 else left # flip claus    
    d = left.dot((cam.matrix_world.translation - loc).normalized())

    return abs(d)
    
bpy.app.driver_namespace["ds"] =  drive_shapekey

In the shape key of the object you wish to drive, type in

#ds("Cube")

the hash "#" signals to blender that this is a python driver expression.

enter image description here

to drive that shapekey based on the left or right-ness of the object named "Cube" to the scene's camera.

Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

Another driver approach

Using the methods outlined in Left / Right Test Purely checks to see if camera is on left or right of an object, where local z is up and y is forward.

enter image description here
Result where shapekey is a simple 2x z scaling.

Copy the script below, paste in text editor and run script to register the driver.

import bpy

def drive_shapekey(name):
    cam = bpy.context.scene.camera
    obj = bpy.context.scene.objects.get(name)
    if not (cam and obj):
        print("Driver Error")
        return 0
    mw = obj.matrix_world
    loc = mw.translation.normalized()
    left = mw.to_3x3().transposed()[0] # normal to the plane 
    left = -left if left.x < 0 else left # flip claus    
    d = left.dot((cam.matrix_world.translation - loc).normalized())

    return abs(d)
    
bpy.app.driver_namespace["ds"] =  drive_shapekey

In the shape key of the object you wish to drive, type in

#ds("Cube")

the hash "#" signals to blender that this is a python driver expression.

enter image description here

to drive that shapekey based on the left or right-ness of the object named "Cube" to the scene's camera.