示例#1
0
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, './demo_facePoints.png')  # make it abs path for windows

## initialize blender
imgRes_x = 480
imgRes_y = 480
numSamples = 100
exposure = 1.5
bt.blenderInit(imgRes_x, imgRes_y, numSamples, exposure)

## read mesh (choose either readPLY or readOBJ)
meshPath = '../meshes/spot.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)

## set shading (uncomment one of them)
bpy.ops.object.shade_smooth()

## subdivision
bt.subdivision(mesh, level=0)

# # set material (single color first)
示例#2
0
import BlenderToolBox as bt

'''
RENDER A MESH STEP-BY-STEP:
1. copy "template_lazy.py" to your preferred local folder
2. In "template_lazy.py":
    - change "mesh_path" to your desired mesh path
    - change to sys.path.append('path/to/BlenderToolBox/cycles/')
3. run "blender --background --python template_lazy.py" in terminal, then terminate the code when it starts rendering. This step outputs a "test.blend"
4. open "test.blend" with your blender software
5. in blender UI, adjust:
    - "mesh_location", "mesh_rotation", "mesh_scale" of the mesh
6. type in the adjusted mesh parameters from UI to "template_lazy.py"
7. run "blender --background --python template_lazy.py" again (wait a couple minutes) to output your final image
'''

arguments = {
  "output_path": "./template_lazy.png",
  "image_resolution": [720, 720], # recommend >1080 for paper figures
  "number_of_samples": 200, # recommend >200 for paper figures
  "mesh_path": "./meshes/spot.ply", # either .ply or .obj
  "mesh_position": (1.12, -0.14, 0), # UI: click mesh > Transform > Location
  "mesh_rotation": (90, 0, 227), # UI: click mesh > Transform > Rotation
  "mesh_scale": (1.5,1.5,1.5), # UI: click mesh > Transform > Scale
  "shading": "smooth", # either "flat" or "smooth"
  "subdivision_iteration": 0, # integer
  "mesh_RGB": [144.0/255, 210.0/255, 236.0/255], # mesh RGB
  "light_angle": (6, -30, -155) # UI: click Sun > Transform > Rotation
}
bt.render_mesh_default(arguments)
示例#3
0
                )  # 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,
                          './demo_glass.png')  # make it abs path for windows

## initialize blender
imgRes_x = 480
imgRes_y = 480
numSamples = 100
exposure = 1.5
bt.blenderInit(imgRes_x, imgRes_y, numSamples, exposure)

## read mesh (choose either readPLY or readOBJ)
meshPath = '../meshes/spot.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)

## set shading (uncomment one of them)
bpy.ops.object.shade_smooth()

## subdivision
bt.subdivision(mesh, level=2)

# # set material (single color first)
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, './demo_drawLines.png')  # make it abs path for windows

## initialize blender
imgRes_x = 480
imgRes_y = 480
numSamples = 100
exposure = 1.5
bt.blenderInit(imgRes_x, imgRes_y, numSamples, exposure)

# create original local frame
orig = np.array([0., -0.4, 0.1])
lineVec = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

p1List = np.tile(orig[None, :], (lineVec.shape[0], 1))
p2List = p1List + lineVec
colorList = np.array([[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 1]])
radius = 0.1
bt.drawLines(p1List, p2List, radius, colorList)

## 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)
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, './demo_faceScalars.png') # make it abs path for windows

## initialize blender
imgRes_x = 480 
imgRes_y = 480 
numSamples = 100 
exposure = 1.5 
bt.blenderInit(imgRes_x, imgRes_y, numSamples, exposure)

## read mesh from numpy array
location = (0,0,0.67)
rotation = (0,0,0) 
scale = (.5,.5,.5)

V = np.array([[1,1,1],[-1,1,-1],[-1,-1,1],[1,-1,-1]], dtype=np.float32) # vertex list
F = np.array([[0,1,2],[0,2,3],[0,3,1],[2,1,3]], dtype=np.int32) # face list
mesh = bt.readNumpyMesh(V,F,location,rotation,scale)

face_scalars = np.array([0.,1.,2.,3.]) # face scalar list
color_type = 'face'
color_map = 'red'
mesh = bt.setMeshScalars(mesh, face_scalars, color_map, color_type)

## set shading (uncomment one of them)
示例#6
0
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,
                          './demo_poop.png')  # make it abs path for windows

