Message 1 of 3
Pan, orbit, zoom, camera in Fusion 360 api
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I get 6 numbers from a 3D mouse.
(x, y, z, yaw, roll, pitch)
How do I change the camera coordinates in the python fusion 360 api in order to do pan, orbit, zoom operations?
My code addin python code bellow:
import adsk.core, adsk.fusion, traceback, math, time
import os, sys
from . import commands
from .lib import fusion360utils as futil
install\_ = sys.path\[0\] +'\\Python\\python.exe -m pip install pyserial'
os.system('cmd /c "' + install\_ + '"')
import serial
ser = serial.Serial('COM8', 9600)
def move_camera(app, view):
while(True):
try:
camera = view.camera
target = camera.target # Use current camera target
up = adsk.core.Vector3D.create(0, 1, 0)
data = ser.readline().decode('utf-8').strip().split(' ')
if len(data) == 6:
\# x y z yaw pitch roll
dist = camera.target.distanceTo(camera.eye)
start_eye = camera.eye
\# Pan
new_target = adsk.core.Point3D.create(target.x, target.y, target.z)
camera.target = new_target
\# Orbit
new_eye = adsk.core.Point3D.create(dist \* math.cos((math.pi\*2) \* data\[3\]), dist \* math.sin((math.pi\*2) \* data\[4\]), dist \* math.sin((math.pi\*2) \* data\[5\]))
camera.eye = new_eye
#zoom
zoom_factor = float(data\[0\])
new_target = adsk.core.Point3D.create(target.x \* zoom_factor, target.y \* zoom_factor, target.z \* zoom_factor)
camera.target = new_target
camera.upVector = up
camera.isSmoothTransition = True
view.camera = camera
else:
break
adsk.doEvents()
view.refresh()
time.sleep(0.005)
except:
ui = app.userInterface
if ui:
ui.messageBox('Failed:\\n{}'.format(traceback.format_exc()))
stop()
def run(context):
try:
\# This will run the start function in each of your commands as defined in commands/\__init_\_.py
commands.start()
main()
except:
futil.handle_error('run')
def stop(context):
try:
\# Remove all of the event handlers your app has created
futil.clear_handlers()
commands.stop()
except:
futil.handle_error('stop')
def main():
ui = None
try:
app = adsk.core.Application.get()
move_camera(app, app.activeViewport)
except:
ui = app.userInterface
if ui:
ui.messageBox('Failed:\\n{}'.format(traceback.format_exc()))