blackbook3d 0.5.0
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.
- checksums.yaml +7 -0
- data/LICENSE +341 -0
- data/README.md +92 -0
- data/SETUP.md +70 -0
- data/data/assets/Texture/A011a.tga +0 -0
- data/data/assets/untitled.awp3d +0 -0
- data/data/cube.mtl +12 -0
- data/data/cube.obj +246 -0
- data/data/cube.raw +12 -0
- data/data/engine_conf.json +9 -0
- data/data/fighter.raw +19198 -0
- data/data/font/100.raw +78 -0
- data/data/font/101.raw +99 -0
- data/data/font/102.raw +58 -0
- data/data/font/103.raw +258 -0
- data/data/font/104.raw +55 -0
- data/data/font/105.raw +48 -0
- data/data/font/106.raw +72 -0
- data/data/font/107.raw +6 -0
- data/data/font/108.raw +2 -0
- data/data/font/109.raw +105 -0
- data/data/font/110.raw +55 -0
- data/data/font/111.raw +96 -0
- data/data/font/112.raw +78 -0
- data/data/font/113.raw +78 -0
- data/data/font/114.raw +53 -0
- data/data/font/115.raw +132 -0
- data/data/font/116.raw +56 -0
- data/data/font/117.raw +54 -0
- data/data/font/118.raw +5 -0
- data/data/font/119.raw +11 -0
- data/data/font/120.raw +10 -0
- data/data/font/121.raw +6 -0
- data/data/font/122.raw +6 -0
- data/data/font/33.raw +118 -0
- data/data/font/37.raw +194 -0
- data/data/font/38.raw +200 -0
- data/data/font/39.raw +4 -0
- data/data/font/40.raw +48 -0
- data/data/font/41.raw +48 -0
- data/data/font/42.raw +226 -0
- data/data/font/43.raw +10 -0
- data/data/font/45.raw +2 -0
- data/data/font/46.raw +46 -0
- data/data/font/47.raw +2 -0
- data/data/font/48.raw +96 -0
- data/data/font/49.raw +2 -0
- data/data/font/50.raw +87 -0
- data/data/font/51.raw +145 -0
- data/data/font/52.raw +15 -0
- data/data/font/53.raw +76 -0
- data/data/font/54.raw +121 -0
- data/data/font/55.raw +4 -0
- data/data/font/56.raw +194 -0
- data/data/font/57.raw +133 -0
- data/data/font/61.raw +4 -0
- data/data/font/63.raw +117 -0
- data/data/font/65.raw +11 -0
- data/data/font/66.raw +108 -0
- data/data/font/67.raw +96 -0
- data/data/font/68.raw +54 -0
- data/data/font/69.raw +10 -0
- data/data/font/70.raw +8 -0
- data/data/font/71.raw +100 -0
- data/data/font/72.raw +10 -0
- data/data/font/73.raw +2 -0
- data/data/font/74.raw +39 -0
- data/data/font/75.raw +9 -0
- data/data/font/76.raw +4 -0
- data/data/font/77.raw +13 -0
- data/data/font/78.raw +8 -0
- data/data/font/79.raw +96 -0
- data/data/font/80.raw +56 -0
- data/data/font/81.raw +124 -0
- data/data/font/82.raw +94 -0
- data/data/font/83.raw +120 -0
- data/data/font/84.raw +6 -0
- data/data/font/85.raw +76 -0
- data/data/font/86.raw +5 -0
- data/data/font/87.raw +11 -0
- data/data/font/88.raw +10 -0
- data/data/font/89.raw +7 -0
- data/data/font/90.raw +6 -0
- data/data/font/91.raw +6 -0
- data/data/font/93.raw +6 -0
- data/data/font/94.raw +5 -0
- data/data/font/95.raw +2 -0
- data/data/font/97.raw +174 -0
- data/data/font/98.raw +100 -0
- data/data/font/99.raw +96 -0
- data/data/ground.raw +12 -0
- data/data/man.mtl +12 -0
- data/data/man.obj +7547 -0
- data/data/robo.mtl +11 -0
- data/data/robo.obj +42065 -0
- data/data/space.json +49 -0
- data/data/sphere.raw +1216 -0
- data/data/texture/Charcoal-2.jpg +0 -0
- data/data/texture/man.png +0 -0
- data/data/texture/man.tif +0 -0
- data/data/texture/t.jpg +0 -0
- data/data/texture/wood.jpg +0 -0
- data/data/texture/wood.png +0 -0
- data/data/texture/x.jpg +0 -0
- data/data/untitled.raw +124 -0
- data/data/w.raw +12474 -0
- data/data/wings.raw +45670 -0
- data/lib/BlackBook/anim.rb +184 -0
- data/lib/BlackBook/b3dobject.rb +475 -0
- data/lib/BlackBook/base.rb +79 -0
- data/lib/BlackBook/camera.rb +202 -0
- data/lib/BlackBook/color.rb +29 -0
- data/lib/BlackBook/constants.rb +327 -0
- data/lib/BlackBook/engine.rb +172 -0
- data/lib/BlackBook/functions.rb +650 -0
- data/lib/BlackBook/light.rb +91 -0
- data/lib/BlackBook/logger.rb +86 -0
- data/lib/BlackBook/material.rb +98 -0
- data/lib/BlackBook/registry.rb +71 -0
- data/lib/BlackBook/space.rb +396 -0
- data/lib/BlackBook/stime.rb +64 -0
- data/lib/Plugins/string_color.rb +74 -0
- data/lib/blackbook/version.rb +5 -0
- data/lib/blackbook.rb +52 -0
- data/lib/plugins.rb +32 -0
- data/lib/ui/button.rb +115 -0
- data/lib/ui/edit.rb +105 -0
- data/lib/ui/text.rb +284 -0
- data/lib/ui/ui.rb +88 -0
- data/lib/ui/ui_element.rb +45 -0
- data/lib/ui/window.rb +138 -0
- data/lib/ui.rb +30 -0
- data/lib/zipfile.rb +27 -0
- metadata +254 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
##############################################################################
|
|
2
|
+
# BlackBook 3D Engine
|
|
3
|
+
# Copyright (C) 2015 Sinan ISLEKDEMIR
|
|
4
|
+
#
|
|
5
|
+
# This program is free software; you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License along
|
|
16
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
17
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18
|
+
##############################################################################
|
|
19
|
+
|
|
20
|
+
################################################################
|
|
21
|
+
# Project BlackBook
|
|
22
|
+
# Lead Engineer: Sinan ISLEKDEMIR
|
|
23
|
+
# Simulation Engine Ruby Sources
|
|
24
|
+
################################################################
|
|
25
|
+
|
|
26
|
+
require 'opengl'
|
|
27
|
+
require 'pp'
|
|
28
|
+
require 'json'
|
|
29
|
+
require 'securerandom' # Ruby 1.9 and above
|
|
30
|
+
|
|
31
|
+
# Local Libs
|
|
32
|
+
require 'BlackBook/constants'
|
|
33
|
+
require 'BlackBook/functions'
|
|
34
|
+
require 'BlackBook/camera'
|
|
35
|
+
require 'BlackBook/base'
|
|
36
|
+
require 'BlackBook/light'
|
|
37
|
+
require 'ui/ui'
|
|
38
|
+
|
|
39
|
+
require 'thread'
|
|
40
|
+
class AkumaThread
|
|
41
|
+
attr_accessor :thread_id
|
|
42
|
+
@@funcs = []
|
|
43
|
+
def initialize()
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def func_register ( func, param )
|
|
48
|
+
@@funcs << Thread.new { func.call(param) }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def get_threads()
|
|
52
|
+
@@funcs
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
module BlackBook
|
|
57
|
+
#
|
|
58
|
+
# BB Space Class. Holds main scene elements.
|
|
59
|
+
# There can be more than one space in an engine and more than one cameras
|
|
60
|
+
# In every Space
|
|
61
|
+
#
|
|
62
|
+
# @author [sinan]
|
|
63
|
+
#
|
|
64
|
+
# @attr width [Integer] Space Viewport Width
|
|
65
|
+
# @attr heigh [Integer] Space Viewport Height
|
|
66
|
+
# @attr gl_active [Boolean] OpelGL Activated
|
|
67
|
+
# @attr multiplier [Float] Viewport - Window Multiplier
|
|
68
|
+
# @attr items [Hash] Hash of items
|
|
69
|
+
#
|
|
70
|
+
|
|
71
|
+
class Space < Base
|
|
72
|
+
attr_accessor :width, :height, :gl_active, :muliplier, :items, :counter
|
|
73
|
+
|
|
74
|
+
# Initialize scene,
|
|
75
|
+
# set lights, init opengl
|
|
76
|
+
# set perspective
|
|
77
|
+
def initialize(w, h, m = 1)
|
|
78
|
+
super
|
|
79
|
+
@counter = 0 #added darkspy
|
|
80
|
+
|
|
81
|
+
@muliplier = m
|
|
82
|
+
@gl_active = false
|
|
83
|
+
@width = w
|
|
84
|
+
@height = h
|
|
85
|
+
@items = {
|
|
86
|
+
cameras: [],
|
|
87
|
+
lights: [],
|
|
88
|
+
objects: {},
|
|
89
|
+
uis: [],
|
|
90
|
+
plugins: [],
|
|
91
|
+
frames: {} # darkspy added
|
|
92
|
+
}
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
#
|
|
96
|
+
# Create camera with given parameters
|
|
97
|
+
# @param options [Hash] BBCamera Options (see BBCamera#initialize)
|
|
98
|
+
#
|
|
99
|
+
# @return [Camera] Camera object
|
|
100
|
+
def add_camera( opts = {} )
|
|
101
|
+
camera = Camera.new(opts)
|
|
102
|
+
@items[:cameras].push camera
|
|
103
|
+
camera
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
#
|
|
107
|
+
# Create a new scene camera and add it to the scene hash
|
|
108
|
+
#
|
|
109
|
+
# @return [Camera] Camera object
|
|
110
|
+
def create_camera
|
|
111
|
+
camera = Camera.new(
|
|
112
|
+
eye_position: CVector.new(10.0, 10.0, 10.0),
|
|
113
|
+
target_position: CVector.new(0, 0, 0),
|
|
114
|
+
up: CVector.new(0.0, 0.0, 1.0)
|
|
115
|
+
)
|
|
116
|
+
@items[:cameras].push camera
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
#
|
|
120
|
+
# Add new object
|
|
121
|
+
# @param options [Hash] Options of new object
|
|
122
|
+
# :filename => Raw file, filename
|
|
123
|
+
# :roll => Roll angle
|
|
124
|
+
# :pitch => Pitch angle
|
|
125
|
+
# :yaw => Yaw angle
|
|
126
|
+
# :position => CVector
|
|
127
|
+
# :time => Time float
|
|
128
|
+
# :name => Name of the object
|
|
129
|
+
# :scale => Scale CVector
|
|
130
|
+
#
|
|
131
|
+
# @return [BB3DObject] 3D Object
|
|
132
|
+
def add_object( opts = {} )
|
|
133
|
+
obj = B3DObject.new
|
|
134
|
+
if opts[:filename]
|
|
135
|
+
ext = File.extname(opts[:filename])
|
|
136
|
+
case ext
|
|
137
|
+
when '.raw'
|
|
138
|
+
obj.load_raw(opts[:filename])
|
|
139
|
+
when '.obj'
|
|
140
|
+
obj.load_obj(opts[:filename])
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
obj.matrix.position = opts[:position] if opts[:position]
|
|
144
|
+
obj.time = opts[:time] if opts[:time]
|
|
145
|
+
name = opts[:name] || SecureRandom.uuid
|
|
146
|
+
obj.name = name
|
|
147
|
+
obj.scale = options[:scale] if opts[:scale]
|
|
148
|
+
@items[:objects][name] = obj
|
|
149
|
+
obj
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
#
|
|
153
|
+
# Add new animation object
|
|
154
|
+
# export from export tool for blender > 2.9
|
|
155
|
+
# named: exporter.py
|
|
156
|
+
# @param options [Hash] Options of new object
|
|
157
|
+
# :filename => Raw file, filename
|
|
158
|
+
# :roll => Roll angle
|
|
159
|
+
# :pitch => Pitch angle
|
|
160
|
+
# :yaw => Yaw angle
|
|
161
|
+
# :position => CVector
|
|
162
|
+
# :time => Time float
|
|
163
|
+
# :name => Name of the object
|
|
164
|
+
# :scale => Scale CVector
|
|
165
|
+
#
|
|
166
|
+
# @return [BB3DObject] 3D Object
|
|
167
|
+
|
|
168
|
+
def add_object_anim( opts = {} ) #
|
|
169
|
+
anim_obj = opts[:anim]
|
|
170
|
+
objs = []
|
|
171
|
+
lc = 0
|
|
172
|
+
osave = ''
|
|
173
|
+
@anim_frame_max = anim_obj.frames.length
|
|
174
|
+
anim_obj.frames.each do |fname|
|
|
175
|
+
obj = B3DObject.new
|
|
176
|
+
|
|
177
|
+
ext = File.extname(fname)
|
|
178
|
+
case ext
|
|
179
|
+
when '.raw'
|
|
180
|
+
obj.load_raw(fname)
|
|
181
|
+
when '.obj'
|
|
182
|
+
obj.load_obj(fname)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
obj.matrix.position = opts[:position] if opts[:position]
|
|
186
|
+
obj.time = opts[:time] if opts[:time]
|
|
187
|
+
name = opts[:name] || SecureRandom.uuid
|
|
188
|
+
#puts "name generated #{name}"
|
|
189
|
+
#name = "___anim_"+name #added darkspy
|
|
190
|
+
obj.name = name
|
|
191
|
+
obj.scale = opts[:scale] if opts[:scale]
|
|
192
|
+
if lc == 0
|
|
193
|
+
#obj.material.load_texture(options[:texture]) if options.key?(:texture)
|
|
194
|
+
obj.material.load_texture(anim_obj.texture_name) if anim_obj.texture_name.length > 0
|
|
195
|
+
osave = obj
|
|
196
|
+
else
|
|
197
|
+
obj.material = osave.material
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
@items[:frames][name] = obj#tmp #[name] = obj
|
|
201
|
+
@items[:frames][lc] = obj
|
|
202
|
+
#@items[:frames][index] = obj
|
|
203
|
+
lc += 1
|
|
204
|
+
objs << obj
|
|
205
|
+
puts "#{fname} loaded , #{lc-1} of #{@anim_frame_max}"
|
|
206
|
+
end #end of do
|
|
207
|
+
@items[:frames]["max"] = lc
|
|
208
|
+
puts "gen animate over"
|
|
209
|
+
objs
|
|
210
|
+
end
|
|
211
|
+
#
|
|
212
|
+
# Create a dummy object
|
|
213
|
+
#
|
|
214
|
+
# @return [BB3DObject] 3D Object
|
|
215
|
+
def create_object
|
|
216
|
+
obj = B3DObject.new
|
|
217
|
+
name = SecureRandom.uuid
|
|
218
|
+
@items[:objects][name] = obj
|
|
219
|
+
obj
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
#
|
|
223
|
+
# Add Light
|
|
224
|
+
# @param options [Hash] Light Properties
|
|
225
|
+
#
|
|
226
|
+
# @return [Boolean] Success
|
|
227
|
+
def add_light(options)
|
|
228
|
+
light = Light.new(options)
|
|
229
|
+
@items[:lights].push light
|
|
230
|
+
light
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
#
|
|
234
|
+
# Create a default light
|
|
235
|
+
#
|
|
236
|
+
# @return [BBLight]
|
|
237
|
+
def create_light
|
|
238
|
+
light = Light.new({})
|
|
239
|
+
@items[:lights].push light
|
|
240
|
+
light
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
#
|
|
244
|
+
# Create a UI Interface Object
|
|
245
|
+
#
|
|
246
|
+
# @return [type] [description]
|
|
247
|
+
def create_ui
|
|
248
|
+
ui = UI::Ui.new(@width, @height)
|
|
249
|
+
@items[:uis].push ui
|
|
250
|
+
ui
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
#
|
|
254
|
+
# Initialize OpenGL
|
|
255
|
+
#
|
|
256
|
+
# @return [Boolean] Initialize main OpenGL Variables
|
|
257
|
+
def init_gl
|
|
258
|
+
GL.Viewport(0, 0, @width, @height)
|
|
259
|
+
GL.ClearDepth(1.0)
|
|
260
|
+
GL.DepthFunc(GL::LESS)
|
|
261
|
+
GL.Enable(GL::DEPTH_TEST)
|
|
262
|
+
GL.Enable(GL::MULTISAMPLE)
|
|
263
|
+
GL.ShadeModel(GL::SMOOTH)
|
|
264
|
+
GL.MatrixMode(GL::PROJECTION)
|
|
265
|
+
GL.LoadIdentity
|
|
266
|
+
BlackBook.perspective(30.0, @width.to_f / @height.to_f, 1.0, 1000.0)
|
|
267
|
+
GL.MatrixMode(GL::MODELVIEW)
|
|
268
|
+
GL.ClearColor(0.05, 0.05, 0.1, 1.0)
|
|
269
|
+
@gl_active = true
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
#
|
|
273
|
+
# Update viewport and projection when window resizes
|
|
274
|
+
#
|
|
275
|
+
# @param w [Integer] New width
|
|
276
|
+
# @param h [Integer] New height
|
|
277
|
+
# @return [Boolean] Success
|
|
278
|
+
def resize(w, h)
|
|
279
|
+
@width = w
|
|
280
|
+
@height = h
|
|
281
|
+
GL.Viewport(0, 0, @width, @height)
|
|
282
|
+
GL.MatrixMode(GL::PROJECTION)
|
|
283
|
+
GL.LoadIdentity
|
|
284
|
+
BlackBook.perspective(30.0, @width.to_f / @height.to_f, 1.0, 1000.0)
|
|
285
|
+
GL.MatrixMode(GL::MODELVIEW)
|
|
286
|
+
@items[:uis].each do |ui|
|
|
287
|
+
ui.w = w
|
|
288
|
+
ui.h = h
|
|
289
|
+
end
|
|
290
|
+
true
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
#
|
|
294
|
+
# Main Mouse Move Handler for Space
|
|
295
|
+
# 1. Mouse move for each plugin
|
|
296
|
+
# 2. Mouse move for each ui
|
|
297
|
+
# 3. Mouse move for each camera
|
|
298
|
+
#
|
|
299
|
+
# @param x [Integer] Mouse X Axis Value
|
|
300
|
+
# @param y [Integer] Mouse Y Axis Value
|
|
301
|
+
# @param right_b [Integer] Right Mouse Button
|
|
302
|
+
# @param left_b [Integer] Left Mouse Button
|
|
303
|
+
# @param middle_b [Integer] Middle Mouse Button
|
|
304
|
+
#
|
|
305
|
+
# @return [Boolean] Success
|
|
306
|
+
def mouse_move(x, y, right_b, left_b, middle_b)
|
|
307
|
+
x *= @muliplier
|
|
308
|
+
y *= @muliplier
|
|
309
|
+
@items[:plugins].each do |plugin|
|
|
310
|
+
if plugin.respond_to('mouse_move')
|
|
311
|
+
plugin.mouse_move(x, y, right_b, left_b, middle_b)
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
@items[:uis].each do |ui|
|
|
315
|
+
return true if ui.mouse_move(x, y, right_b, left_b, middle_b)
|
|
316
|
+
end
|
|
317
|
+
@items[:cameras].each do |camera|
|
|
318
|
+
camera.mouse_move(x, y, right_b, left_b, middle_b)
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def render_anim window=nil #added darkspy
|
|
323
|
+
# Render Plugin Cameras
|
|
324
|
+
last = @items[:frames]["max"]
|
|
325
|
+
#puts @counter, last
|
|
326
|
+
@items[:frames][@counter].render
|
|
327
|
+
|
|
328
|
+
if @counter >= last-1
|
|
329
|
+
@counter = 0
|
|
330
|
+
else
|
|
331
|
+
@counter+=1
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
#
|
|
335
|
+
# General Render Method
|
|
336
|
+
# 1. Render Lights
|
|
337
|
+
# 2. Call Light Methods of Plugins
|
|
338
|
+
# 3. Call Camera Methods of Plugins
|
|
339
|
+
# Make it before real cameras for shaders)
|
|
340
|
+
# 4. Render Cameras
|
|
341
|
+
# 4a. Render Objects
|
|
342
|
+
# 4b. Call Render Methods of Plugins
|
|
343
|
+
# 5. Render UI's
|
|
344
|
+
# 6. Call ui Methods of Plugins
|
|
345
|
+
#
|
|
346
|
+
# @return [type] [description]
|
|
347
|
+
def render window=nil
|
|
348
|
+
# Render Plugin Cameras
|
|
349
|
+
vx, vy, vw, vh=0,0,0,0
|
|
350
|
+
@items[:plugins].each do |plugin|
|
|
351
|
+
plugin.camera if plugin.respond_to?('camera')
|
|
352
|
+
end
|
|
353
|
+
# Render Objects for each camera
|
|
354
|
+
@items[:cameras].each do |cam|
|
|
355
|
+
cam.begin_render
|
|
356
|
+
grid = BlackBook::Registry.instance.read('grid')
|
|
357
|
+
BlackBook.draw_grid if grid
|
|
358
|
+
vx, vy, vw, vh =
|
|
359
|
+
cam.frame_x, cam.frame_y, cam.frame_width, cam.frame_height
|
|
360
|
+
# Render Lights
|
|
361
|
+
@items[:lights].each do |light|
|
|
362
|
+
light.render
|
|
363
|
+
end
|
|
364
|
+
# Render Plugins Lights
|
|
365
|
+
@items[:plugins].each do |plugin|
|
|
366
|
+
plugin.light if plugin.respond_to?('light')
|
|
367
|
+
end
|
|
368
|
+
@items[:objects].each do |name, obj|
|
|
369
|
+
#GL.Enable(GL::SCISSOR_TEST)
|
|
370
|
+
#GL.Scissor(0, 0, 0, 0)
|
|
371
|
+
#GL.Clear(GL::COLOR_BUFFER_BIT)
|
|
372
|
+
#GL.Disable(GL::SCISSOR_TEST)
|
|
373
|
+
#if name.index("__anim") == nil #added darkspy
|
|
374
|
+
obj.render
|
|
375
|
+
|
|
376
|
+
@items[:plugins].each do |plugin|
|
|
377
|
+
plugin.render if plugin.respond_to?('render')
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
cam.end_render
|
|
381
|
+
end
|
|
382
|
+
GL.Viewport(0, 0, @width, @height)
|
|
383
|
+
@items[:uis].each do |ui|
|
|
384
|
+
ui.render
|
|
385
|
+
end
|
|
386
|
+
@items[:plugins].each do |plugin|
|
|
387
|
+
plugin.ui if plugin.respond_to?('ui')
|
|
388
|
+
end
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
def save(filename)
|
|
392
|
+
space_json = JSON.generate(@items)
|
|
393
|
+
File.open(filename, 'w') { |file| file.write(space_json) }
|
|
394
|
+
end
|
|
395
|
+
end
|
|
396
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
##############################################################################
|
|
2
|
+
# BlackBook 3D Engine
|
|
3
|
+
# Copyright (C) 2015 Sinan ISLEKDEMIR
|
|
4
|
+
#
|
|
5
|
+
# This program is free software; you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License along
|
|
16
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
17
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18
|
+
##############################################################################
|
|
19
|
+
|
|
20
|
+
################################################################
|
|
21
|
+
# Project BlackBook
|
|
22
|
+
# Lead Engineer: Sinan ISLEKDEMIR
|
|
23
|
+
# Simulation Engine Ruby Sources
|
|
24
|
+
################################################################
|
|
25
|
+
|
|
26
|
+
module BlackBook
|
|
27
|
+
# Space - Time Class
|
|
28
|
+
class STime
|
|
29
|
+
attr_accessor :year, :days, :seconds, :scale, :start, :diff,
|
|
30
|
+
:last_time
|
|
31
|
+
|
|
32
|
+
# start timer
|
|
33
|
+
def initialize
|
|
34
|
+
@start = @last_time = Time.now.to_f
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# get time difference
|
|
38
|
+
def calc_time
|
|
39
|
+
@diff = Time.now.to_f - @start
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def step
|
|
43
|
+
r = Time.now.to_f - @last_time
|
|
44
|
+
@last_time = Time.now.to_f
|
|
45
|
+
r
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# reset start time
|
|
49
|
+
def reset_time
|
|
50
|
+
@start = Time.now.to_f
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def reset_lasttime
|
|
54
|
+
@last_time = Time.now.to_f
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# calculate time dilation caused by velocity
|
|
58
|
+
def time_dilation(velocity)
|
|
59
|
+
calc_time
|
|
60
|
+
f = (velocity.to_f**2) / (299792458.to_f**2)
|
|
61
|
+
@diff / Math.sqrt(1.0 - f)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Colorize string object
|
|
2
|
+
class String
|
|
3
|
+
def black
|
|
4
|
+
"\033[30m#{self}\033[0m"
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def red
|
|
8
|
+
"\033[31m#{self}\033[0m"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def green
|
|
12
|
+
"\033[32m#{self}\033[0m"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def brown
|
|
16
|
+
"\033[33m#{self}\033[0m"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def blue
|
|
20
|
+
"\033[34m#{self}\033[0m"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def magenta
|
|
24
|
+
"\033[35m#{self}\033[0m"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def cyan
|
|
28
|
+
"\033[36m#{self}\033[0m"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def gray
|
|
32
|
+
"\033[37m#{self}\033[0m"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def bg_black
|
|
36
|
+
"\033[40m#{self}\033[0m"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def bg_red
|
|
40
|
+
"\033[41m#{self}\033[0m"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def bg_green
|
|
44
|
+
"\033[42m#{self}\033[0m"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def bg_brown
|
|
48
|
+
"\033[43m#{self}\033[0m"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def bg_blue
|
|
52
|
+
"\033[44m#{self}\033[0m"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def bg_magenta
|
|
56
|
+
"\033[45m#{self}\033[0m"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def bg_cyan
|
|
60
|
+
"\033[46m#{self}\033[0m"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def bg_gray
|
|
64
|
+
"\033[47m#{self}\033[0m"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def bold
|
|
68
|
+
"\033[1m#{self}\033[22m"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def reverse_color
|
|
72
|
+
"\033[7m#{self}\033[27m"
|
|
73
|
+
end
|
|
74
|
+
end
|
data/lib/blackbook.rb
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
##############################################################################
|
|
2
|
+
# BlackBook 3D Engine
|
|
3
|
+
# Copyright (C) 2015 Sinan ISLEKDEMIR
|
|
4
|
+
#
|
|
5
|
+
# This program is free software; you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License along
|
|
16
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
17
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18
|
+
##############################################################################
|
|
19
|
+
|
|
20
|
+
################################################################
|
|
21
|
+
# Project BlackBook
|
|
22
|
+
# Lead Engineer: Sinan ISLEKDEMIR
|
|
23
|
+
# Simulation Engine Ruby Sources
|
|
24
|
+
################################################################
|
|
25
|
+
|
|
26
|
+
require 'BlackBook/engine'
|
|
27
|
+
require 'BlackBook/base'
|
|
28
|
+
require 'BlackBook/b3dobject'
|
|
29
|
+
require 'BlackBook/camera'
|
|
30
|
+
require 'BlackBook/constants'
|
|
31
|
+
require 'BlackBook/functions'
|
|
32
|
+
require 'BlackBook/light'
|
|
33
|
+
require 'BlackBook/logger'
|
|
34
|
+
require 'BlackBook/space'
|
|
35
|
+
require 'BlackBook/stime'
|
|
36
|
+
require 'BlackBook/material'
|
|
37
|
+
require 'BlackBook/anim'
|
|
38
|
+
# BlackBook main module definition
|
|
39
|
+
module BlackBook
|
|
40
|
+
extend self
|
|
41
|
+
VERSION = '0.0.1'.freeze
|
|
42
|
+
|
|
43
|
+
# Shortcut for BlackBook::Main.new *args
|
|
44
|
+
# BlackBook.loop( w: 800, h: 600, t: 'BlackBook Sample' )
|
|
45
|
+
# BlackBook.loop( width: 800, height: 600, title: '...' )
|
|
46
|
+
def self.loop( opts = {} )
|
|
47
|
+
width = opts[:w] || opts[:width]
|
|
48
|
+
height = opts[:h] || opts[:height]
|
|
49
|
+
title = opts[:t] || opts[:title]
|
|
50
|
+
Main.new( width, height, title ).engine_loop
|
|
51
|
+
end
|
|
52
|
+
end
|
data/lib/plugins.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
##############################################################################
|
|
2
|
+
# BlackBook 3D Engine
|
|
3
|
+
# Copyright (C) 2015 Sinan ISLEKDEMIR
|
|
4
|
+
#
|
|
5
|
+
# This program is free software; you can redistribute it and/or modify
|
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
|
7
|
+
# the Free Software Foundation; either version 2 of the License, or
|
|
8
|
+
# (at your option) any later version.
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU General Public License for more details.
|
|
14
|
+
#
|
|
15
|
+
# You should have received a copy of the GNU General Public License along
|
|
16
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
17
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18
|
+
##############################################################################
|
|
19
|
+
|
|
20
|
+
################################################################
|
|
21
|
+
# Project BlackBook
|
|
22
|
+
# Lead Engineer: Sinan ISLEKDEMIR
|
|
23
|
+
# Simulation Engine Ruby Sources
|
|
24
|
+
################################################################
|
|
25
|
+
|
|
26
|
+
require 'Plugins/string_color'
|
|
27
|
+
|
|
28
|
+
# BlackBook common plugins
|
|
29
|
+
module BlackBookPlugins
|
|
30
|
+
extend self
|
|
31
|
+
VERSION = '0.0.1'.freeze
|
|
32
|
+
end
|