Skip to content

Commit efa8ebc

Browse files
committed
add orthographic camera
1 parent e479187 commit efa8ebc

File tree

5 files changed

+8839
-12
lines changed

5 files changed

+8839
-12
lines changed

BlenderToolbox/cycles/demo_orthocameraFromMat.py renamed to BlenderToolbox/cycles/demo_orthocamera.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
import numpy as np
2121

22-
outputPath = './results/demo_orthocameraFromMat.png'
22+
outputPath = './results/demo_orthocamera.png'
2323

2424
# # init blender
2525
imgRes_x = 720 # increase this for paper figures
2626
imgRes_y = 720 # increase this for paper figures
27-
numSamples = 50 # usually increase it to >200 for paper figures
27+
numSamples = 20 # usually increase it to >200 for paper figures
2828
exposure = 1.0
2929
blenderInit(imgRes_x, imgRes_y, numSamples, exposure)
3030

@@ -56,19 +56,13 @@
5656
invisibleGround(groundCenter, groundSize, shadowDarkeness)
5757

5858
# # set camera
59-
# camLocation = (1.9,2,2.2)
60-
# lookAtLocation = (0,0,0.5)
61-
# focalLength = 45
62-
# cam = setCamera(camLocation, lookAtLocation, focalLength)
63-
59+
camLocation = (1.9,2,2.2)
60+
lookAtLocation = (0,0,0.5)
6461
left = -1.0
6562
right = 1.0
6663
top = 1.0
67-
bottom = 1.0
68-
69-
bpy.context.object.data.type = 'ORTHO'
70-
bpy.context.object.data.ortho_scale = 2
71-
64+
bottom = -1.0
65+
cam = setCamera_orthographic(camLocation, lookAtLocation, top, bottom, left, right)
7266

7367
# # set sunlight
7468
lightAngle = (-15,-34,-155)

BlenderToolbox/cycles/include.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from utils.recalculateNormals import *
2626
from utils.selectOBJ import *
2727
from utils.setCamera import *
28+
from utils.setCamera_orthographic import *
2829
from utils.setCameraPath import *
2930
from utils.setLight_sun import *
3031
from utils.setLight_ambient import *
Loading
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2020 The TensorFlow Authors, Derek Liu
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import bpy
16+
import math
17+
import mathutils
18+
from utils.lookAt import *
19+
20+
def setCamera_orthographic(camLocation, lookAtLocation, top, bottom, left, right):
21+
# scale the resolution y using resolution x
22+
assert(abs(left-right)>0)
23+
assert(abs(top-bottom)>0)
24+
aspectRatio = abs(right - left)*1.0 / abs(top - bottom)
25+
bpy.context.scene.render.resolution_y = bpy.context.scene.render.resolution_x / aspectRatio
26+
27+
bpy.ops.object.camera_add(location = camLocation)
28+
cam = bpy.context.object
29+
bpy.context.object.data.type = 'ORTHO'
30+
cam.data.ortho_scale = abs(left-right)
31+
loc = mathutils.Vector(lookAtLocation)
32+
lookAt(cam, loc)
33+
return cam

0 commit comments

Comments
 (0)