def alg_lorenz_attractor(vmf: Vmf): # cfg scale_f = 64 xrange = 32 yrange = 32 zrange = 32 material = "realworldtextures/floor/mixtile/solid/blue1" # init rho = 28.0 sigma = 10.0 beta = 8.0 / 3.0 def f(state, t): x, y, z = state # Unpack the state vector # Derivatives return sigma * (y - x), x * (rho - z) - y, x * y - beta * z state0 = [1.0, 1.0, 1.0] t = np.arange(0.0, 40.0, 0.01) states = odeint(f, state0, t) # todo add import # fig = plt.figure() # ax = fig.gca(projection="3d") # ax.plot(states[:, 0], states[:, 1], states[:, 2]) # plt.draw() # plt.show() for s in states: x = int(s[0]) * scale_f y = int(s[1]) * scale_f z = int(s[2]) * scale_f vmf.add_solid(Vertex(x, y, z), xrange, yrange, zrange, material)
def alg_myon_trace(vmf: Vmf): # cfg block_xr = 64 block_yr = 64 block_zr = 16 r = 20 for i in range(r): x, y, z = little_test(6969) if plot: plt.plot(z, x) if gen: for j in range(len(x)): # TODO add z var (or keep static (?)) # TODO add blockdiff range print( str(i) + "/" + str(r) + " :: " + str(j) + "/" + str(len(x))) vmf.add_solid(Vertex(x[j], z[j], 0), block_xr, block_yr, block_zr, checkCollisionType=2) if plot: plt.show()
def alg_prime_spiral(vmf: Vmf): # cfg texture_t1 = "realworldtextures2/concrete/concrete_37" texture_t2 = "realworldtextures2/concrete/concrete_38" prime_start = 24 prime_range = 256 xrange = 32 yrange = 32 zrange = 8 z = 0 z_inc = 2 # prime numbers p_list = [] for i in range(prime_start, prime_range + prime_start): p_list.append(prime(i)) # gen solids index = 1 for p in p_list: polar = Polar(p, p) if (index % 2 == 0): material = texture_t1 else: material = texture_t2 vmf.add_solid(Vertex(polar.x, polar.y, z), xrange, yrange, zrange, material) z += z_inc index += 1
def alg_perlin_noise(vmf: Vmf): # cfg texture_t1 = "REALWORLDTEXTURES2/GROUND/SAND_10" texture_t2 = "REALWORLDTEXTURES/NEWER/1/DIRT_1_02" texture_t3 = "DE_AZTEC/HR_AZTEC/HR_AZTEC_BLEND_GROUNDMUD03-GROUNDROCK04" xrange = 128 yrange = 128 zrange = 128 z_noise_scale = 384 gridsize = 50 # ndarray # init noise lin = np.linspace(0, 5, gridsize, endpoint=False) x, y = np.meshgrid(lin, lin) # plt.imshow(perlin(x, y, seed=2), origin='upper') # plt.show() noisegrid = perlin(x, y, seed=2) index_row = 0 index_col = 0 for row in noisegrid: for ele in row: x = xrange * index_col + xrange / 2 y = yrange * index_row - yrange / 2 z = ele * z_noise_scale if ele < -0.35: material = texture_t3 elif ele > 0.2: material = texture_t1 else: material = texture_t2 vmf.add_solid(Vertex(x, y, z), xrange, yrange, zrange, material) index_col += 1 index_row += 1 index_col = 0
def __init__(self, origin: Vertex, xr: int, yr: int, zr: int, direction: int): # self.origin = origin # self.xr = xr # self.yr = yr # self.zr = zr # TODO enum [1,2,3,4,5,6]->[+x,-y,-x,+y,+z,-z] self.direction = direction if (direction == 1): self.origin = Vertex(origin.x + (1 / 2) * xr, origin.y, origin.z) self.height = zr self.width = yr elif (direction == 2): self.origin = Vertex(origin.x, origin.y - (1 / 2) * yr, origin.z) self.height = zr self.width = xr elif (direction == 3): self.origin = Vertex(origin.x - (1 / 2) * xr, origin.y, origin.z) self.height = zr self.width = yr elif (direction == 4): self.origin = Vertex(origin.x, origin.y + (1 / 2) * yr, origin.z) self.height = zr self.width = xr elif (direction == 5): self.origin = Vertex(origin.x, origin.y, origin.z + (1 / 2) * zr) self.height = yr self.width = xr elif (direction == 6): self.origin = Vertex(origin.x, origin.y, origin.z - (1 / 2) * zr) self.height = yr self.width = xr
def alg_shape_3d(vmf: Vmf): # cfg addSolid = True draw = False block_xr = 96 block_yr = 96 block_zr = 128 assert block_xr == block_yr dimRange = 8192 blockDiffRange = 48 #s1 = 0.01 #s2 = 0.01 numberPoints = int(dimRange / (block_xr + blockDiffRange)) assert numberPoints > 0 X = np.linspace(0, dimRange, numberPoints) Y = np.linspace(0, dimRange, numberPoints) xx, yy = np.meshgrid(X, Y) # todo outsource func # todo try p60 numpy doc zz = 192 * np.cos((0.0008 * xx)**2 + 8 * np.cos(0.0009 * yy)**2) #zz = (s1*(xx))**2-(s2*(yy))**2 points = np.vstack((xx.flatten(), yy.flatten(), zz.flatten())).T if draw: fig = plt.figure() ax = Axes3D(fig) ax.plot_surface(xx, yy, zz, rstride=1, cstride=1, cmap='viridis') plt.show() if addSolid: i = 1 for p in points: assert len(p) == 3 pX = int(p[0]) pY = int(p[1]) pZ = int(p[2]) if pX % 2 != 0: pX = pX + 1 if pY % 2 != 0: pY = pY + 1 if pZ % 2 != 0: pZ = pZ + 1 vmf.add_solid(Vertex(pX, pY, pZ), block_xr, block_yr, block_zr) # debug print(str(i) + " / " + str(len(points))) i += 1
def gen_solid(self, centre: Vertex, xr: int, yr: int, zr: int, mflag=False, material="TOOLS/TOOLSNODRAW") -> Solid: v1 = Vertex(centre.x - int(xr / 2), centre.y + int(yr / 2), centre.z + int(zr / 2)) # up-back-left v2 = Vertex(centre.x - int(xr / 2) + xr, centre.y + int(yr / 2), centre.z + int(zr / 2)) # up-back-right v3 = Vertex(centre.x - int(xr / 2), centre.y + int(yr / 2) - yr, centre.z + int(zr / 2)) # up-front-left v4 = Vertex(centre.x - int(xr / 2) + xr, centre.y + int(yr / 2) - yr, centre.z + int(zr / 2)) # up-front-right v5 = Vertex(centre.x - int(xr / 2), centre.y + int(yr / 2), centre.z + int(zr / 2) - zr) # down-back-left v6 = Vertex(centre.x - int(xr / 2) + xr, centre.y + int(yr / 2), centre.z + int(zr / 2) - zr) # down-back-right v7 = Vertex(centre.x - int(xr / 2), centre.y + int(yr / 2) - yr, centre.z + int(zr / 2) - zr) # down-front-left v8 = Vertex(centre.x - int(xr / 2) + xr, centre.y + int(yr / 2) - yr, centre.z + int(zr / 2) - zr) # down-front-right # p1 = Plane(v1, v2, v4, material) # up if not mflag: p1 = Plane(v1, v2, v4, "realworldtextures2/concrete/concrete_38") # up else: p1 = Plane(v1, v2, v4, "campus/concrete/stone_floor01") # up #p2 = Plane(v7, v8, v6) # down ##### FORCE NODRAW ##### p2 = Plane(v7, v8, v6, material) # down p3 = Plane(v1, v3, v7, material) # left p4 = Plane(v6, v8, v4, material) # right p5 = Plane(v2, v1, v5, material) # back p6 = Plane(v8, v7, v3, material) # front vertexList = [v1, v2, v3, v4, v5, v6, v7, v8] radiusEvaluate = [] for v in vertexList: radiusEvaluate.append( np.sqrt((v.x - centre.x)**2 + (v.y - centre.y)**2 + (v.z - centre.z)**2)) radius = int(max(radiusEvaluate)) return Solid(p1, p2, p3, p4, p5, p6, centre, radius, xr, yr, zr)
def alg_bhop_concatenation(vmf: Vmf): # cfg n = 4000 min_size = 64 assert min_size > 8 max_size = 128 fail_seq_max = 100 block_min_distance = 256 block_xr = min_size block_yr = min_size block_zr = min_size / 4 i = 0 fail_seq_nr = 0 root = vmf.gen_solid(Vertex(0, 0, 12000), max_size, max_size, max_size) solid = root vmf.add_solid(solid.origin, solid.xr, solid.yr, solid.zr) while i < n or fail_seq_nr >= fail_seq_max: skip = False # debug print(f'{i} / {n}') # quick math R = solid.radius + block_min_distance phi = random.uniform(0, 2 * np.pi) costheta = random.uniform(-1, 1) u = random.uniform(0, 1) theta = np.arccos(costheta) r = R * np.cbrt(u) x = r * np.sin(theta) * np.cos(phi) y = r * np.sin(theta) * np.sin(phi) z = r * np.cos(theta) new_solid_z = int(solid.origin.z + z) if new_solid_z % 2 != 0: new_solid_z = new_solid_z + 1 if (new_solid_z > solid.origin.z) or (new_solid_z < solid.origin.z - 32): skip = True if not skip: new_solid_x = int(solid.origin.x + x) if new_solid_x % 2 != 0: new_solid_x = new_solid_x + 1 new_solid_y = int(solid.origin.y + y) if new_solid_y % 2 != 0: new_solid_y = new_solid_y + 1 add_success = vmf.add_solid( Vertex(new_solid_x, new_solid_y, new_solid_z), block_xr, block_yr, block_zr, checkCollisionType=2, material="realworldtextures2/marble/marble_02") if add_success: i = i + 1 fail_seq_nr = 0 # contine on new solid solid = vmf.gen_solid( Vertex(new_solid_x, new_solid_y, new_solid_z), block_xr, block_yr, block_zr) else: fail_seq_nr = fail_seq_nr + 1
def alg_voxel_cube_bomb(vmf: Vmf): stack = [] root = vmf.gen_solid(Vertex(0, 0, 0), 1024, 1024, 1024) i = root vmf.add_solid(i.origin, i.xr, i.yr, i.zr) for k in range(1, 7): stack.append(CuboidSide(i.origin, i.xr, i.yr, i.zr, k)) seed = 1337 material_main = "concrete/hr_c/hr_concrete_wall_001" interationCount = 1 iterationMax = 1000 assert iterationMax > interationCount done = False min_size = 96 swap = True dir_up_swap = True dir_up_flag = None while (stack and (not done)): if (interationCount > iterationMax): done = True side = stack.pop(0) random.seed(seed) new_cuboid_width = None new_cuboid_height = None temp_min = min(side.width, side.height) min_val = int((temp_min) / 4) if (min_val % 2) != 0: min_val = min_val+1 if min_val < min_size: min_val = min_size new_cuboid_width = random.randint( min_val, int(side.width*(5/4))) # TODO tweak if (new_cuboid_width % 2) != 0: new_cuboid_width = new_cuboid_width + 1 new_cuboid_height = random.randint( min_val, int(side.height*(5/4))) # TODO tweak if (new_cuboid_height % 2) != 0: new_cuboid_height = new_cuboid_height+1 new_cuboid_dir_length = None if swap: new_cuboid_dir_length = random.randint( min_size, int((new_cuboid_width + new_cuboid_height) * (4/5))) swap = not swap else: new_cuboid_dir_length = random.randint( min_size, int((new_cuboid_width + new_cuboid_height) / (3/5))) swap = not swap if (new_cuboid_dir_length % 2) != 0: new_cuboid_dir_length = new_cuboid_dir_length+1 seed = seed + 1 interationCount = interationCount + 1 currentCuboid = None add_success = None if (side.direction == 1): add_success = vmf.add_solid(Vertex(side.origin.x+(1 / 2) * new_cuboid_dir_length, side.origin.y, side.origin.z), new_cuboid_dir_length, new_cuboid_width, new_cuboid_height, material=material_main, checkCollisionType=2) currentCuboid = vmf.gen_solid(Vertex(side.origin.x+(1 / 2) * new_cuboid_dir_length, side.origin.y, side.origin.z), new_cuboid_dir_length, new_cuboid_width, new_cuboid_height) elif (side.direction == 2): add_success = vmf.add_solid(Vertex(side.origin.x, side.origin.y-(1 / 2) * new_cuboid_dir_length, side.origin.z), new_cuboid_width, new_cuboid_dir_length, new_cuboid_height, material=material_main, checkCollisionType=2) currentCuboid = vmf.gen_solid(Vertex(side.origin.x, side.origin.y-(1 / 2) * new_cuboid_dir_length, side.origin.z), new_cuboid_width, new_cuboid_dir_length, new_cuboid_height) elif (side.direction == 3): add_success = vmf.add_solid(Vertex(side.origin.x-(1 / 2) * new_cuboid_dir_length, side.origin.y, side.origin.z), new_cuboid_dir_length, new_cuboid_width, new_cuboid_height, material=material_main, checkCollisionType=2) currentCuboid = vmf.gen_solid(Vertex(side.origin.x-(1 / 2) * new_cuboid_dir_length, side.origin.y, side.origin.z), new_cuboid_dir_length, new_cuboid_width, new_cuboid_height) elif (side.direction == 4): add_success = vmf.add_solid(Vertex(side.origin.x, side.origin.y+(1 / 2) * new_cuboid_dir_length, side.origin.z), new_cuboid_width, new_cuboid_dir_length, new_cuboid_height, material=material_main, checkCollisionType=2) currentCuboid = vmf.gen_solid(Vertex(side.origin.x, side.origin.y+(1 / 2) * new_cuboid_dir_length, side.origin.z), new_cuboid_width, new_cuboid_dir_length, new_cuboid_height) elif (side.direction == 5): if dir_up_swap: dir_up_flag = False add_success = vmf.add_solid(Vertex(side.origin.x, side.origin.y, side.origin.z+(1 / 2) * new_cuboid_dir_length), new_cuboid_width, new_cuboid_height, new_cuboid_dir_length, material=material_main, checkCollisionType=2) currentCuboid = vmf.gen_solid(Vertex(side.origin.x, side.origin.y, side.origin.z+(1 / 2) * new_cuboid_dir_length), new_cuboid_width, new_cuboid_height, new_cuboid_dir_length) dir_up_swap = not dir_up_swap else: dir_up_flag = True # TODO off center-origin amount_failure = 0 amount_failure_max = 10 # cfg while amount_failure < amount_failure_max: min_jumpblock_size = 16 new_cuboid_dir_length_add_min = -16 new_cuboid_dir_length_add_max = 32 new_cuboid_dir_length = new_cuboid_dir_length + \ random.randint(new_cuboid_dir_length_add_min, new_cuboid_dir_length_add_max) new_cuboid_width = random.randint( min_jumpblock_size, int(side.width*(5/4))) # TODO tweak if (new_cuboid_width % 2) != 0: new_cuboid_width = new_cuboid_width + 1 new_cuboid_height = random.randint( min_jumpblock_size, int(side.height*(5/4))) # TODO tweak if (new_cuboid_height % 2) != 0: new_cuboid_height = new_cuboid_height+1 if (new_cuboid_dir_length % 2) != 0: new_cuboid_dir_length = new_cuboid_dir_length + 1 if (new_cuboid_dir_length < min_jumpblock_size) or (new_cuboid_dir_length > 256): new_cuboid_dir_length = min_jumpblock_size if (new_cuboid_height / 4 < min_jumpblock_size): new_cuboid_height = min_jumpblock_size else: new_cuboid_height = new_cuboid_height / 4 if (new_cuboid_height % 2) != 0: new_cuboid_height = new_cuboid_height + 1 if (new_cuboid_width / 4 < min_jumpblock_size): new_cuboid_width = min_jumpblock_size else: new_cuboid_width = new_cuboid_width / 4 if (new_cuboid_width % 2) != 0: new_cuboid_width = new_cuboid_width + 1 new_cuboid_x_pos = side.origin.x x_min = int(side.origin.x - (1 / 2) * side.width + (1/2)*new_cuboid_width) x_max = int(side.origin.x + (1 / 2) * side.width - (1/2)*new_cuboid_width) new_cuboid_x_pos = random.randint( min(x_min, x_max), max(x_min, x_max)) if (new_cuboid_x_pos % 2) != 0: new_cuboid_x_pos = new_cuboid_x_pos + 1 new_cuboid_y_pos = side.origin.y y_min = int(side.origin.y - (1 / 2) * side.height + (1/2)*new_cuboid_height) y_max = int(side.origin.y + (1 / 2) * side.height - (1/2)*new_cuboid_height) new_cuboid_y_pos = random.randint( min(y_min, y_max), max(y_min, y_max)) if (new_cuboid_y_pos % 2) != 0: new_cuboid_y_pos = new_cuboid_y_pos + 1 add_success = vmf.add_solid(Vertex(new_cuboid_x_pos, new_cuboid_y_pos, side.origin.z+( 1 / 2) * new_cuboid_dir_length), new_cuboid_width, new_cuboid_height, new_cuboid_dir_length, material="realworldtextures2/marble/marble_02", mflag=True, checkCollisionType=2) if not add_success: amount_failure = amount_failure + 1 else: # check for <amount_failure_max> fails in a row amount_failure = 0 dir_up_swap = not dir_up_swap elif (side.direction == 6): add_success = vmf.add_solid(Vertex(side.origin.x, side.origin.y, side.origin.z-(1 / 2) * new_cuboid_dir_length), new_cuboid_width, new_cuboid_height, new_cuboid_dir_length, material=material_main, checkCollisionType=2) currentCuboid = vmf.gen_solid(Vertex(side.origin.x, side.origin.y, side.origin.z+( 1 / 2) * new_cuboid_dir_length), new_cuboid_width, new_cuboid_height, new_cuboid_dir_length) if (add_success and (not dir_up_flag)): for k in range(1, 7): dir_comp = None if (side.direction == 1): dir_comp = 3 elif (side.direction == 2): dir_comp = 4 elif (side.direction == 3): dir_comp = 1 elif (side.direction == 4): dir_comp = 2 elif (side.direction == 5): dir_comp = 6 elif (side.direction == 6): dir_comp = 5 if (k != dir_comp): stack.append(CuboidSide(currentCuboid.origin, currentCuboid.xr, currentCuboid.yr, currentCuboid.zr, k))