4

Is there a way to import Sketchup scenes into Blender as cameras?

I can get the geometry into Blender without any problems; my issue is that I'd also like to bring along the scene viewpoint as a camera.

The data obtained from SketchUP API is like this:

mod = Sketchup.active_model
vue = mod.active_view
cam = vue.camera

cam.eye
> Point3d(240.719, -236.069, 102.276)

cam.target
> Point3d(-285.372, 553.004, -82.0446)

cam.fov
> 35.0

What is a convenient way to convert this into a new camera?

zeffii
  • 39,634
  • 9
  • 103
  • 186
jkjenner
  • 201
  • 1
  • 3

1 Answers1

1

If that's all sketchup gives, then it's a little awkward -- but I think still doable. Maybe something like this. You will have to 'tame' the dimensions yourself.

import bpy

# Data from Sketchup.
cam = {
    "eye": (240.719, -236.069, 102.276),
    "target": (-285.372, 553.004, -82.0446),
    "fov": 35.0,
}

# Create empty to target.
bpy.ops.object.empty_add(location=cam["target"])
target = bpy.context.object

# Create camera.
bpy.ops.object.camera_add(location=cam["eye"])
bpy.context.object.data.lens = cam["fov"]

# Configure camera to track the empty.
constraint = bpy.context.object.constraints.new("TRACK_TO")
constraint.target = target
constraint.track_axis = "TRACK_NEGATIVE_Z"
constraint.up_axis = "UP_Y"
Aldrik
  • 9,720
  • 22
  • 56
zeffii
  • 39,634
  • 9
  • 103
  • 186
  • Then you can apply the constraint (Apply Visual Transforms) and delete both it and the empty to avoid clutter. – wchargin Oct 22 '13 at 03:18