Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_scene():
downsample = 2
camera = tc.Camera(
'pinhole',
res=(1500 // downsample, 600 // downsample),
fov=30,
origin=(0, 1, 20),
look_at=(0, 2, 0),
up=(0, 1, 0))
scene = tc.Scene()
with scene:
scene.set_camera(camera)
ground_tex = tc.Texture(
'image', filename=tc.get_asset_path('textures/paper.jpg'))
mesh = tc.Mesh(
'plane',
tc.SurfaceMaterial('pbr', diffuse_map=ground_tex),
translate=(0, 0, -5),
scale=10,
rotation=(90, 0, 0))
scene.add_mesh(mesh)
mesh = tc.Mesh(
'plane',
tc.SurfaceMaterial('pbr', diffuse_map=ground_tex),
translate=(0, 0, 0),
scale=10,
rotation=(0, 0, 0))
'pbr', diffuse=(1, 0, 0), specular=(0, 1, 0), glossiness=(100, 0, 0)),
]
with scene:
scene.set_camera(camera)
for i, mat in enumerate(materials):
scene.add_mesh(
tc.Mesh(
base_mesh,
mat,
translate=((i - (len(materials) - 1) / 2) * 3, 1.3, 0),
scale=1))
# Ground
tex = (((tc.Texture('perlin') + 1) * 6).zoom(
(0.6, 0.6, 0.6))).fract() * (1.0, 0.7, 0.4)
scene.add_mesh(
tc.Mesh(
'plane',
tc.SurfaceMaterial('pbr', diffuse_map=tex),
scale=200,
translate=(0, 0, 0),
rotation=(0, 0, 0)))
# Board
gradient = tc.Texture('uv', coeff_u=1, coeff_v=0)
scene.add_mesh(
tc.Mesh(
'plane',
tc.SurfaceMaterial(
scene = tc.Scene()
with scene:
scene.set_camera(camera)
taichi_tex = tc.Texture('taichi', scale=0.96)
mesh = tc.Mesh(
'plane',
tc.SurfaceMaterial('pbr', diffuse=(.1, .1, .1)),
translate=(0, 0, -0.05),
scale=10,
rotation=(90.3, 0, 0))
scene.add_mesh(mesh)
# Taichi Text
text = 1 - tc.Texture(
'text',
content='Taichi',
width=200,
height=200,
font_file=tc.get_asset_path('fonts/go/Go-Bold.ttf'),
size=50,
dx=0,
dy=0)
mesh = tc.Mesh(
'plane',
tc.SurfaceMaterial(
'transparent',
nested=tc.SurfaceMaterial('diffuse', color=(1, 1, 1)),
mask=text),
translate=(5.0, 2, 0.05),
scale=2,
material=material,
translate=(2, 0.3 * (i - 3), 0.2),
scale=(0.01, 0.10, 0.5)))
material = tc.SurfaceMaterial(
'diffuse', color=(0.3, 0.3, 0.3), roughness_map=tex.id, f0=1)
scene.add_mesh(
tc.Mesh(
'cube',
material=material,
translate=(0, 0, -1),
scale=(1.9, 0.9, 0.03)))
with tc.transform_scope(rotation=(0, 30, 0), translate=(0, 0, 0)):
scene.add_mesh(create_volumetric_block())
envmap_texture = tc.Texture(
'spherical_gradient',
inside_val=(10, 10, 10, 10),
outside_val=(1, 1, 1, 0),
angle=10,
sharpness=20)
envmap = tc.EnvironmentMap('base', texture=envmap_texture.id, res=(1024, 1024))
scene.set_environment_map(envmap)
return scene
scene = tc.Scene()
with scene:
scene.set_camera(camera)
tex = tc.Texture.create_taichi_wallpaper(20, rotation=0, scale=0.95) * 0.9
material = tc.SurfaceMaterial(
'microfacet', color=(1.0, 1, 0.8), roughness_map=tex.id, f0=1)
for i in range(-7, 5):
scene.add_mesh(
tc.Mesh(
'sphere',
material=material,
translate=(i, -i * 1.6, -math.sin(i * 0.1)),
scale=0.7))
envmap_texture = tc.Texture('sky', height=0.5, direction=0.3)
envmap_texture.show(res=(500, 500), post_processor=tc.post_process.LDRDisplay())
envmap = tc.EnvironmentMap('base', texture=envmap_texture.id, res=(1024, 1024))
scene.set_environment_map(envmap)
return scene
def create_taichi_text():
text = 1 - tc.Texture(
'text',
content='Taichi',
width=200,
height=200,
font_file=tc.get_asset_path('fonts/go/Go-Bold.ttf'),
size=50,
dx=0,
dy=0)
mesh = tc.Mesh(
'plane',
tc.SurfaceMaterial(
'transparent',
nested=tc.SurfaceMaterial('diffuse', color=(1, 1, 1)),
mask=text),
translate=(5.0, 2, 0.05),
scale=2,
scene = tc.Scene()
with scene:
scene.set_camera(camera)
text_tex = tc.Texture(
'image', filename=tc.get_asset_path('textures/graphic_design.png'))
for i in range(3):
with tc.transform_scope(
translate=(0, 0.101, 0), scale=(8, 4, 0.2), rotation=(-90, 0, 0)):
with tc.transform_scope(scale=1**i):
mesh = tc.create_volumetric_block(text_tex * 8, res=(512, 256, 4))
scene.add_mesh(mesh)
ground_tex = tc.Texture(
'image', filename=tc.get_asset_path('textures/metal.jpg'))
mesh = tc.Mesh(
'plane',
tc.SurfaceMaterial('pbr', diffuse_map=ground_tex),
translate=(0, 0, 0),
scale=10,
rotation=(0, 0, 0))
scene.add_mesh(mesh)
mesh = tc.Mesh(
'plane',
tc.SurfaceMaterial('emissive', color=(1, 1, 1)),
translate=(-10, 3, 5),
scale=1,
rotation=(0, 0, -90))
base_delta_t=1e-4,
gravity=(0, -10, 0),
pushing_force=0,
penalty=5e4,
rpic_damping=1,
cfl=0.5,)
levelset = mpm.create_levelset()
levelset.add_plane(tc.Vector(0, 1, 0), -0.445)
levelset.set_friction(-1)
mpm.set_levelset(levelset, False)
ratio = 0.5
rho = (400, 2000, 5000)
tex = tc.Texture('rect', bounds=(0.4, 0.1, 0.2)) * 20
mpm.add_particles(
type='von_mises',
density_tex=tex.id,
density=rho[0],
youngs_modulus=5e4,
poisson_ratio=0.4,
yield_stress=10)
period = 0.3
def frame_update(t, frame_dt):
id = floor(t / period)
if (id < 3 and 0 < t <= id * period + frame_dt):
mpm.add_particles(
type='rigid',
scene = tc.Scene()
with scene:
scene.set_camera(camera)
# Plane
scene.add_mesh(
tc.Mesh(
'plane',
tc.SurfaceMaterial('pbr', diffuse=(1, 1, 1.0)),
translate=(0, 0, 0),
scale=100,
rotation=(0, 0, 0)))
for i in range(8):
menger = 1 - tc.Texture("menger", limit=i)
scene.add_mesh(
tc.Mesh(
'plane',
tc.SurfaceMaterial(
'transparent',
mask=menger,
nested=tc.SurfaceMaterial(
'diffuse',
color=colorsys.hls_to_rgb(i * 0.1 + 0.3, 0.3, 1.0))),
translate=(i * 7 - 28, 3.5, -5),
scale=3,
rotation=(90, 0, 0)))
# Lights
scene.add_mesh(
tc.Mesh(
size=50,
dx=0,
dy=0)
mesh = tc.Mesh(
'plane',
tc.SurfaceMaterial(
'transparent',
nested=tc.SurfaceMaterial('emissive', color=(10, 10, 10)),
mask=text),
translate=(0.20, 3.3, 0),
scale=0.4,
rotation=(90, 0, 0))
scene.add_mesh(mesh)
with tc.transform_scope(translate=(0, 1, 0), rotation=(0, -20, 0)):
grid_tex = (1 - tc.Texture('rect', bounds=(0.8, 0.8, 1.0))).repeat(
5, 5, 1)
tex = tc.Texture(
'image', filename=tc.get_asset_path('textures/paper.jpg'))
material = tc.SurfaceMaterial(
'transparent',
nested=tc.SurfaceMaterial('reflective', color_map=tex),
mask=grid_tex)
for i in range(1):
mesh = tc.Mesh(
'plane',
material,
translate=(0, 0.4, -i * 0.3),
scale=(1, 1, 1.4),
rotation=(90, 0, 0))
scene.add_mesh(mesh)