def sculpture_text(text, d=1.0, height=3.0, vertical=False): """ An urban sculpture, sitting centered on the XY plane. """ #pedestal = ddd.cube(d=d / 2.0) #pedestal = ddd.uv.map_cubic(pedestal) logger.debug("Generating text for: %s", text) item = Text3D.quick_text(text) item = item.extrude(0.5).material(ddd.mats.bronze).recenter() if vertical: item = item.rotate(ddd.ROT_TOP_CCW) item = item.rotate(ddd.ROT_FLOOR_TO_FRONT) item = filters.noise_random(item, scale=0.03) bounds = item.bounds() item = item.scale([d, d, (height) / (bounds[1][2] - bounds[0][2])]).recenter(onplane=True) #item = item.translate([0, 0, d]) item = ddd.uv.map_cubic(item) #item = ddd.group([pedestal, item], name="Urban sculpture: %s" % text) item.name = "Urban sculpture: %s" % text item = item.combine() return item
def generate_item_3d_historic_archaeological_site(self, item_2d): # TODO: Move the actual site generation, given an area, to sketchy coords = item_2d.centroid().geom.coords[0] if item_2d.geom.type in ("Point", "LineString"): points = item_2d.buffer(5.0).random_points(12) else: points = item_2d.random_points(12) line1 = ddd.line(points[0:2]) line2 = ddd.line(points[2:5]) line3 = ddd.line(points[5:]) geomobj = ddd.group2([line1, line2, line3]).buffer(0.5).union() #geomobj = filters.noise_random(geomobj, scale=0.075).clean().remove_z() #geomobj.show() item_3d = geomobj.extrude(0.8) #item_3d.copy_from(item_2d) item_3d = filters.noise_random(item_3d, scale=0.3) item_3d = item_3d.material(ddd.mats.tiles_stones_veg_sparse) item_3d = ddd.uv.map_cubic(item_3d) # Dont translate ir rotate, item is already in world space (built from item_2d). #item_3d = item_3d.rotate([0, 0, item_2d.get('ddd:angle', 0) - math.pi / 2]) #item_3d = item_3d.translate([coords[0], coords[1], 0.0]) # mat_bronze item_3d.name = 'Archaeological Site: %s' % item_2d.name return item_3d
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 solids_borders(root, pipeline, obj): floors = ddd.group2(name="Floors") ceilings = ddd.group2(name="Ceilings") walls = ddd.group2(name="Walls") angles_ceiling = [-math.pi / 4, math.pi / 4] angles_floor1 = [math.pi / 4 * 3, math.pi / 4 * 4] angles_floor2 = [-math.pi / 4 * 4, -math.pi / 4 * 3] polygon = obj.geom.exterior if polygon.is_ccw: polygon.coords = reversed(list(polygon.coords)) segments = zip(polygon.coords, polygon.coords[1:] + polygon.coords[:1]) for a, b in segments: angle = math.atan2(b[1] - a[1], b[0] - a[0]) if (angle > angles_floor1[0] and angle < angles_floor1[1]): floors.append(ddd.line([a, b])) if (angle > angles_floor2[0] and angle < angles_floor2[1]): floors.append(ddd.line([a, b])) if (angle > angles_ceiling[0] and angle < angles_ceiling[1]): ceilings.append(ddd.line([a, b])) ddd.mats.grass = ddd.material( name="Grass", color='#2dd355', texture_path="res://assets/scene/props/grass-texture-tiled.png", #alpha_cutoff=0.05, #extra={'ddd:collider': False, 'ddd:shadows': False, 'uv:scale': 0.05} ) floor_lines = floors floors = ddd.line([[0, 0], [1, 1]], name="Floors") floors.geom = linemerge([g.geom for g in floor_lines.children]) # Iterate merged lines floors = floors.individualize(always=True) for line in floors.children: floor = line.buffer(10.0) floor = floor.material(ddd.mats.grass) floor.extra['floor_line'] = line floor.extra['ddd:z_index'] = 40 floor = uvmapping.map_2d_path(floor, line, line_x_offset=64.0, line_x_width=64.0) #ddd.trace(locals()) print(floor.get('uv', None)) line.replace(floor) #floors.extra['ddd:z_index'] = 40 #newobj = ddd.group2([obj, floors], name="Solid") #obj.replace(newobj) root.find("/Rooms").append(floors) obj.extra['floors'] = floors ceiling_lines = ceilings lines = linemerge([g.geom for g in ceiling_lines.children]) ceilings = DDDObject2(name="Ceilings", geom=lines) ceilings.extra['ddd:z_index'] = 40 ceilings = ceilings.individualize(always=True).clean() for pc in ceilings.children: c = pc.copy() c.extra['ceiling_line'] = c.copy() c = c.buffer(15.0) c = filters.noise_random(c, scale=10.0) pc.replace(c) ceilings = ceilings.material(ddd.mats.bricks) ceilings.mat.color_rgba[3] = 128 ceilings = ceilings.clean() #newobj = ddd.group2([obj, floors], name="Solid") #obj.replace(newobj) root.find("/Rooms").append(ceilings) obj.extra['ceilings'] = ceilings
def solids_borders(root, pipeline, obj): if 'godot:material' in obj.extra: del(obj.extra['godot:material']) floors = ddd.group2(name="Floors") ceilings = ddd.group2(name="Ceilings") walls = ddd.group2(name="Walls") angles_ceiling = [-math.pi / 4, math.pi / 4] angles_floor1 = [math.pi / 4 * 3, math.pi / 4 * 4] angles_floor2 = [-math.pi / 4 * 4, -math.pi / 4 * 3] polygon = obj.geom.exterior if polygon.is_ccw: polygon.coords = reversed(list(polygon.coords)) segments = zip(polygon.coords, polygon.coords[1:] + polygon.coords[:1]) for a, b in segments: angle = math.atan2(b[1] - a[1], b[0] - a[0]) if (angle >= angles_floor1[0] and angle <= angles_floor1[1]): borderline = ddd.line([a, b]) borderline.extra.update(obj.extra) floors.append(borderline) if (angle >= angles_floor2[0] and angle <= angles_floor2[1]): borderline = ddd.line([a, b]) borderline.extra.update(obj.extra) floors.append(borderline) if (angle >= angles_ceiling[0] and angle <= angles_ceiling[1]): borderline = ddd.line([a, b]) borderline.extra.update(obj.extra) ceilings.append(borderline) ''' ddd.mats.grass = ddd.material(name="Grass", color='#2dd355', texture_path="res://assets/scene/props/grass-texture-tiled.png", #alpha_cutoff=0.05, #extra={'ddd:collider': False, 'ddd:shadows': False, 'uv:scale': 0.05} ) ''' floors2 = ddd.group2(name="Floors Background") floor_lines = floors floors = ddd.line([[0, 0], [1, 1]], name="Floors") floors.extra.update(obj.extra) floors.geom = linemerge([g.geom for g in floor_lines.children]) # Iterate merged lines floors = floors.individualize(always=True).clean() for line in floors.children: floor = line.buffer(8.0, resolution=1, cap_style=ddd.CAP_FLAT) # cap_style=ddd.CAP_FLAT) floor = floor.material(ddd.mats.grass_fore) floor.name = "Floor Fore: %s" % line.name floor.extra['floor_line'] = line.copy() #floor.extra['godot:material'] = "grass_fore" floor.extra['ddd:z_index'] = 46 # floor = floor.subtract(obj) floor = uvmapping.map_2d_path(floor, line, line_x_offset=64.0, line_x_width=63.0) if 'uv' in floor.extra: floor.extra['uv'] = [(v[0], v[1] * 4.0) for v in floor.extra['uv']] # temp: transposed and scaled floor.extra['ddd:collider'] = False floor.extra['ddd:occluder'] = False floor.extra['solid'] = False floor.extra['godot:light_mask'] = 0 # floor = filters.noise_random(floor, scale=3.0) # ddd.trace(locals()) # print(floor.get('uv', None)) floor2 = line.buffer(18.0, resolution=3, cap_style=ddd.CAP_FLAT) floor2 = floor2.material(ddd.mats.grass) floor2.name = "Floor: %s" % line.name floor2.extra['floor_line'] = line.copy() #floor.extra['godot:material'] = "grass" floor2.extra['ddd:z_index'] = -1 floor2 = uvmapping.map_2d_path(floor2, line, line_x_offset=64.0, line_x_width=63.0) if 'uv' in floor2.extra: floor2.extra['uv'] = [(v[0], 16.0 + v[1] * 3.5)for v in floor2.extra['uv']] # temp: transposed and scaled # floor2 = filters.noise_random(floor2, scale=3.0) floor2.extra['ddd:collider'] = False floor2.extra['ddd:occluder'] = False floor2.extra['solid'] = False floor2.extra['godot:light_mask'] = 1 min_length = 50 if line.length() > min_length and not obj.get('border:floor', None) == 'false': floors2.append(floor2) line.replace(floor) else: line.geom = None # for f2 in floors2: floors.append(f2) floors.append(floors2) # floors.extra['ddd:z_index'] = 40 # newobj = ddd.group2([obj, floors], name="Solid") # obj.replace(newobj) root.find("/Rooms").append(floors) obj.extra['floors'] = floors ceiling_lines = ceilings lines = linemerge([g.geom for g in ceiling_lines.children]) ceilings = DDDObject2(name="Ceilings", geom=lines) ceilings.extra.update(obj.extra) ceilings.extra['ddd:z_index'] = 40 ceilings = ceilings.individualize(always=True).clean() for pc in ceilings.children: c = pc.copy() c.extra['ceiling_line'] = c.copy() c = c.buffer(15.0) c = filters.noise_random(c, scale=10.0) pc.replace(c) ceilings = ceilings.material(ddd.mats.bricks) # ceilings.mat.color_rgba[3] = 128 ceilings = ceilings.clean() ceilings.set('ddd:collider', False, children=True) ceilings.set('ddd:occluder', False, children=True) ceilings.set('solid', False, children=True) ceilings.set('godot:light_mask', 1, children=True) # newobj = ddd.group2([obj, floors], name="Solid") # obj.replace(newobj) root.find("/Rooms").append(ceilings) obj.extra['ceilings'] = ceilings