Class: Teien::MeshObjectInfo

Inherits:
ObjectInfo show all
Defined in:
lib/teien/ui/std_objects/mesh_object_info.rb,
lib/teien/base_object/std_objects/mesh_object_info.rb

Instance Attribute Summary collapse

Attributes inherited from ObjectInfo

#use_physics

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mesh_path, scale = Vector3D.new(1, 1, 1), view_offset = Vector3D.new(0, 0, 0), view_rotation = Quaternion.new(0, 0, 0, 1.0), physics_offset = Vector3D.new(0, 0, 0)) ⇒ MeshObjectInfo

Returns a new instance of MeshObjectInfo.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/teien/base_object/std_objects/mesh_object_info.rb', line 13

def initialize(mesh_path, scale = Vector3D.new(1, 1, 1),
               view_offset = Vector3D.new(0, 0, 0),
               view_rotation = Quaternion.new(0, 0, 0, 1.0),
               physics_offset = Vector3D.new(0, 0, 0))
  super()
  @mesh_path = mesh_path
  @scale = scale
  @view_offset = view_offset
  @view_rotation = view_rotation
  @physics_offset = physics_offset
  @material_name = nil
end

Instance Attribute Details

#material_nameObject

Returns the value of attribute material_name.



11
12
13
# File 'lib/teien/base_object/std_objects/mesh_object_info.rb', line 11

def material_name
  @material_name
end

#mesh_pathObject

Returns the value of attribute mesh_path.



6
7
8
# File 'lib/teien/base_object/std_objects/mesh_object_info.rb', line 6

def mesh_path
  @mesh_path
end

#physics_offsetObject

Loading mesh only: offset of collision Box



10
11
12
# File 'lib/teien/base_object/std_objects/mesh_object_info.rb', line 10

def physics_offset
  @physics_offset
end

#scaleObject

Loading mesh only: scales mesh



7
8
9
# File 'lib/teien/base_object/std_objects/mesh_object_info.rb', line 7

def scale
  @scale
end

#view_offsetObject

Loading mesh only: offset of Mesh



8
9
10
# File 'lib/teien/base_object/std_objects/mesh_object_info.rb', line 8

def view_offset
  @view_offset
end

#view_rotationObject

Loading mesh only: rotation offset of Mesh



9
10
11
# File 'lib/teien/base_object/std_objects/mesh_object_info.rb', line 9

def view_rotation
  @view_rotation
end

Class Method Details

.create_physics_object(obj, physics) ⇒ Object

This method needs the obj.entity to create a collision shape. So it’s not support to use this method on server(physics only) currently.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/teien/base_object/std_objects/mesh_object_info.rb', line 28

def self.create_physics_object(obj, physics)
  physics_object = PhysicsObject.new(physics)

  if obj.physics_info
    strider = Teienlib::MeshStrider.new(obj.entity.get_mesh().get())
    cShape = Bullet::BtGImpactMeshShape.new(strider)
    cShape.set_local_scaling(Bullet::BtVector3.new(obj.object_info.scale.x, 
                                                   obj.object_info.scale.y, 
                                                   obj.object_info.scale.z))
    cShape.instance_variable_set(:@strider, strider) # prevent this from GC.
    cShape.post_update()
    cShape.update_bound()
    inertia = Bullet::BtVector3.new()
    cShape.calculate_local_inertia(obj.physics_info.mass, inertia)
    physics_object.set_rigid_body(obj, cShape, inertia, 
                                  obj.object_info.physics_offset)
    obj.object_info.use_physics = true
  else
    # use a rigid body as a position holder only(not as collision shape).
    cShape = Bullet::BtSphereShape.new(0.1)
    inertia = Bullet::BtVector3.new()
    cShape.calculate_local_inertia(0, inertia)
    obj.physics_info = PhysicsInfo.new(0) # dummy to make a rigid body.
    physics_object.set_rigid_body(obj, cShape, inertia)
    obj.physics_info = nil
    obj.object_info.use_physics = false
  end

  return physics_object
end

.create_view_object(obj, view) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/teien/ui/std_objects/mesh_object_info.rb', line 7

def self.create_view_object(obj, view)
  entity = view.scene_mgr.create_entity(obj.name, obj.object_info.mesh_path)
  entity.set_cast_shadows(true)
  entity.set_material_name(obj.object_info.material_name) if obj.object_info.material_name

  view_object = ViewObject.new(view)
  node = view_object.set_scene_node(entity, obj.object_info.view_offset)
  node.set_scale(obj.object_info.scale.x, 
                 obj.object_info.scale.y, 
                 obj.object_info.scale.z)

  return view_object
end