## initialize blender
imgRes_x = 480
imgRes_y = 480
numSamples = 100
exposure = 1.5
bt.blenderInit(imgRes_x, imgRes_y, numSamples, exposure)

## read mesh (choose either readPLY or readOBJ)
meshPath = '../meshes/spot.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)

## set shading (uncomment one of them)
bpy.ops.object.shade_smooth()

## subdivision
bt.subdivision(mesh, level=2)

# # set material (TODO: this has some new issue due to new version of Blender)
                )  # 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, './demo_pointCloudScalars.png')  # make it abs path for windows

## initialize blender
imgRes_x = 480
imgRes_y = 480
numSamples = 100
exposure = 1.5
bt.blenderInit(imgRes_x, imgRes_y, numSamples, exposure)

## read mesh
location = (0, 0, 0.67)
rotation = (0, 0, 0)
scale = (.5, .5, .5)
P = np.array([[1, 1, 1], [-1, 1, -1], [-1, -1, 1], [1, -1, -1]],
             dtype=np.float32)  # point location
mesh = bt.readNumpyPoints(P, location, rotation, scale)

## add color to point cloud
PC = np.array([0., 1., 2., 3.])  # point colors
color_map = 'default'
mesh = bt.setPointScalars(mesh, PC, color_map)

## set material ptColor = (vertex_RGBA, H, S, V, Bright, Contrast)
示例#8
0
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, './demo_isolineNumpy.png') # make it abs path for windows

## initialize blender
imgRes_x = 480 
imgRes_y = 480 
numSamples = 100 
exposure = 1.5 
bt.blenderInit(imgRes_x, imgRes_y, numSamples, exposure)

## read mesh from numpy array
location = (0,0,0.67) 
rotation = (0,0,0) 
scale = (.5,.5,.5)
V = np.array([[1,1,1],[-1,1,-1],[-1,-1,1],[1,-1,-1]], dtype=np.float32) # vertex list
F = np.array([[0,1,2],[0,2,3],[0,3,1],[2,1,3]], dtype=np.int32) # face list
mesh = bt.readNumpyMesh(V,F,location,rotation,scale)

vertex_scalars = np.array([0.,1.,2.,3.])
mesh = bt.vertexScalarToUV(mesh, vertex_scalars)

## set shading (uncomment one of them)
# bpy.ops.object.shade_smooth() 

## subdivision
示例#9
0
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,
                          './demo_muscle.png')  # make it abs path for windows

## initialize blender
imgRes_x = 480
imgRes_y = 480
numSamples = 100
exposure = 1.5
bt.blenderInit(imgRes_x, imgRes_y, numSamples, exposure)

## read mesh (choose either readPLY or readOBJ)
meshPath = '../meshes/spot.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)

## set shading (uncomment one of them)
bpy.ops.object.shade_smooth()

## subdivision
bt.subdivision(mesh, level=2)

# # set material
示例#10
0
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, './demo_monotone.png')  # make it abs path for windows

## initialize blender
imgRes_x = 480
imgRes_y = 480
numSamples = 100
exposure = 1.5
bt.blenderInit(imgRes_x, imgRes_y, numSamples, exposure)

## read mesh (choose either readPLY or readOBJ)
meshPath = '../meshes/spot.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)

## set shading (uncomment one of them)
bpy.ops.object.shade_smooth()

## subdivision
bt.subdivision(mesh, level=2)

# # set material
示例#11
0
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()

outputHeader = os.path.join(
    cwd, './demo_circCamera_')  # make it abs path for windows

## initialize blender
imgRes_x = 480
imgRes_y = 480
numSamples = 100
exposure = 1.5
bt.blenderInit(imgRes_x, imgRes_y, numSamples, exposure)

## read mesh (choose either readPLY or readOBJ)
meshPath = '../meshes/spot.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)

## set shading (uncomment one of them)
bpy.ops.object.shade_smooth()

## subdivision
bt.subdivision(mesh, level=2)

# # set material
示例#12
0
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, './demo_edgeWire.png')  # make it abs path for windows

## initialize blender
imgRes_x = 480
imgRes_y = 480
numSamples = 100
exposure = 1.5
bt.blenderInit(imgRes_x, imgRes_y, numSamples, exposure)

## read mesh (choose either readPLY or readOBJ)
meshPath = '../meshes/spot.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)

## set shading (uncomment one of them)
bpy.ops.object.shade_smooth()

## subdivision
bt.subdivision(mesh, level=0)

radius = 0.0015