forked from HTDerekLiu/BlenderToolbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate_pointCloud.py
58 lines (47 loc) · 2.08 KB
/
template_pointCloud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
sys.path.append('/Users/hsuehtil/Dropbox/BlenderToolbox/') # change this to your path to “path/to/BlenderToolbox/"
import BlenderToolBox as bt
import os, bpy, bmesh
import numpy as np
cwd = os.getcwd()
outputPath = os.path.join(cwd, './template_pointCloud.png') # make it abs path for windows
## initialize blender
imgRes_x = 720 # recommend > 1080 (UI: Scene > Output > Resolution X)
imgRes_y = 720 # recommend > 1080
numSamples = 200 # recommend > 200 for paper images
exposure = 1.5
bt.blenderInit(imgRes_x, imgRes_y, numSamples, exposure)
## read mesh (choose either readPLY or readOBJ)
meshPath = './meshes/spot_pt.ply'
location = (1.12, -0.14, 0) # (UI: click mesh > Transform > Location)
rotation = (90, 0, 227) # (UI: click mesh > Transform > Rotation)
scale = (1.5,1.5,1.5) # (UI: click mesh > Transform > Scale)
mesh = bt.readMesh(meshPath, location, rotation, scale)
## Draw points
RGBA = (144.0/255, 210.0/255, 236.0/255, 1)
ptColor = bt.colorObj(RGBA, 0.5, 1.3, 1.0, 0.0, 0.0)
ptSize = 0.014
bt.setMat_pointCloud(mesh, ptColor, ptSize)
## set invisible plane (shadow catcher)
bt.invisibleGround(shadowBrightness=0.9)
## set camera (recommend to change mesh instead of camera, unless you want to adjust the Elevation)
camLocation = (3, 0, 2)
lookAtLocation = (0,0,0.5)
focalLength = 45 # (UI: click camera > Object Data > Focal Length)
cam = bt.setCamera(camLocation, lookAtLocation, focalLength)
## set light
## Option1: Three Point Light System
# bt.setLight_threePoints(radius=4, height=10, intensity=1700, softness=6, keyLoc='left')
## Option2: simple sun light
lightAngle = (6, -30, -155)
strength = 2
shadowSoftness = 0.3
sun = bt.setLight_sun(lightAngle, strength, shadowSoftness)
## set ambient light
bt.setLight_ambient(color=(0.1,0.1,0.1,1))
## set gray shadow to completely white with a threshold (optional but recommended)
bt.shadowThreshold(alphaThreshold = 0.05, interpolationMode = 'CARDINAL')
## save blender file so that you can adjust parameters in the UI
bpy.ops.wm.save_mainfile(filepath=os.getcwd() + '/test.blend')
## save rendering
bt.renderImage(outputPath, cam)