shattered_view 0.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/base.rb +34 -109
- data/lib/camera.rb +1 -1
- data/lib/extensions.rb +4 -1
- data/lib/{animation.rb → mesh/animation.rb} +3 -0
- data/lib/mesh/mesh.rb +174 -0
- data/lib/node.rb +69 -0
- data/lib/resources.rb +10 -26
- data/lib/runner.rb +24 -0
- data/lib/shattered_view.rb +9 -8
- data/lib/utilities.rb +0 -51
- metadata +23 -30
- data/lib/mesh.rb +0 -79
data/lib/base.rb
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
2
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
|
3
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
|
4
|
+
|
|
5
|
+
require 'mesh/mesh'
|
|
6
|
+
|
|
3
7
|
include ShatteredSupport
|
|
4
8
|
|
|
5
9
|
module ShatteredView
|
|
@@ -29,41 +33,6 @@ module ShatteredView
|
|
|
29
33
|
before_init_set name, {:create_ogre_material => []}
|
|
30
34
|
end
|
|
31
35
|
|
|
32
|
-
# This deserves a larger explanation
|
|
33
|
-
#
|
|
34
|
-
# options can include:
|
|
35
|
-
# - :animation => (not implemented yet)
|
|
36
|
-
# - - :speed => speed in game_seconds/animation_seconds
|
|
37
|
-
# - - :start_at => animation name to start the animation
|
|
38
|
-
# - - :loops => default for looping
|
|
39
|
-
def mesh(file, options = {})
|
|
40
|
-
name = file.underscore
|
|
41
|
-
before_init_set( "self", {:new_mesh => file })
|
|
42
|
-
|
|
43
|
-
define_method(name.to_sym) do
|
|
44
|
-
return instance_variable_get(:"@#{name}")
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
#What is this?
|
|
48
|
-
options = options.dup
|
|
49
|
-
options.delete :file
|
|
50
|
-
options.delete :name
|
|
51
|
-
|
|
52
|
-
before_init_set( name, options )
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
# options can include any function in animation.rb
|
|
58
|
-
# and :alias => :alias_name
|
|
59
|
-
def animation(name, options = {})
|
|
60
|
-
alias_option = options.delete(:alias)
|
|
61
|
-
before_init_set("animation(:#{name})", options)
|
|
62
|
-
before_init_set("self", {:new_animation => [name]})
|
|
63
|
-
if not alias_option.nil?
|
|
64
|
-
before_init_set("self", {:new_animation_alias => [name, alias_option]})
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
36
|
|
|
68
37
|
|
|
69
38
|
# Any view can create a light.
|
|
@@ -98,54 +67,23 @@ module ShatteredView
|
|
|
98
67
|
before_init_set name, options
|
|
99
68
|
end
|
|
100
69
|
|
|
70
|
+
# Particle systems are defined in .particle files
|
|
71
|
+
# - This works for first order particle systems --
|
|
72
|
+
# - We need to look into second and third order particle systems
|
|
73
|
+
#
|
|
74
|
+
def particle_system(name, options = {})
|
|
75
|
+
raise Error, "Must supply a template for your particle system." if options[:template].nil?
|
|
76
|
+
before_init_set "self", {:new_particle_system, [name, options[:template]]}
|
|
77
|
+
options.delete :template
|
|
78
|
+
before_init_set name, options
|
|
79
|
+
end
|
|
101
80
|
end
|
|
102
81
|
|
|
103
82
|
class Base < ShatteredSupport::Base
|
|
104
83
|
attr_reader :meshes
|
|
84
|
+
attr_accessor :model
|
|
105
85
|
|
|
106
|
-
def unload!
|
|
107
|
-
meshes.each { |mesh| mesh.remove_from_scene }
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
#Note that this method is very similiar to ShatteredController::Actor.
|
|
111
|
-
#And that a common function can be refactored from both.
|
|
112
|
-
def method_missing(method, *args)
|
|
113
|
-
super(method,*args) if !method_defined?(method)
|
|
114
|
-
retv=nil
|
|
115
|
-
meshes.each do |mesh|
|
|
116
|
-
retv =mesh.send(method, *args) if mesh.method_defined? method
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
return retv
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def method_defined?(method)
|
|
123
|
-
meshes.each { |mesh| return true if mesh.method_defined? method }
|
|
124
|
-
return super(method)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
def mesh(file, options={})
|
|
128
|
-
self.class.mesh(file,options)
|
|
129
|
-
pre_initialize
|
|
130
|
-
retv = meshes[-1] # Return the last created mesh
|
|
131
|
-
return retv
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def new_mesh=(file)
|
|
135
|
-
options = {}
|
|
136
|
-
options[:name]=file.underscore
|
|
137
|
-
options[:file]=file
|
|
138
|
-
name = options[:name]
|
|
139
|
-
mesh = Mesh.new(options)
|
|
140
|
-
eval("@#{name}=mesh")
|
|
141
|
-
#keep track of the meshes we create
|
|
142
|
-
meshes << mesh
|
|
143
|
-
end
|
|
144
86
|
|
|
145
|
-
def meshes
|
|
146
|
-
@meshes ||= []
|
|
147
|
-
end
|
|
148
|
-
|
|
149
87
|
def new_material=(name)
|
|
150
88
|
@materials ||= {}
|
|
151
89
|
name = name.to_sym
|
|
@@ -156,44 +94,31 @@ module ShatteredView
|
|
|
156
94
|
end
|
|
157
95
|
end
|
|
158
96
|
|
|
159
|
-
def
|
|
160
|
-
|
|
161
|
-
|
|
97
|
+
def define_accessor(array, new_obj, name)
|
|
98
|
+
|
|
99
|
+
instance_eval("#{array} ||= {}")
|
|
100
|
+
instance_eval("#{array}[\"#{name}\"] = new_obj")
|
|
101
|
+
|
|
162
102
|
self.class.class_eval <<-EOF
|
|
163
103
|
define_method(:#{name}) do
|
|
164
|
-
|
|
104
|
+
#{array}[\"#{name}\"]
|
|
165
105
|
end
|
|
166
106
|
EOF
|
|
167
107
|
end
|
|
168
108
|
|
|
169
|
-
def
|
|
170
|
-
|
|
171
|
-
mesh.instance_eval <<-EOF
|
|
172
|
-
class << self
|
|
173
|
-
define_method(:#{name}) do
|
|
174
|
-
animation(:#{name})
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
EOF
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
def new_animation_alias=(name, alias_option)
|
|
181
|
-
self.class.class_eval <<-EOF
|
|
182
|
-
define_method(:#{alias_option}) do
|
|
183
|
-
meshes.each do |mesh|
|
|
184
|
-
mesh.#{name}.play
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
EOF
|
|
109
|
+
def new_light=(name)
|
|
110
|
+
define_accessor("@lights", ShatteredView::Light.new, name)
|
|
188
111
|
end
|
|
189
112
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
methods |= mesh.public_methods
|
|
195
|
-
end
|
|
196
|
-
return methods
|
|
197
|
-
end
|
|
113
|
+
def new_particle_system=(name, template)
|
|
114
|
+
define_accessor("@particle_systems", ShatteredView::ParticleSystem.new(template), name)
|
|
115
|
+
end
|
|
116
|
+
|
|
198
117
|
end
|
|
199
118
|
end
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
ShatteredView::Base.class_eval do
|
|
122
|
+
include ShatteredView::Mesh
|
|
123
|
+
end
|
|
124
|
+
|
data/lib/camera.rb
CHANGED
data/lib/extensions.rb
CHANGED
data/lib/mesh/mesh.rb
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
|
3
|
+
|
|
4
|
+
require 'animation'
|
|
5
|
+
|
|
6
|
+
module ShatteredView
|
|
7
|
+
module Mesh
|
|
8
|
+
def self.included(base)
|
|
9
|
+
base.extend(ClassMethods)
|
|
10
|
+
base.send(:include, InstanceMethods)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module ClassMethods
|
|
14
|
+
|
|
15
|
+
# Meshes are the foundation for your world.
|
|
16
|
+
#
|
|
17
|
+
# They tie in to Ogre's .mesh file format, and display a 3d object onto the screen.
|
|
18
|
+
#
|
|
19
|
+
# Shattered has support for loading meshes, creating materials for those meshes (using RMaterials)
|
|
20
|
+
# and skeletal animation support.
|
|
21
|
+
#
|
|
22
|
+
# class DirtyRubyView
|
|
23
|
+
# mesh "dirty_ruby", :position => [0,0,1]
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# When a Mesh is created, all animations found in that mesh are loaded, and added
|
|
27
|
+
# as functions to that mesh.
|
|
28
|
+
#
|
|
29
|
+
# example: Tim.mesh has animations kick and punch
|
|
30
|
+
#
|
|
31
|
+
# after loading Tim.mesh, View has the Mesh object tim
|
|
32
|
+
# tim.kick.play
|
|
33
|
+
# tim.animation(:kick).play
|
|
34
|
+
#
|
|
35
|
+
# See Rmaterials and Animation for more details.
|
|
36
|
+
def mesh(file, options = {})
|
|
37
|
+
before_init_call( :mesh, file, options )
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Animations declare helper functions for mesh animations.
|
|
41
|
+
#
|
|
42
|
+
# class AnimatedRubyView < ...
|
|
43
|
+
# mesh :animated_ruby, ...
|
|
44
|
+
# animation "shatter"
|
|
45
|
+
#
|
|
46
|
+
# def initialize
|
|
47
|
+
# shatter # same as animated_ruby.shatter
|
|
48
|
+
# end
|
|
49
|
+
# end
|
|
50
|
+
#
|
|
51
|
+
# options can include any function in animation.rb
|
|
52
|
+
# and :alias => :alias_name
|
|
53
|
+
def animation(name, options = {})
|
|
54
|
+
play_alias = options.delete(:alias)
|
|
55
|
+
before_init_call(:animation, name, options)
|
|
56
|
+
unless play_alias.nil?
|
|
57
|
+
before_init_call(:animation_alias, name, play_alias)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
module InstanceMethods
|
|
63
|
+
|
|
64
|
+
def unload!
|
|
65
|
+
meshes.each { |mesh| mesh.remove_from_scene }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
#Note that this method is very similiar to ShatteredController::Actor.
|
|
69
|
+
#And that a common function can be refactored from both.
|
|
70
|
+
def method_missing(method, *args)
|
|
71
|
+
super(method,*args) if !method_defined?(method)
|
|
72
|
+
retv=nil
|
|
73
|
+
meshes.each do |mesh|
|
|
74
|
+
retv =mesh.send(method, *args) if mesh.method_defined? method
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
return retv
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def method_defined?(method)
|
|
81
|
+
meshes.each { |mesh| return true if mesh.method_defined? method }
|
|
82
|
+
return super(method)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
private
|
|
86
|
+
|
|
87
|
+
def mesh(file, options={})
|
|
88
|
+
mesh = Mesh.new(file)
|
|
89
|
+
name = mesh.name
|
|
90
|
+
attr_reader name.to_sym, mesh
|
|
91
|
+
|
|
92
|
+
call_object_function_for_each_key(name, options)
|
|
93
|
+
#keep track of the meshes we create
|
|
94
|
+
@meshes ||= []
|
|
95
|
+
@meshes << mesh
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def meshes
|
|
99
|
+
@meshes ||= []
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def animation(name, options={})
|
|
103
|
+
meshes.each do |mesh|
|
|
104
|
+
mesh.instance_eval <<-EOF
|
|
105
|
+
class << self
|
|
106
|
+
define_method(:#{name}) do
|
|
107
|
+
animation(:#{name})
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
EOF
|
|
111
|
+
call_object_function_for_each_key(:"#{mesh.name}.#{name}", options)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def animation_alias(name, renamed)
|
|
116
|
+
define_method(renamed.to_sym) do
|
|
117
|
+
meshes.each do |mesh|
|
|
118
|
+
mesh.animation(name.to_sym).play
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
protected
|
|
125
|
+
def mesh_public_methods
|
|
126
|
+
methods=[]
|
|
127
|
+
meshes.each do |mesh|
|
|
128
|
+
methods |= mesh.public_methods
|
|
129
|
+
end
|
|
130
|
+
return methods
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# This Mesh class corresponds (almost 1 to 1) with ShatteredOgre's mesh class
|
|
135
|
+
class Mesh < ShatteredView::Node
|
|
136
|
+
attr_reader :name
|
|
137
|
+
|
|
138
|
+
def initialize( file, options = {} )
|
|
139
|
+
@name = file.underscore
|
|
140
|
+
unless defined?(TESTING)
|
|
141
|
+
@scene_object = ShatteredOgre::Scene.getSingleton.createMesh( [0,0,0].to_v3, "#{file}.mesh" )
|
|
142
|
+
puts "Loading Mesh: #{@scene_object} from #{:file}.mesh"
|
|
143
|
+
populate_animations
|
|
144
|
+
else
|
|
145
|
+
@scene_object = MockObject.new
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
# This is overriden from ShatteredSupport's extension to Object
|
|
149
|
+
# missing alias's
|
|
150
|
+
def method_defined?( method )
|
|
151
|
+
return (super(method) or @animations.include?(method))
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# Access a given animation. Returns nil on failure.
|
|
155
|
+
def animation( animation )
|
|
156
|
+
return @animations[animation]
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
private
|
|
161
|
+
|
|
162
|
+
# populate_animations queries ShatteredOgre and adds the found animations to the mesh.
|
|
163
|
+
def populate_animations
|
|
164
|
+
@animations = {}
|
|
165
|
+
(0...@scene_object.getNumberOfAnimations).each do |idx|
|
|
166
|
+
name = @scene_object.getAnimationName(idx)
|
|
167
|
+
@animations[name.downcase.to_sym] = ShatteredView::Animation.new(@scene_object, name)
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
data/lib/node.rb
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
module ShatteredView
|
|
2
|
+
class Node
|
|
3
|
+
|
|
4
|
+
# Remove the Ogre Mesh from the scene
|
|
5
|
+
def remove_from_scene
|
|
6
|
+
@scene_object.removeFromScene
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def position=( *array )
|
|
10
|
+
array = array[0] if(array.length == 1)
|
|
11
|
+
@scene_object.setPosition array.to_v3
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# uses #look_at
|
|
15
|
+
def looking_at=( *look_toward )
|
|
16
|
+
look_toward = look_toward[0] if(look_toward.length == 1)
|
|
17
|
+
look_at(look_toward)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def position
|
|
21
|
+
@scene_object.getPosition.to_v
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# look_at a Vector, Mesh, or Actor.
|
|
25
|
+
def look_at( position )
|
|
26
|
+
position = position.position unless position.is_a?(ShatteredOgre::Vector3) || position.is_a?(Vector) || position.is_a?(Array)
|
|
27
|
+
position = position.to_v3 unless position.is_a?(ShatteredOgre::Vector3)
|
|
28
|
+
@scene_object.lookAt(position)
|
|
29
|
+
# raise ArgumentError, "#{position.inspect} is not a Mesh, Actor, or Vector."
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# rotate along axis, degrees amount
|
|
33
|
+
def rotate( axis, degrees )
|
|
34
|
+
axis = axis.to_v.normalize
|
|
35
|
+
@scene_object.rotate(axis.to_v3, degrees)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def rotation=(axis, degrees)
|
|
39
|
+
rotate axis, degrees
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def scale=(*scale)
|
|
43
|
+
scale = scale[0] if scale.length == 1
|
|
44
|
+
scale = [scale, scale, scale].to_v if scale.kind_of?(Numeric)
|
|
45
|
+
scale = scale.to_v
|
|
46
|
+
|
|
47
|
+
@scene_object.scale scale.to_v3
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def scale(amount)
|
|
51
|
+
amount = amount.to_v3 unless amount.is_a? Fixnum
|
|
52
|
+
@scene_object.scale amount
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def material=( material )
|
|
56
|
+
if material.is_a? RMaterial
|
|
57
|
+
@scene_object.generateTangents if material.tangent_space
|
|
58
|
+
material = material.name
|
|
59
|
+
end
|
|
60
|
+
@scene_object.setMaterial(material.to_s)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def visible=(visible)
|
|
64
|
+
@scene_object.setVisible(visible)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
end
|
data/lib/resources.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
require 'singleton'
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
module ShatteredView
|
|
5
4
|
# Resource Handler is the ruby binding around Ogre's resource handler
|
|
6
5
|
# It provides all types of shortcuts for finding files and adding new paths.
|
|
@@ -15,10 +14,10 @@ module ShatteredView
|
|
|
15
14
|
|
|
16
15
|
def add_resource_paths(*paths)
|
|
17
16
|
paths.each do |path|
|
|
18
|
-
path = SHATTERED_ROOT + path
|
|
17
|
+
path = SHATTERED_ROOT + "/"+path
|
|
19
18
|
@resource_paths << path
|
|
20
19
|
each_directory_in_path(path) do |sub_path|
|
|
21
|
-
ShatteredOgre::ResourceHandler.getSingleton.addResourcePath(sub_path)
|
|
20
|
+
ShatteredOgre::ResourceHandler.getSingleton.addResourcePath(sub_path)
|
|
22
21
|
end
|
|
23
22
|
end
|
|
24
23
|
end
|
|
@@ -30,34 +29,19 @@ module ShatteredView
|
|
|
30
29
|
# This is useful for any extension wanting to load resource files:
|
|
31
30
|
#
|
|
32
31
|
# Usage:
|
|
33
|
-
#
|
|
32
|
+
# Resources.instance.find_files_by_extensions("ogg","mp3","wav")
|
|
34
33
|
def find_files_by_extensions(*extensions)
|
|
35
|
-
|
|
36
|
-
files = []
|
|
37
|
-
@resource_paths.each do |path|
|
|
38
|
-
each_file_in_path(path) do |filename|
|
|
39
|
-
files << filename if filename =~ reg_exp
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
return files
|
|
34
|
+
File.find_by_extensions(@resource_paths,*extensions)
|
|
43
35
|
end
|
|
44
36
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
resource = directory + "/#{filename}"
|
|
49
|
-
yield(resource) if File.file? resource
|
|
50
|
-
end
|
|
51
|
-
end
|
|
37
|
+
# This is deprecated in favor of File.each_in_path
|
|
38
|
+
def each_file_in_path(path, &block)
|
|
39
|
+
File.each_in_path(path, &block)
|
|
52
40
|
end
|
|
53
41
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
full_path = "#{path}/#{directory}"
|
|
58
|
-
yield full_path
|
|
59
|
-
each_directory_in_path(full_path, &block)
|
|
60
|
-
end
|
|
42
|
+
# This is deprecated in favor of Dir.each_in_path
|
|
43
|
+
def each_directory_in_path(path,&block)
|
|
44
|
+
Dir.each_in_path(path, &block)
|
|
61
45
|
end
|
|
62
46
|
end
|
|
63
47
|
end
|
data/lib/runner.rb
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
|
+
require 'erb'
|
|
1
2
|
|
|
2
3
|
module ShatteredView
|
|
3
4
|
class Runner
|
|
4
5
|
def initialize(options = {})
|
|
6
|
+
generate_plugin_config
|
|
5
7
|
Resources.instance.add_resource_paths("/app/views", "/media")
|
|
6
8
|
@renderer = ShatteredOgre::Renderer.new
|
|
7
9
|
raise Error, "Renderer failed to initialize Ogre" if @renderer.failed
|
|
8
10
|
@scene = ShatteredOgre::Scene.new(translate_to_scene_type(options[:scene_manager]))
|
|
9
11
|
end
|
|
12
|
+
def generate_plugin_config
|
|
13
|
+
plugin_directory = SHATTERED_ROOT+"/config/"
|
|
14
|
+
generated_plugin = plugin_directory+ "plugins."
|
|
15
|
+
generator = plugin_directory + "ogre_plugins.rcfg"
|
|
16
|
+
if PLATFORM =~ /mswin/
|
|
17
|
+
generated_plugin += "win32"
|
|
18
|
+
elsif PLATFORM =~ /darwin/
|
|
19
|
+
generated_plugin += "darwin"
|
|
20
|
+
else
|
|
21
|
+
generated_plugin += "linux"
|
|
22
|
+
end
|
|
23
|
+
process_plugin(generator, generated_plugin+".cfg")
|
|
24
|
+
end
|
|
25
|
+
def process_plugin(base, generate_to)
|
|
26
|
+
puts "Generating #{generate_to} from #{base}, #{File.exists?(base)}"
|
|
27
|
+
return unless File.exists?(base)
|
|
28
|
+
generated_banner = "\n\r//=== This file is generated. Modify the .rcfg instead. ===\n\r\n\r"
|
|
29
|
+
to_write = generated_banner + ERB.new(File.open(base,"r").read).result + generated_banner
|
|
30
|
+
output = File.open(generate_to, "w")
|
|
31
|
+
output.syswrite(to_write)
|
|
32
|
+
output.close
|
|
33
|
+
end
|
|
10
34
|
def translate_to_scene_type( symbol )
|
|
11
35
|
return ShatteredOgre::Scene::Generic if(symbol == :general)
|
|
12
36
|
return ShatteredOgre::Scene::Terrain if(symbol == :terrain)
|
data/lib/shattered_view.rb
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
require "active_support"
|
|
2
1
|
["shattered_support","shattered_ogre"].each do |dependency|
|
|
3
2
|
begin
|
|
4
|
-
# require File.dirname(__FILE__)+"/../../#{dependency}/lib/#{dependency}"
|
|
5
|
-
#shattered_ogre is not getting included????
|
|
6
3
|
require dependency
|
|
7
|
-
rescue
|
|
4
|
+
rescue LoadError => e
|
|
8
5
|
require 'rubygems'
|
|
9
6
|
require dependency
|
|
10
7
|
end
|
|
11
8
|
end
|
|
12
9
|
|
|
10
|
+
raise( ShatteredSupport::Error, "Could not find ShatteredOgre (a ShatteredView dependency)" ) if not defined? ShatteredOgre
|
|
11
|
+
|
|
12
|
+
require 'rubygems'
|
|
13
|
+
require "active_support"
|
|
13
14
|
|
|
14
|
-
require File.dirname(__FILE__) + '/animation'
|
|
15
15
|
require File.dirname(__FILE__) + '/utilities'
|
|
16
|
-
require File.dirname(__FILE__) + '/
|
|
16
|
+
require File.dirname(__FILE__) + '/node'
|
|
17
17
|
require File.dirname(__FILE__) + '/camera'
|
|
18
18
|
require File.dirname(__FILE__) + '/extensions'
|
|
19
19
|
require File.dirname(__FILE__) + '/runner'
|
|
20
|
-
require File.dirname(__FILE__) + '/base'
|
|
21
20
|
require File.dirname(__FILE__) + '/rmaterial'
|
|
22
|
-
require File.dirname(__FILE__) + '/
|
|
21
|
+
#require File.dirname(__FILE__) + '/particle_system'
|
|
22
|
+
require File.dirname(__FILE__) + '/base'
|
|
23
|
+
require File.dirname(__FILE__) + '/resources'
|
data/lib/utilities.rb
CHANGED
|
@@ -1,58 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
class Array
|
|
3
|
-
def shuffle; sort_by {rand}; end
|
|
4
|
-
def to_v;
|
|
5
|
-
raise StandardError, "vector #{self.inspect} does not have 3 elements" if self.length < 3
|
|
6
|
-
return Vector3.new(self[0],self[1],self[2]);
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
1
|
module ShatteredView
|
|
11
|
-
class Vector < Array
|
|
12
|
-
def initialize(*args)
|
|
13
|
-
raise ArgumentError, "Vector takes three inputs on initialize" if args.length != 3
|
|
14
|
-
args.each { |value| self << value }
|
|
15
|
-
end
|
|
16
|
-
def +(args)
|
|
17
|
-
return (self.to_v + args.to_v).to_a
|
|
18
|
-
end
|
|
19
|
-
def -(args)
|
|
20
|
-
return (self.to_v - args.to_v).to_a
|
|
21
|
-
end
|
|
22
|
-
def *(value)
|
|
23
|
-
return (self.to_v*value).to_a
|
|
24
|
-
end
|
|
25
|
-
def x
|
|
26
|
-
self[0]
|
|
27
|
-
end
|
|
28
|
-
def y
|
|
29
|
-
self[1]
|
|
30
|
-
end
|
|
31
|
-
def z
|
|
32
|
-
self[2]
|
|
33
|
-
end
|
|
34
|
-
# def x=(ix)
|
|
35
|
-
# self[0] = ix
|
|
36
|
-
# end
|
|
37
|
-
# def y=(iy)
|
|
38
|
-
# self[1] = iy
|
|
39
|
-
# end
|
|
40
|
-
# def z=(iz)
|
|
41
|
-
# self[2] = iz
|
|
42
|
-
# end
|
|
43
|
-
end
|
|
44
2
|
class MockObject
|
|
45
3
|
def method_missing(sym, *args)
|
|
46
4
|
MockObject.new
|
|
47
5
|
end
|
|
48
6
|
end
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
# class Vector3
|
|
52
|
-
# def to_s
|
|
53
|
-
# return "(#{x},#{y},#{z})"
|
|
54
|
-
# end
|
|
55
|
-
# end
|
|
56
|
-
|
|
57
|
-
|
|
58
7
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
|
-
rubygems_version: 0.8.
|
|
2
|
+
rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
|
4
4
|
name: shattered_view
|
|
5
5
|
version: !ruby/object:Gem::Version
|
|
6
|
-
version:
|
|
7
|
-
date: 2006-
|
|
6
|
+
version: 0.3.1
|
|
7
|
+
date: 2006-05-16
|
|
8
8
|
summary: "Shattered View: Manipulates OGRE in a ruby-esque fashion."
|
|
9
9
|
require_paths:
|
|
10
|
-
- lib
|
|
10
|
+
- lib
|
|
11
11
|
email:
|
|
12
12
|
homepage: http://www.hastilymade.com
|
|
13
13
|
rubyforge_project:
|
|
@@ -18,39 +18,32 @@ bindir: bin
|
|
|
18
18
|
has_rdoc: "true"
|
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
20
20
|
requirements:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
-
|
|
22
|
+
- ">"
|
|
23
|
+
- !ruby/object:Gem::Version
|
|
24
|
+
version: 0.0.0
|
|
24
25
|
version:
|
|
25
26
|
platform: ruby
|
|
26
|
-
signing_key:
|
|
27
|
-
cert_chain:
|
|
28
27
|
authors: []
|
|
29
|
-
|
|
30
28
|
files:
|
|
31
|
-
- lib/
|
|
32
|
-
- lib/
|
|
33
|
-
- lib/
|
|
34
|
-
- lib/
|
|
35
|
-
- lib/
|
|
36
|
-
- lib/
|
|
37
|
-
- lib/
|
|
38
|
-
- lib/
|
|
39
|
-
- lib/
|
|
40
|
-
- lib/
|
|
41
|
-
- lib/
|
|
42
|
-
- lib/
|
|
29
|
+
- lib/base.rb
|
|
30
|
+
- lib/camera.rb
|
|
31
|
+
- lib/extensions.rb
|
|
32
|
+
- lib/game.rb
|
|
33
|
+
- lib/light.rb
|
|
34
|
+
- lib/node.rb
|
|
35
|
+
- lib/resources.rb
|
|
36
|
+
- lib/rmaterial.rb
|
|
37
|
+
- lib/runner.rb
|
|
38
|
+
- lib/shattered_view.rb
|
|
39
|
+
- lib/utilities.rb
|
|
40
|
+
- lib/mesh/animation.rb
|
|
41
|
+
- lib/mesh/mesh.rb
|
|
43
42
|
test_files: []
|
|
44
|
-
|
|
45
43
|
rdoc_options: []
|
|
46
|
-
|
|
47
44
|
extra_rdoc_files: []
|
|
48
|
-
|
|
49
45
|
executables: []
|
|
50
|
-
|
|
51
46
|
extensions: []
|
|
52
|
-
|
|
53
47
|
requirements:
|
|
54
|
-
- Shattered View is reliant on OGRE.
|
|
55
|
-
dependencies: []
|
|
56
|
-
|
|
48
|
+
- Shattered View is reliant on OGRE.
|
|
49
|
+
dependencies: []
|
data/lib/mesh.rb
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
module ShatteredView
|
|
3
|
-
class Mesh
|
|
4
|
-
def remove_from_scene
|
|
5
|
-
@scene_object.removeFromScene
|
|
6
|
-
end
|
|
7
|
-
def initialize( options = {} )
|
|
8
|
-
if options[:test] != true
|
|
9
|
-
puts "Loading Mesh: #{@scene_object} from #{options[:file]}.mesh"
|
|
10
|
-
@scene_object = Scene.getSingleton.createMesh( Vector3.new(0,0,0), "#{options[:file]}.mesh" )
|
|
11
|
-
populate_animations
|
|
12
|
-
else
|
|
13
|
-
@scene_object = MockObject.new
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
def populate_animations
|
|
17
|
-
@animations = {}
|
|
18
|
-
(0...@scene_object.getNumberOfAnimations).each do |idx|
|
|
19
|
-
name = @scene_object.getAnimationName(idx)
|
|
20
|
-
@animations[name.downcase.to_sym] = ShatteredView::Animation.new(@scene_object, name)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
def position=( *array )
|
|
24
|
-
array = array[0] if(array.length == 1)
|
|
25
|
-
@scene_object.setPosition array.to_v
|
|
26
|
-
end
|
|
27
|
-
def looking_at=( *look_toward )
|
|
28
|
-
look_toward = look_toward[0] if(look_toward.length == 1)
|
|
29
|
-
look_at(look_toward)
|
|
30
|
-
end
|
|
31
|
-
def position
|
|
32
|
-
@scene_object.getPosition.to_a
|
|
33
|
-
end
|
|
34
|
-
def look_at( position )
|
|
35
|
-
if position.is_a?(Array)
|
|
36
|
-
@scene_object.lookAt(position.to_v)
|
|
37
|
-
elsif position.is_a?(ShatteredOgre::Vector3)
|
|
38
|
-
@scene_object.lookAt(position)
|
|
39
|
-
elsif(position.is_a?(Mesh) || position.is_a?(Actor))
|
|
40
|
-
@scene_object.lookAt(position.position.to_v)
|
|
41
|
-
elsif position.is_a?(ShatteredOgre::Vector3)
|
|
42
|
-
else
|
|
43
|
-
raise ArgumentError, "#{position.inspect} is not a Mesh, Actor, or Vector."
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
def rotate( axis, degrees )
|
|
47
|
-
@scene_object.rotate(axis.to_v, degrees)
|
|
48
|
-
end
|
|
49
|
-
def rotation=(axis, degrees)
|
|
50
|
-
rotate axis, degrees
|
|
51
|
-
end
|
|
52
|
-
def animation( animation )
|
|
53
|
-
return @animations[animation]
|
|
54
|
-
end
|
|
55
|
-
def scale=( *scale )
|
|
56
|
-
if(scale.length == 1)
|
|
57
|
-
scale=scale[0]
|
|
58
|
-
@scene_object.scale( [scale,scale,scale].to_v )
|
|
59
|
-
else
|
|
60
|
-
@scene_object.scale( scale.to_v )
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
def material=( material )
|
|
64
|
-
if material.is_a? RMaterial
|
|
65
|
-
@scene_object.generateTangents if material.tangent_space
|
|
66
|
-
material = material.name
|
|
67
|
-
end
|
|
68
|
-
@scene_object.setMaterial(material.to_s)
|
|
69
|
-
end
|
|
70
|
-
def visible=(visible)
|
|
71
|
-
@scene_object.setVisible(visible)
|
|
72
|
-
end
|
|
73
|
-
# This is overriden from ShatteredSupport's extension to Object
|
|
74
|
-
# missing alias's
|
|
75
|
-
def method_defined?( method )
|
|
76
|
-
return (super(method) or @animations.include?(method))
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|