# -*- coding:utf-8 -*- # title :石头 # description :石头 # author :Python超人 # date :2023-11-10 # link :https://gitcode.net/pythoncr/ # python_version :3.9 # ============================================================================== from objs.obj import Obj class Stone(Obj): """ 石头 """ def __init__(self, name="石头", mass=5.97237e24, init_position=[0, 0, 0], init_velocity=[0, 0, 0], texture="stone1.png", size_scale=1.0, distance_scale=1.0, ignore_mass=False, density=1e3, color=(7, 0, 162), trail_color=None, show_name=False, model="stone1.obj", rotation=(0, 0, 0), parent=None, gravity_only_for=[]): params = { "name": name, "mass": mass, "init_position": init_position, "init_velocity": init_velocity, "density": density, "color": color, "texture": texture, "size_scale": size_scale, "distance_scale": distance_scale, "ignore_mass": ignore_mass, "trail_color": trail_color, "show_name": show_name, "parent": parent, "rotation": rotation, "gravity_only_for": gravity_only_for, "model": model } super().__init__(**params) # 对岩石进行缩放,保证 create_rock 保证创建的岩石大小差异不会过大 ROCK_SIZE_SCALE_FACTOR = { 6: 0.5, 7: 1e-2 } def create_stone(no: int = None, **kwargs): if no is not None: kwargs["model"] = f"stone{no}.obj" kwargs["texture"] = f"stone{no}.jpg" if "size_scale" in kwargs: kwargs["size_scale"] = kwargs["size_scale"] * ROCK_SIZE_SCALE_FACTOR.get(no, 1.0) else: kwargs["size_scale"] = ROCK_SIZE_SCALE_FACTOR.get(no, 1.0) stone = Stone(**kwargs) # print(rock) return stone if __name__ == '__main__': # stone = Stone() # print(stone) # stone.show_demo(size_scale=1000000) stone = create_stone(no=2) stone.show_demo(size_scale=1000000)