def gltf_ddd(): sphere1 = ddd.sphere(r=1.0, name="Sphere1").translate([0, 0, -2]) sphere2 = ddd.sphere(r=2.0, name="Sphere2").translate([5, 5, 5]) sphere1.append(sphere2) sphere1.extra['testSphere1'] = 'MyTest' sphere2.extra.update(test_metadata) sphere2.extra['test_obj'] = test_metadata root = ddd.group([sphere1], name="Spheres Root") scene1 = ddd.group([root], name="Scene") scene1.extra['test'] = test_metadata scene1.dump() scene1.save("gltf-hierarchy-ddd.glb") scene1.show()
def pipeline_start(pipeline, root): """ Draws several catenary cables. """ ddd.mats.traffic_signs = ddd.material(name="TrafficSigns", color="#ffffff", #color="#e01010", texture_path=ddd.DATA_DIR + "/materials/traffic-signs-es/traffic_signs_es_0.png", atlas_path=ddd.DATA_DIR + "/materials/traffic-signs-es/traffic_signs_es_0.plist", extra={'ddd:texture:resize': 2048}) items = ddd.group3() # Cube with logo fig = ddd.box() fig = fig.material(ddd.mats.logo) fig = ddd.uv.map_cubic(fig) items.append(fig) # Sphere with logo fig = ddd.sphere() fig = fig.material(ddd.mats.logo) #fig = fig.merge_vertices() #fig = fig.smooth(math.pi*2) fig = ddd.uv.map_spherical(fig) fig = fig.translate([0, 0, 2]) items.append(fig) # Cube fig = ddd.box() fig = fig.material(ddd.mats.traffic_signs) fig = ddd.uv.map_cubic(fig) #fig.show() #items.append(fig) fig = TextureAtlasUtils().create_sprite_rect(ddd.mats.traffic_signs) #fig.show() #items.append(fig) fig = TextureAtlasUtils().create_sprite_from_atlas(ddd.mats.traffic_signs, "ES_P6.png") #fig.show() #items.append(fig) ''' ddd.mats.roadmarks = ddd.material(name="Roadmarks", color='#e8e8e8', texture_path=ddd.DATA_DIR + "/materials/road-marks-es/TexturesCom_Atlas_RoadMarkings2_White_1K_albedo_with_alpha.png", atlas_path=ddd.DATA_DIR + "/materials/road-marks-es/RoadMarkings2.plist") fig = TextureAtlasUtils().create_sprite_from_atlas(ddd.mats.roadmarks, "give_way") fig.show() ''' items = ddd.align.grid(items, width=4) items.append(ddd.helper.all(size=40.0, center=[5, 5, 0]).twosided()) root.append(items)
def treetop(r=1.75, flatness=0.3, subdivisions=1): treetop = ddd.sphere(center=ddd.point([random.uniform(-r * 0.2, r * 0.2), random.uniform(-r * 0.2, r * 0.2), 0]), r=r, subdivisions=subdivisions) treetop = treetop.scale([1.0, 1.0, (1.0 - flatness) * random.uniform(0.85, 1.15)]) treetop = treetop.smooth(math.pi * 2 / 3) treetop = ddd.uv.map_spherical(treetop, scale=[3, 2]) treetop = filters.noise_random(treetop, scale=0.25) treetop.extra['ddd:collider'] = False treetop.name = "Treetop" return treetop
def sculpture(d=1.0, height=4.0): """ An urban sculpture, sitting centered on the XY plane. """ #pedestal = ddd.cube(d=d / 2.0) #pedestal = ddd.uv.map_cubic(pedestal) item = ddd.sphere(r=1, subdivisions=2, name="Sculpture") item = item.scale([d, d, height / 2]) item = filters.noise_random(item, scale=0.2) item = item.translate([0, 0, height / 2]) # + d item = ddd.uv.map_spherical(item) return item
def rock(bounds=(1, 1, 1)): """ Final size will be bounds * 2. """ obj = ddd.sphere(subdivisions=1) raise_factor = random.uniform(-0.15, 0.35) obj = obj.translate([0, 0, raise_factor]) obj = obj.subtract(ddd.box([-2, -2, 0, 2, 2, -2])) obj = obj.scale(bounds) noise_scale = min(bounds) * 0.25 obj = filters.noise_random(obj, scale=noise_scale) obj = obj.translate([0, 0, -0.2]) obj = obj.material(ddd.mats.rock) #obj.mesh = obj.mesh.smoothed(angle=0) obj = ddd.uv.map_cubic(obj) return obj
def fountain(r=1.5): # Base base = ddd.disc(r=r, resolution=2).extrude(0.30).material(ddd.mats.stone) base = ddd.uv.map_cylindrical(base) # Fountain fountain = ddd.sphere(r=r, subdivisions=1).subtract(ddd.cube(d=r * 1.2)).subtract(ddd.sphere(r=r - 0.2, subdivisions=1)) fountain = fountain.translate([0, 0, 1.2]) # TODO: align fountain = fountain.material(ddd.mats.stone) fountain = ddd.uv.map_spherical(fountain) #.subtract(base) # Water water = ddd.disc(r=r-0.2, resolution=2).triangulate().translate([0, 0, 1.1]).material(ddd.mats.water) water.extra['ddd:collider'] = False water.extra['ddd:occluder'] = False water.extra['ddd:shadows'] = False item = ddd.group([base, fountain, water]) return item
def tree_fir(height=20, r=0.2): """ (Abeto) They are large trees, reaching heights of 10–80 m (33–262 ft) tall with trunk diameters of 0.5–4 m (1 ft 8 in–13 ft 1 in) when mature. """ top_r = (height / 4) * random.uniform(0.9, 1.1) top_base_h = height / 10 section = ddd.regularpolygon(sides=5, r=r).extrude_step(ddd.regularpolygon(sides=5, r=r*0.1), height) section = ddd.uv.map_cylindrical(section) section = section.material(ddd.mats.bark) #pol = ddd.regularpolygon(sides=9, r=1) #layer = pol.extrude_step(pol.scale(0.5), -0.4, base=False, cap=False) #layer = layer.extrude_step(ddd.point(), -0.2, cap=False) #layer = layer.material(ddd.mats.treetop).twosided().translate([0, 0, 0.6]) layer = ddd.sphere(subdivisions=1).scale([1, 1, 0.5]) #layer = ddd.uv.map_spherical(layer) layer = layer.vertex_func(lambda x, y, z, i: [x, y, z + ((x*x + y*y) * 0.7)]) layer = layer.material(ddd.mats.treetop) numlayers = 8 leaves = ddd.group3(name="Fir leaves group") for i in range(numlayers): lh = top_base_h + ((height - top_base_h) / (numlayers - 1)) * i lobj = layer.copy(name="Fir leaves %d" % i) lscale = top_r * (1 / numlayers) * (numlayers - i) lobj = layer.scale([lscale, lscale, lscale]).translate([0, 0, lh]) #lobj = ddd.uv.map_cubic(lobj) leaves.append(lobj) leaves = leaves.combine() leaves = leaves.merge_vertices() #leaves = leaves.smooth(math.pi*2) leaves = ddd.uv.map_spherical(leaves, scale=[4, 8], split=False) obj = ddd.group3([section.combine(), leaves], name="Fir") #obj.show() return obj
def lamp_ball(r=0.25): lamp = ddd.sphere(r=r, subdivisions=1) # .scale([1.0, 1.0, 1.2]) lamp = lamp.material(ddd.mats.lightbulb) return lamp
def crane_vertical(): """ Large vertical crane (such as those seen in cargo ports). Inspired by: https://commons.wikimedia.org/wiki/File:Port_crane_of_Mammoet,_Schiedam-8054.jpg """ base_width = 7 base_length = 6 # Piers pier_height = 2.0 pier_width = 1.5 pier_length = base_length + 2 pier = ddd.rect( [-pier_width / 2, -pier_length / 2, pier_width / 2, pier_length / 2], name="Crane Pier") pier = pier.extrude(pier_height).material(ddd.mats.metal_paint_red) pier = ddd.uv.map_cubic(pier) pier_l = pier.translate([-base_width * (2 / 6), 0, 0]) pier_r = pier.translate([base_width * (2 / 6), 0, 0]) piers = ddd.group3([pier_l, pier_r], name="Crane Piers") # Base base_height = 1.5 base = ddd.rect([0, 0, base_width, base_length], name="Crane Base").recenter() base = base.extrude(base_height).translate([0, 0, pier_height]) base = base.material(ddd.mats.cement) base = ddd.uv.map_cubic(base) # Base Tower column_height = 8 column_radius_base = base_width * 0.85 * 0.5 column_radius = column_radius_base * 0.5 column_shape_base = ddd.regularpolygon(4, column_radius_base) column_shape_middle = ddd.regularpolygon(12, column_radius) column = column_shape_base.extrude_step(column_shape_middle, 1, base=False) column = column.extrude_step(column_shape_middle, column_height - 1, cap=False) column = column.translate([0, 0, pier_height + base_height ]).material(ddd.mats.metal_paint_red) column = ddd.uv.map_cubic(column) column.name = "Crane column" # Platform and railing platform_radius = column_radius + 0.85 platform_base_height = pier_height + base_height + column_height - 2.0 platform_shape = ddd.point(name="Crane platform").buffer( platform_radius, cap_style=ddd.CAP_ROUND) platform = platform_shape.triangulate(twosided=True) platform = platform.material(ddd.mats.metallic_grid) platform_fence = platform_shape.outline().extrude(1.2).material( ddd.mats.fence) platform = ddd.group([platform, platform_fence], name="Crane platform") platform = ddd.uv.map_cylindrical(platform) platform = platform.translate([0, 0, platform_base_height]) # WeightBlock block_width = base_width * 0.6 block_length = base_length * 1.25 block_base_height = pier_height + base_height + column_height block_height = 2.2 block = ddd.rect([-block_width / 2, 0, block_width / 2, block_length], name="Crane Weight") block = block.extrude(block_height).translate([0, -2.5, block_base_height ]).material(ddd.mats.cement) block = ddd.uv.map_cubic(block) # Cabin cabin_width = block_width * 0.6 cabin_length = 3 cabin_height = block_height cabin_shape = ddd.rect( [-block_width * 0.5, 0, block_width * 0.5, cabin_length]) cabin_shape_top = ddd.rect( [-block_width * 0.5, 1, block_width * 0.5, cabin_length]) cabin = cabin_shape.extrude_step(cabin_shape, 1) cabin = cabin.extrude_step(cabin_shape_top, cabin_height - 1) cabin = cabin.extrude_step(cabin_shape_top.buffer(-0.4), 0.3) cabin = cabin.material(ddd.mats.metal_paint_yellow) cabin = cabin.translate([0, -2.5 - cabin_length, block_base_height]) cabin = ddd.uv.map_cubic(cabin) mainsupport_width = 2 mainsupport_skew = 2 mainsupport_height = 10 mainsupport_base_height = block_base_height + block_height mainsupport = ddd.rect([0, 0, mainsupport_width, mainsupport_width], name="Main Support").recenter() mainsupport = mainsupport.extrude_step(mainsupport.translate( [0, -mainsupport_skew]), mainsupport_height, base=False) mainsupport = mainsupport.material(ddd.mats.metal_paint_red) mainsupport = mainsupport.translate([0, 0, mainsupport_base_height]) mainsupport = ddd.uv.map_cubic(mainsupport) secsupport_width = 1.5 secsupport_skew = 11 secsupport_height = 18 secsupport_base_height = block_base_height + block_height secsupport = ddd.rect([0, 0, secsupport_width, secsupport_width], name="Sec Support").recenter() secsupport = secsupport.extrude_step(secsupport.scale( [0.8, 0.7]).translate([0, -secsupport_skew]), secsupport_height, base=False) secsupport = secsupport.material(ddd.mats.metal_paint_red) secsupport = secsupport.translate([0, -1.5, secsupport_base_height]) secsupport = ddd.uv.map_cubic(secsupport) maincable1 = cable( [-block_width * 0.4, block_length - 3, mainsupport_base_height], [ -mainsupport_width * 0.2, -mainsupport_skew, mainsupport_base_height + mainsupport_height - 0.2 ]) maincable1 = maincable1.material(ddd.mats.cable_metal) maincable2 = cable( [block_width * 0.4, block_length - 3, mainsupport_base_height], [ mainsupport_width * 0.2, -mainsupport_skew, mainsupport_base_height + mainsupport_height - 0.2 ]) maincable2 = maincable2.material(ddd.mats.cable_metal) seccable1 = cable( [0, -mainsupport_skew, mainsupport_base_height + mainsupport_height], [ 0, -1.5 - secsupport_skew, mainsupport_base_height + secsupport_height - 0.2 ]) seccable1 = seccable1.material(ddd.mats.cable_metal) # Drag cable dragcable_length = 20 dragcable_point = [ 0, -1.5 - secsupport_skew, mainsupport_base_height + secsupport_height - 0.2 ] dragcable_endpoint = [ 0, -1.5 - secsupport_skew, mainsupport_base_height + secsupport_height - 0.2 - dragcable_length ] dragcable = cable(dragcable_endpoint, dragcable_point) dragcable = dragcable.material(ddd.mats.cable_metal) # Pulley block pulley_block_width = 0.5 pulley_block_thick = 0.3 pulley_block_height = 0.8 pulley_block_profile = ddd.polygon( [[-pulley_block_width * 0.25, 0], [pulley_block_width * 0.25, 0], [pulley_block_width / 2, pulley_block_height], [-pulley_block_width / 2, pulley_block_height]], name="Pulley block") pulley_block_profile = pulley_block_profile.buffer( 0.2, resolution=3, join_style=ddd.JOIN_ROUND) pulley_block = pulley_block_profile.extrude(pulley_block_thick).translate( [0, 0, -pulley_block_thick / 2]) pulley_block = pulley_block.rotate(ddd.ROT_FLOOR_TO_FRONT).rotate( ddd.ROT_TOP_CW) pulley_block = pulley_block.material(ddd.mats.metal_paint_yellow) pulley_block = ddd.uv.map_cubic(pulley_block) pulley_block = pulley_block.translate(dragcable_endpoint) # Hook hook_radius = 0.6 hook_radius_inner = 0.35 hook = ddd.sphere(r=hook_radius, name="Hook") hook = hook.scale([0.2, 1.0, 1.0]) hole = ddd.point().buffer(hook_radius_inner, resolution=3, cap_style=ddd.CAP_ROUND).extrude(4.0).translate( [0, 0, -2]) hole = hole.rotate(ddd.ROT_FLOOR_TO_FRONT).rotate(ddd.ROT_TOP_CW) hook = hook.subtract(hole) hook = hook.material(ddd.mats.steel) #hook = ddd.uv.map_cubic(hook) hook = hook.translate(dragcable_endpoint) item = ddd.group3([ piers, base, column, platform, block, cabin, mainsupport, maincable1, maincable2, secsupport, seccable1, dragcable, pulley_block, hook ], name="Crane Vertical") return item