Exemplo n.º 1
0
def duplicate_node_object(original_node: hg.Node, name):
    node = hg.Node(name)
    trans = hg.Transform()
    node.AddComponent(trans)
    obj = hg.Object()
    obj.SetGeometry(original_node.GetObject().GetGeometry())
    node.AddComponent(obj)
    return node
def create_instance(scn, path):
    node = hg.Node()
    node.AddComponent(hg.Transform())
    instance = hg.Instance()
    instance.SetPath(path)
    node.AddComponent(instance)
    node.GetTransform().SetPosition(vec3(0, 0, 0))
    scn.AddNode(node)
    return node
Exemplo n.º 3
0
def create_box(pos = hg.Vector3(), rot = hg.Vector3(), width = 1.0, height = 1.0):
	node = hg.Node()
	object = hg.Object()
	transform = hg.Transform()
	transform.SetPosition(pos + hg.Vector3(0, height * 0.5, 0))
	transform.SetRotation(rot)
	node.AddComponent(transform)
	object.SetGeometry(render_system.CreateGeometry(hg.CreateCube(width, height, width)))
	node.AddComponent(object)
	return node
Exemplo n.º 4
0
def create_wall(pos = hg.Vector3.Zero, rot = hg.Vector3.Zero, width = 1.0, length = 1.0, material_path = "material_diffuse_color.mat", name="dummy"):
	""" generic function to create a wall """
	node = hg.Node()
	transform = hg.Transform()
	transform.SetPosition(pos)
	transform.SetRotation(rot)
	node.AddComponent(transform)
	object = hg.Object()
	object.SetGeometry(render_system.CreateGeometry(hg.CreatePlane(width, length, 1, material_path, name)))
	node.AddComponent(object)
	return node
Exemplo n.º 5
0
def load_object(plus, geometry_file_name, name, duplicate_material=False):
    renderSystem = plus.GetRenderSystem()
    node = hg.Node(name)
    trans = hg.Transform()
    node.AddComponent(trans)
    obj = hg.Object()
    geo = hg.Geometry()
    hg.LoadGeometry(geo, geometry_file_name)
    if geo is not None:
        geo = renderSystem.CreateGeometry(geo, False)
        if duplicate_material:
            material = geo.GetMaterial(0)
            material = material.Clone()
            geo.SetMaterial(0, material)
        obj.SetGeometry(geo)
        node.AddComponent(obj)
    return node, geo
Exemplo n.º 6
0
def setup_teleporter(scn, ground_size: hg.Vector2):
    global authorise_ground_node
    authorise_ground_node = hg.Node()
    trans = hg.Transform()
    authorise_ground_node.AddComponent(trans)
    rb = hg.RigidBody()
    rb.SetCollisionLayer(2)
    rb.SetType(hg.RigidBodyKinematic)
    authorise_ground_node.AddComponent(rb)

    box_col = hg.BoxCollision()
    box_col.SetDimensions(hg.Vector3(ground_size.x, 0.1, ground_size.y))
    box_col.SetMass(0)
    authorise_ground_node.AddComponent(box_col)
    scn.AddNode(authorise_ground_node)

    while authorise_ground_node.GetRigidBody().GetState() == hg.NotReady:
        scn.UpdateAndCommitWaitAll()
Exemplo n.º 7
0
sky.Set("shadow_range", 10000.0)  # 10km shadow range
sky.Set("shadow_split", hg.Vector4(0.1, 0.2, 0.3, 0.4))
scn.AddComponent(sky)

# load terrain
terrain = hg.Terrain()
terrain.SetSize(hg.Vector3(68767, 5760, 68767))
terrain.SetHeightmap("@data/terrain/island.r16")
terrain.SetHeightmapResolution(hg.IntVector2(1024, 1024))
terrain.SetMinPrecision(
    50
)  # don't bother with a very fine grid given the low resolution heightmap in use
terrain.SetSurfaceShader("@data/terrain/island.isl")

terrain_node = hg.Node()
terrain_node.AddComponent(hg.Transform())
terrain_node.AddComponent(terrain)
scn.AddNode(terrain_node)

#
fps = hg.FPSController(0, 3000, -30000, 100, 400)

while not plus.IsAppEnded():
    dt = plus.UpdateClock()

    old_pos = fps.GetPos()
    fps.UpdateAndApplyToNode(cam, dt)
    speed = hg.Dist(fps.GetPos(),
                    old_pos) / hg.time_to_sec_f(dt) if dt > 0 else 0

    plus.UpdateScene(scn, dt)
Exemplo n.º 8
0
render_system.Initialize(renderer)

# create scene
scene = hg.Scene()
hg.SceneSetupCoreSystemsAndComponents(scene, render_system)

env = hg.Environment()
env.SetBackgroundColor(hg.Color.Black)
env.SetAmbientColor(hg.Color.White)
env.SetAmbientIntensity(0.1)
scene.AddComponent(env)

# light Source Definition
node_light = hg.Node()

light_transform = hg.Transform()
light_transform.SetPosition(hg.Vector3(0.0, box_height * 0.825, 0.0))
node_light.AddComponent(light_transform)

light_component = hg.Light()
light_component.SetDiffuseColor(hg.Color(1, 0.9, 0.7))
light_component.SetRange(box_width * 10.0)
light_component.SetShadow(hg.LightShadowMap)
node_light.AddComponent(light_component)

scene.AddNode(node_light)

# wall definitions
def create_wall(pos = hg.Vector3.Zero, rot = hg.Vector3.Zero, width = 1.0, length = 1.0, material_path = "material_diffuse_color.mat", name="dummy"):
	""" generic function to create a wall """
	node = hg.Node()