mittsu 0.3.3 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bce7b85c4911927e9f33bb5212d9011122a33356cc8811b33482af05577b9977
4
- data.tar.gz: 23620dc7e242612382df2647df7b45f2a21364543deb0d64e389844d65a069c1
3
+ metadata.gz: 806e8ad78d34edc7dfa72cbe35414c0fe765628b5dd074d691d5bf0f45dd52cb
4
+ data.tar.gz: b477a885ca405bd5ad8b71464b06ce794567c00abceb56738f3ace06885fe4d3
5
5
  SHA512:
6
- metadata.gz: 192b53dca3a2f7ecc79c22cdeae9410d7ce5dcf4af30803d9f0242bdc9caa10cef93cc8a1948932da102cbfe049e6d67951ce983e27ed40f20809fa18b044897
7
- data.tar.gz: d08903f9f798c488b35f52f991e311bdbd2f95427094c10b55c5c6d67570d4956c8616d52ad025b9507945e57a5e3ecbff876c50472317493e778d6819286d8e
6
+ metadata.gz: d65b207aaaf6136a1e6d7fd39237bd5710192748338eb388fd974d4128069cbc41b6df4132bc2597793f507ed7349abdb0f3d28e9df1584ff9d4e1f9a39c8bc2
7
+ data.tar.gz: b4eb049497dc7f46d4285d8d8d677f3221f08d904dcc21b1efa3e7044edea42a1d49e8979d74bd26c3bc9470598fd9755c460865cc324ce71b6c87fec036d07e
@@ -13,25 +13,16 @@ jobs:
13
13
  runs-on: ubuntu-latest
14
14
  strategy:
15
15
  matrix:
16
- ruby: ['2.5.x', '2.6.x', '2.7.x', '3.0.x']
16
+ ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', 'head']
17
17
  steps:
18
- - uses: actions/checkout@v1
19
- - name: Cache gems
20
- uses: actions/cache@v1
18
+ - uses: actions/checkout@v4
19
+ - uses: awalsh128/cache-apt-pkgs-action@v1
21
20
  with:
22
- path: vendor/bundle
23
- key: gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-${{ hashFiles('**/*.gemspec') }}-
24
- restore-keys: |
25
- gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-${{ hashFiles('**/*.gemspec') }}-
26
- gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-
27
- gems-v1-${{ runner.os }}-
28
- - uses: actions/setup-ruby@v1
21
+ packages: libglfw3
22
+ - uses: ruby/setup-ruby@v1
29
23
  with:
30
24
  ruby-version: ${{ matrix.ruby }}
31
- - run: sudo apt-get update; sudo apt-get install cmake xorg-dev libgl1-mesa-dev
32
- - run: bash install-glfw.sh
33
- - run: gem install bundler
34
- - run: bundle install --path vendor/bundle
25
+ bundler-cache: true
35
26
  - name: Test & publish code coverage
36
27
  uses: paambaati/codeclimate-action@v2.2.1
37
28
  if: github.event_name == 'push'
@@ -48,48 +39,29 @@ jobs:
48
39
  runs-on: macos-latest
49
40
  strategy:
50
41
  matrix:
51
- ruby: ['2.5.x', '2.6.x', '2.7.x', '3.0.x']
42
+ ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', 'head']
52
43
  steps:
53
- - uses: actions/checkout@v1
54
- - name: Cache gems
55
- uses: actions/cache@v1
56
- with:
57
- path: vendor/bundle
58
- key: gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-${{ hashFiles('**/*.gemspec') }}-
59
- restore-keys: |
60
- gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-${{ hashFiles('**/*.gemspec') }}-
61
- gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-
62
- gems-v1-${{ runner.os }}-
63
- - uses: actions/setup-ruby@v1
44
+ - uses: actions/checkout@v4
45
+ - run: brew install glfw
46
+ - uses: ruby/setup-ruby@v1
64
47
  with:
65
48
  ruby-version: ${{ matrix.ruby }}
66
- - run: brew install glfw
67
- - run: bundle install --path vendor/bundle
49
+ bundler-cache: true
68
50
  - run: bundle exec rake test
69
51
 
70
52
  windows:
71
53
  name: Windows
72
54
  runs-on: windows-latest
73
55
  env:
74
- MITTSU_LIBGLFW_FILE: c:\projects\mittsu\glfw-3.3.1.bin.WIN32\lib-mingw\glfw3.dll
56
+ MITTSU_LIBGLFW_PATH: c:\projects\mittsu\glfw-3.3.1.bin.WIN32\lib-mingw
75
57
  strategy:
76
58
  matrix:
77
- ruby: ['2.5.x', '2.6.x', '2.7.x', '3.0.x']
59
+ ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', 'head']
78
60
  steps:
79
- - uses: actions/checkout@v1
80
- - name: Cache gems
81
- uses: actions/cache@v1
82
- with:
83
- path: vendor/bundle
84
- key: gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-${{ hashFiles('**/*.gemspec') }}-
85
- restore-keys: |
86
- gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-${{ hashFiles('**/*.gemspec') }}-
87
- gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-
88
- gems-v1-${{ runner.os }}-
89
- - uses: actions/setup-ruby@v1
61
+ - uses: actions/checkout@v4
62
+ - run: .\install-glfw.ps1
63
+ - uses: ruby/setup-ruby@v1
90
64
  with:
91
65
  ruby-version: ${{ matrix.ruby }}
92
- - run: .\install-glfw.ps1
93
- - run: gem install bundler
94
- - run: bundle install --path vendor/bundle
66
+ bundler-cache: true
95
67
  - run: bundle exec rake test
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2016 Daniel Smith
3
+ Copyright (c) 2015-2022 Danielle Smith
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Mittsu
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/mittsu.svg)](https://badge.fury.io/rb/mittsu)
4
- [![Test Coverage](https://api.codeclimate.com/v1/badges/22be300984d81fa10af8/test_coverage)](https://codeclimate.com/github/jellymann/mittsu/test_coverage)
5
- [![Maintainability](https://api.codeclimate.com/v1/badges/22be300984d81fa10af8/maintainability)](https://codeclimate.com/github/jellymann/mittsu/maintainability)
6
- [![Build Status](https://github.com/jellymann/mittsu/workflows/Build/badge.svg)](https://github.com/jellymann/mittsu/actions?query=workflow%3A%22Build%22)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/22be300984d81fa10af8/test_coverage)](https://codeclimate.com/github/danini-the-panini/mittsu/test_coverage)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/22be300984d81fa10af8/maintainability)](https://codeclimate.com/github/danini-the-panini/mittsu/maintainability)
6
+ [![Build Status](https://github.com/danini-the-panini/mittsu/workflows/Build/badge.svg)](https://github.com/danini-the-panini/mittsu/actions?query=workflow%3A%22Build%22)
7
7
 
8
8
  3D Graphics Library for Ruby
9
9
 
@@ -15,7 +15,7 @@ Mittsu makes 3D graphics easier by providing an abstraction over OpenGL, and is
15
15
  ![Point Light](https://cloud.githubusercontent.com/assets/1171825/18411861/4531bb4c-7781-11e6-92b4-b6ebda60e2c9.gif)
16
16
  ![Tank Demo](https://cloud.githubusercontent.com/assets/1171825/18411862/4531fe9a-7781-11e6-9665-b172df1a3645.gif)
17
17
 
18
- (You can find the source for the Tank Demo [here](https://github.com/jellymann/mittsu-tank-demo))
18
+ (You can find the source for the Tank Demo [here](https://github.com/danini-the-panini/mittsu-tank-demo))
19
19
 
20
20
  ## Installation
21
21
 
@@ -34,6 +34,7 @@ $ sudo apt-get install libglfw3
34
34
  **NOTE:** On Windows, you will have to manually specify the glfw3.dll path in an environment variable
35
35
  (you can download it [here](http://www.glfw.org/download.html))
36
36
  ```bash
37
+ # ex) set MITTSU_LIBGLFW_PATH=C:\Users\username\lib-mingw-w64
37
38
  > set MITTSU_LIBGLFW_PATH=C:\path\to\glfw3.dll
38
39
  > ruby your_awesome_mittsu_app.rb
39
40
  ```
@@ -212,7 +213,7 @@ If you just want to see what Mittsu can do and how to do it, take a peek inside
212
213
 
213
214
  ## Contributing
214
215
 
215
- 1. Fork it ( https://github.com/jellymann/mittsu/fork )
216
+ 1. Fork it ( https://github.com/danini-the-panini/mittsu/fork )
216
217
  2. Create your feature branch (`git checkout -b my-new-feature`)
217
218
  3. Commit your changes (`git commit -am 'Add some feature'`)
218
219
  4. Push to the branch (`git push origin my-new-feature`)
@@ -50,6 +50,18 @@ module Mittsu
50
50
  self
51
51
  end
52
52
 
53
+ def get_x(index)
54
+ @array[index * @item_size]
55
+ end
56
+
57
+ def get_y(index)
58
+ @array[index * @item_size + 1]
59
+ end
60
+
61
+ def get_z(index)
62
+ @array[index * @item_size + 2]
63
+ end
64
+
53
65
  def set_xy(index, x, y)
54
66
  index *= @item_size
55
67
 
@@ -397,7 +397,7 @@ module Mittsu
397
397
  end
398
398
 
399
399
  def merge_mesh(mesh)
400
- if mesh instanceof Mittsu::Mesh == false
400
+ if mesh.is_a?(Mittsu::Mesh) == false
401
401
  puts('ERROR: Mittsu::Geometry#merge_mesh: mesh not an instance of Mittsu::Mesh.', mesh.inspect)
402
402
  return
403
403
  end
@@ -469,7 +469,7 @@ module Mittsu
469
469
  end
470
470
  vertices = []
471
471
  @vertices.each do |vert|
472
- vertices << vertex.x << vertex.y << vertex.z
472
+ vertices << vert.x << vert.y << vert.z
473
473
  end
474
474
  faces = []
475
475
  normals = []
@@ -507,7 +507,7 @@ module Mittsu
507
507
  faces << get_uv_index(face_vertex_uvs[2], uvs_hash, uvs)
508
508
  end
509
509
  if has_face_normal
510
- faces << get_normal_index(face.normal)
510
+ faces << get_normal_index(face.normal, normals_hash, normals)
511
511
  end
512
512
  if has_face_vertex_normal
513
513
  vertex_normals = face.vertex_normals
@@ -305,17 +305,13 @@ module Mittsu
305
305
  end
306
306
 
307
307
  def to_json
308
- @_output = {
308
+ {
309
309
  metadata: {
310
310
  version: 4.3,
311
311
  type: 'Object',
312
312
  generator: 'ObjectExporter'
313
- }
314
- }
315
- @_geometries = {}
316
- @_materials = {}
317
- @_output[:object] = self.jsonify
318
- @_output
313
+ },
314
+ }.merge(jsonify)
319
315
  end
320
316
 
321
317
  def clone(object = nil, recursive = true)
@@ -346,46 +342,32 @@ module Mittsu
346
342
  protected
347
343
 
348
344
  def jsonify
349
- data = {
350
- uuid: @uuid,
351
- type: @type,
352
- matrix: @matrix.to_a
353
- }
354
- data[:name] = @name unless @name.nil? || @name.empty?
355
- data[:user_data] = @user_data unless @user_data.nil? || @user_data.empty?
356
- data[:visible] = @visible unless @visible
357
-
358
- if !self.children.empty?
359
- data[:children] = @children.map do |child|
360
- child.jsonify
361
- end
362
- end
363
-
364
- # TODO: implement jsonify for PointCloud
365
-
366
- data
367
- end
368
-
369
- def jsonify_geometry(geometry)
370
- @_output[:geometries] ||= []
371
- if @_geometries[geometry.uuid].nil?
372
- json = geometry.to_json
373
- json.delete :metadata
374
- @_geometries[geometry.uuid] = json
375
- @_output[:geometries] << json
376
- end
377
- geometry.uuid
378
- end
379
-
380
- def jsonify_material(material)
381
- @_output[:materials] ||= []
382
- if @_materials[material.uuid].nil?
383
- json = material.to_json
384
- json.delete :metadata
385
- @_materials[material.uuid] = json
386
- @_output[:materials] << json
387
- end
388
- material.uuid
345
+ children = @children.map(&:to_json)
346
+ {
347
+ object: {
348
+ uuid: @uuid,
349
+ type: @type,
350
+ matrix: @matrix.to_a,
351
+ geometry: @geometry&.uuid,
352
+ material: @material&.uuid,
353
+ name: @name&.empty? ? nil : @name,
354
+ user_data: @user_data&.empty? ? nil : @user_data,
355
+ visible: @visible ? nil : @visible,
356
+ children: children.map { |x| x[:object] }.flatten
357
+ }.reject { |k,v| v.nil? || v == [] },
358
+ geometries: ([jsonify_geometry] + children.map { |x| x[:geometries] }).flatten.compact,
359
+ materials: ([jsonify_material] + children.map { |x| x[:materials] }).flatten.compact
360
+ }.reject { |k,v| v.nil? || v == [] }
361
+ end
362
+
363
+ def jsonify_geometry
364
+ return nil if @geometry.nil?
365
+ @geometry.to_json.delete_if {|k, v| k == :metadata }
366
+ end
367
+
368
+ def jsonify_material
369
+ return nil if @material.nil?
370
+ @material.to_json.delete_if {|k, v| k == :metadata }
389
371
  end
390
372
  end
391
373
  end
@@ -27,7 +27,6 @@ module Mittsu
27
27
  v1 = @vertices[indices[i]]
28
28
  v2 = @vertices[indices[i + 1]]
29
29
  v3 = @vertices[indices[i + 2]]
30
- binding.irb if v1.nil? || v2.nil? || v3.nil?
31
30
 
32
31
  faces[j] = Face3.new(v1.index, v2.index, v3.index, [v1.clone, v2.clone, v3.clone])
33
32
 
@@ -53,7 +53,7 @@ module Mittsu
53
53
 
54
54
  when FACE_PATTERN then parse_face(line)
55
55
 
56
- when OBJECT_PATTERN then new_object($1) and reset_vertices
56
+ when OBJECT_PATTERN then handle_object($1)
57
57
  when GROUP_PATTERN # ignore
58
58
  when SMOOTH_GROUP_PATTERN # ignore
59
59
 
@@ -105,9 +105,15 @@ module Mittsu
105
105
  raw_lines.split("\n").map(&:strip).reject(&:empty?).reject{|l| l.start_with? '#'}
106
106
  end
107
107
 
108
- def new_object(object_name = '')
109
- end_object
110
- @object = Object3D.new
108
+ def handle_object(object_name = '')
109
+ # Reset if we're already working on a named object
110
+ # otherwise, just name the one we have in progress
111
+ unless @object&.name.nil?
112
+ end_object
113
+ reset_vertices
114
+ @object = nil
115
+ end
116
+ @object ||= Object3D.new
111
117
  @object.name = object_name
112
118
  end
113
119
 
@@ -120,7 +126,7 @@ module Mittsu
120
126
 
121
127
  def new_mesh
122
128
  end_mesh
123
- new_object if @object.nil?
129
+ handle_object if @object.nil?
124
130
  @geometry = Geometry.new
125
131
  @mesh = Mesh.new(@geometry, @material || MeshLambertMaterial.new)
126
132
  @mesh.name = @object.name
@@ -38,18 +38,18 @@ module Mittsu
38
38
  object.traverse do |node|
39
39
  geometry = node.geometry
40
40
  if geometry != nil
41
- if geometry instanceof Mittsu::Geometry
41
+ if geometry.is_a?(Mittsu::Geometry)
42
42
  vertices = geometry.vertices
43
43
  vertices.each do |vertex|
44
44
  v1.copy(vertex)
45
- v1.apply_matrix4(node.matrixWorld)
45
+ v1.apply_matrix4(node.matrix_world)
46
46
  scope.expand_by_point(v1)
47
47
  end
48
- elsif geometry instanceof Mittsu::BufferGeometry && geometry.attributes['position'] != nil
48
+ elsif geometry.is_a?(Mittsu::BufferGeometry) && geometry.attributes['position'] != nil
49
49
  positions = geometry.attributes['position'].array
50
50
  positions.each_slice(3) do |postition|
51
51
  v1.set(position[0], position[1], position[2])
52
- v1.apply_matrix4(node.matrixWorld)
52
+ v1.apply_matrix4(node.matrix_world)
53
53
  scope.expand_by_point(v1)
54
54
  end
55
55
  end
@@ -187,6 +187,114 @@ module Mittsu
187
187
  self
188
188
  end
189
189
 
190
+ def set_scalar(scalar)
191
+ set(scalar, scalar, scalar)
192
+
193
+ self
194
+ end
195
+
196
+ def set_component(index, value)
197
+ _x, _y, _z = *@elements
198
+
199
+ case index
200
+ when 0
201
+ set(value, _y, _z)
202
+ when 1
203
+ set(_x, value, _z)
204
+ when 2
205
+ set(_x, _y, value)
206
+ else
207
+ raise ArgumentError, "index is out of range: #{index}"
208
+ end
209
+
210
+ self
211
+ end
212
+
213
+ def get_component(index)
214
+ _x, _y, _z = *@elements
215
+
216
+ case index
217
+ when 0
218
+ return _x
219
+ when 1
220
+ return _y
221
+ when 2
222
+ return _z
223
+ else
224
+ raise ArgumentError, "index is out of range: #{index}"
225
+ end
226
+ end
227
+
228
+ def add_scaled_vector(vector, scalar)
229
+ set(vector.x * scalar, vector.y * scalar, vector.z * scalar)
230
+
231
+ self
232
+ end
233
+
234
+ def set_from_spherical(sphere)
235
+ set_from_spherical_coords(sphere.radius, sphere.phi, sphere.theta)
236
+ end
237
+
238
+ def set_from_spherical_coords(radius, phi, theta)
239
+ sin_phi_radius = ::Math.sin(phi) * radius
240
+ set(sin_phi_radius * ::Math.sin(theta), ::Math.cos(phi) * radius, sin_phi_radius * ::Math.cos(theta))
241
+
242
+ self
243
+ end
244
+
245
+ def set_from_cylindrical(cylinder)
246
+ set_from_cylindrical_coords(cylinder.radius, cylinder.theta, cylinder.y)
247
+ end
248
+
249
+ def set_from_cylindrical_coords(radius, theta, y)
250
+ set(radius * ::Math.sin(theta), y, radius * ::Math.sin(theta))
251
+
252
+ self
253
+ end
254
+
255
+ def set_from_matrix3_column(matrix, index)
256
+ from_array(matrix.elements, index * 3)
257
+ end
258
+
259
+ def equals(vector)
260
+ _x, _y, _z = *@elements
261
+
262
+ ((vector.x == _x) && (vector.y == _y) && (vector.z == _z ))
263
+ end
264
+
265
+ def from_buffer_attribute(attribute, index)
266
+ set(attribute.get_x(index), attribute.get_y(index), attribute.get_z(index))
267
+
268
+ self
269
+ end
270
+
271
+ def clamp_length(min, max)
272
+ divide_scalar(length || 1).multiply_scalar([min, [max, length].min].max)
273
+ end
274
+
275
+ def manhattan_distance_to(vector)
276
+ _x, _y, _z = *@elements
277
+
278
+ (_x - vector.x).abs + (_y - vector.y).abs + (_z - vector.z).abs
279
+ end
280
+
281
+ # TODO: maybe add range 3 values as arguments (range_x, range_y, range_z) to this method
282
+ def random()
283
+ set(Random.new.rand, Random.new.rand, Random.new.rand)
284
+
285
+ self
286
+ end
287
+
288
+ def random_direction()
289
+ u = (Random.new.rand - 0.5) *2
290
+ t = Random.new.rand * ::Math::PI * 2
291
+ f = ::Math.sqrt(1 - u ** 2)
292
+
293
+ set(f * ::Math.cos(t), f * ::Math.sin(t), u)
294
+
295
+ self
296
+ end
297
+
190
298
  def from_attribute(attribute, index, offset = 0)
191
299
  index = index * attribute.itemSize + offset
192
300
 
@@ -143,9 +143,7 @@ module Mittsu
143
143
 
144
144
  def jsonify
145
145
  data = super
146
- data[:geometry] = jsonify_geometry(self.geometry)
147
- data[:material] = jsonify_material(self.material)
148
- data[:mode] = self.mode
146
+ data[:object][:mode] = self.mode
149
147
  data
150
148
  end
151
149
  end
@@ -98,7 +98,7 @@ module Mittsu
98
98
  @_ray.copy(raycaster.ray).apply_matrix4(@_inverse_matrix)
99
99
 
100
100
  if !geometry.bounding_box.nil?
101
- return unless ray.intersection_box?(geometry.bounding_box)
101
+ return unless @_ray.intersection_box?(geometry.bounding_box)
102
102
  end
103
103
 
104
104
 
@@ -132,16 +132,16 @@ module Mittsu
132
132
  v_c.from_array(positions, c * 3)
133
133
 
134
134
  if material.side == BackSide
135
- intersection_point = ray.intersect_triangle(v_c, v_b, v_a, true)
135
+ intersection_point = @_ray.intersect_triangle(v_c, v_b, v_a, true)
136
136
  else
137
- intersection_point = ray.intersect_triangle(v_a, v_b, v_c, material.side != DoubleSide)
137
+ intersection_point = @_ray.intersect_triangle(v_a, v_b, v_c, material.side != DoubleSide)
138
138
  end
139
139
 
140
140
  next if intersection_point.nil?
141
141
 
142
142
  intersection_point.apply_matrix4(@matrix_world)
143
143
 
144
- distance = racaster.ray.origin.distance_to(intersection_point)
144
+ distance = raycaster.ray.origin.distance_to(intersection_point)
145
145
 
146
146
  next if distance < precision || distance < raycaster.near || distance > raycaster.far
147
147
 
@@ -170,17 +170,17 @@ module Mittsu
170
170
  v_b.from_array(positions, j + 3)
171
171
  v_c.from_array(positions, j + 6)
172
172
 
173
- if material.side = BackSide
174
- intersection_point = ray.intersect_triangle(v_c, v_b, v_a, true)
173
+ if material.side == BackSide
174
+ intersection_point = @_ray.intersect_triangle(v_c, v_b, v_a, true)
175
175
  else
176
- intersection_point = ray.intersect_triangle(v_a, v_b, v_c, material.side != DoubleSide)
176
+ intersection_point = @_ray.intersect_triangle(v_a, v_b, v_c, material.side != DoubleSide)
177
177
  end
178
178
 
179
179
  next if intersection_point.nil?
180
180
 
181
181
  intersection_point.apply_matrix4(@matrix_world)
182
182
 
183
- distance = racaster.ray.origin.distance_to(intersection_point)
183
+ distance = raycaster.ray.origin.distance_to(intersection_point)
184
184
 
185
185
  next if distance < precision || distance < raycaster.near || distance > raycaster.far
186
186
 
@@ -269,10 +269,7 @@ module Mittsu
269
269
  protected
270
270
 
271
271
  def jsonify
272
- data = super
273
- data[:geometry] = jsonify_geometry(@geometry)
274
- data[:material] = jsonify_material(@material)
275
- data
272
+ super
276
273
  end
277
274
  end
278
275
  end
@@ -16,11 +16,11 @@ module Mittsu
16
16
 
17
17
  def raycast(raycaster, intersects)
18
18
  threshold = raycaster.params[:point_cloud][:threshold]
19
- @_inverse_matrix.inverse(self.materix_world)
19
+ @_inverse_matrix.inverse(self.matrix_world)
20
20
  @_ray.copy(raycaster.ray).apply_matrix4(@_inverse_matrix)
21
21
 
22
22
  if !geometry.bounding_box.nil?
23
- return if ray.intersection_box?(geometry.bounding_box) == false
23
+ return if @_ray.intersection_box?(geometry.bounding_box) == false
24
24
  end
25
25
 
26
26
  local_threshold = threshold / ((self.scale.x + self.scale.y + self.scale.z) / 3.0)
@@ -82,7 +82,7 @@ module Mittsu
82
82
  def test_point(point, index, local_threshold, raycaster, intersects)
83
83
  ray_point_distance = @_ray.distance_to_point(point)
84
84
  if ray_point_distance < local_threshold
85
- intersect_point = @_ray.closes_point_to_point(point)
85
+ intersect_point = @_ray.closest_point_to_point(point)
86
86
  intersect_point.apply_matrix4(self.matrix_world)
87
87
 
88
88
  distance = raycaster.ray.origin.distance_to(intersect_point)
@@ -1,3 +1,5 @@
1
+ require 'open3'
2
+
1
3
  module Mittsu
2
4
  module GenericLib
3
5
  def discover
@@ -32,7 +34,8 @@ module Mittsu
32
34
 
33
35
  class << self
34
36
  def kernel_module_in_use
35
- lspci_line = `lspci -nnk | grep -i vga -A3 | grep 'in use'`
37
+ lspci_line, stderr, _status = Open3.capture3("lspci -nnk | grep -i vga -A3 | grep 'in use'")
38
+ puts stderr if DEBUG
36
39
  /in use:\s*(\S+)/ =~ lspci_line && $1
37
40
  rescue
38
41
  ''
@@ -17,7 +17,9 @@ module Mittsu
17
17
  end
18
18
 
19
19
  def ldconfig
20
- `ldconfig -p | grep 'libglfw3\\?\\.so'`.lines
20
+ out, stderr, _status = Open3.capture3("ldconfig -p | grep 'libglfw3\\?\\.so'")
21
+ puts stderr if DEBUG
22
+ out.lines
21
23
  rescue
22
24
  []
23
25
  end
@@ -25,17 +27,38 @@ module Mittsu
25
27
  end
26
28
 
27
29
  class Windows < GenericLib::Base
30
+ def file
31
+ 'glfw3.dll'
32
+ end
28
33
  end
29
34
 
30
35
  class MacOS < GenericLib::Base
36
+ SEARCH_GLOBS = ['/usr/local/lib/**',
37
+ '/usr/lib/**',
38
+ '/opt/homebrew/**']
39
+
31
40
  def path
32
- '/usr/local/lib'
41
+ File.dirname(match.to_s)
33
42
  end
34
43
 
35
44
  def file
36
- matches = Dir.glob('/usr/local/lib/libglfw*.dylib').map { |path| File.basename(path) }
37
- return matches.find { |m| m == 'libglfw3.dylib' || m == 'libglfw.3.dylib' } || matches.first
45
+ File.basename(match.to_s)
38
46
  end
47
+
48
+ private
49
+
50
+ def match
51
+ @match ||= find_match
52
+ end
53
+
54
+ def find_match
55
+ SEARCH_GLOBS.each do |glob|
56
+ matches = Dir.glob("#{glob}/libglfw*.dylib")
57
+ next if matches.empty?
58
+
59
+ return matches.find { |m| m.end_with?('libglfw3.dylib') || m.end_with?('libglfw.3.dylib') } || matches.first
60
+ end
61
+ end
39
62
  end
40
63
  end
41
64
  end
@@ -13,7 +13,7 @@ module Mittsu
13
13
  class Window
14
14
  attr_accessor :key_press_handler, :key_release_handler, :key_repeat_handler, :char_input_handler, :cursor_pos_handler, :mouse_button_press_handler, :mouse_button_release_handler, :scroll_handler, :framebuffer_size_handler
15
15
 
16
- def initialize(width, height, title)
16
+ def initialize(width, height, title, antialias: 0)
17
17
  glfwInit
18
18
 
19
19
  glfwWindowHint GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE
@@ -22,6 +22,10 @@ module Mittsu
22
22
  glfwWindowHint GLFW_CONTEXT_VERSION_MINOR, 3
23
23
  glfwWindowHint GLFW_CONTEXT_REVISION, 0
24
24
 
25
+ if antialias > 0
26
+ glfwWindowHint GLFW_SAMPLES, antialias
27
+ end
28
+
25
29
  @width, @height, @title = width, height, title
26
30
  @handle = glfwCreateWindow(@width, @height, @title, nil, nil)
27
31
  if @handle.null?
@@ -61,14 +61,14 @@ module Mittsu
61
61
  glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
62
62
 
63
63
  if wrap_s != ClampToEdgeWrapping || wrap_t != ClampToEdgeWrapping
64
- puts "WARNING: Mittsu::Texture: Texture is not power of two. Texture.wrap_s and Texture.wrap_t should be set to Mittsu::ClampToEdgeWrapping. (#{texture.source_file})"
64
+ puts "WARNING: Mittsu::Texture: Texture is not power of two. Texture.wrap_s and Texture.wrap_t should be set to Mittsu::ClampToEdgeWrapping. (#{source_file})"
65
65
  end
66
66
 
67
67
  glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, filter_fallback(mag_filter))
68
68
  glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, filter_fallback(min_filter))
69
69
 
70
70
  if min_filter != NearestFilter && min_filter != LinearFilter
71
- puts "WARNING: Mittsu::Texture: Texture is not a power of two. Texture.min_filter should be set to Mittsu::NearestFilter or Mittsu::LinearFilter. (#{texture.source_file})"
71
+ puts "WARNING: Mittsu::Texture: Texture is not a power of two. Texture.min_filter should be set to Mittsu::NearestFilter or Mittsu::LinearFilter. (#{source_file})"
72
72
  end
73
73
 
74
74
  # TODO: anisotropic extension ???
@@ -35,7 +35,7 @@ module Mittsu
35
35
  attr_reader :logarithmic_depth_buffer, :programs, :light_renderer, :proj_screen_matrix
36
36
 
37
37
  def initialize(parameters = {})
38
- puts "OpenGLRenderer (Revision #{REVISION})"
38
+ puts "Mittsu OpenGL Renderer #{VERSION}"
39
39
 
40
40
  fetch_parameters(parameters)
41
41
 
@@ -935,14 +935,14 @@ module Mittsu
935
935
  @_alpha = parameters.fetch(:alpha, false)
936
936
  @_depth = parameters.fetch(:depth, true)
937
937
  @_stencil = parameters.fetch(:stencil, true)
938
- @_antialias = parameters.fetch(:antialias, false)
939
938
  @_premultiplied_alpha = parameters.fetch(:premultiplied_alpha, true)
940
939
  @_preserve_drawing_buffer = parameters.fetch(:preserve_drawing_buffer, false)
941
940
  @logarithmic_depth_buffer = parameters.fetch(:logarithmic_depth_buffer, false)
942
941
 
943
942
  @width = parameters.fetch(:width, 800)
944
943
  @height = parameters.fetch(:height, 600)
945
- @title = parameters.fetch(:title, "Mittsu #{REVISION}")
944
+ @title = parameters.fetch(:title, "Mittsu #{VERSION}")
945
+ @antialias = parameters.fetch(:antialias, 0)
946
946
  end
947
947
 
948
948
  def get_gpu_capabilities
@@ -974,7 +974,7 @@ module Mittsu
974
974
  # preserve_drawing_buffer: _preserve_drawing_buffer
975
975
  # }
976
976
 
977
- @window = GLFW::Window.new(@width, @height, @title)
977
+ @window = GLFW::Window.new(@width, @height, @title, antialias: @antialias)
978
978
 
979
979
  default_target.set_viewport_size(*(@window.framebuffer_size))
980
980
 
@@ -1,4 +1,3 @@
1
1
  module Mittsu
2
- VERSION = "0.3.3"
3
- REVISION = "71"
2
+ VERSION = "0.4.1"
4
3
  end
data/mittsu.gemspec CHANGED
@@ -6,15 +6,15 @@ require 'mittsu/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "mittsu"
8
8
  spec.version = Mittsu::VERSION
9
- spec.authors = ["Daniel Smith"]
10
- spec.email = ["jellymann@gmail.com"]
9
+ spec.authors = ["Danielle Smith"]
10
+ spec.email = ["danini@hey.com"]
11
11
 
12
12
  spec.summary = %q{3D Graphics Library for Ruby}
13
13
  spec.description = %q{Mittsu makes 3D graphics easier by providing an abstraction over OpenGL, and is based heavily off of THREE.js. No more weird pointers and wondering about the difference between a VAO and a VBO (besides the letter). Simply think of something awesome and make it!}
14
- spec.homepage = "https://github.com/jellymann/mittsu"
14
+ spec.homepage = "https://github.com/danini-the-panini/mittsu"
15
15
  spec.license = "MIT"
16
16
  spec.metadata = {
17
- "bug_tracker" => "https://github.com/jellymann/mittsu/issues"
17
+ "bug_tracker" => "https://github.com/danini-the-panini/mittsu/issues"
18
18
  }
19
19
 
20
20
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{(^(test|examples)/|\.sh$)}) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mittsu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
- - Daniel Smith
7
+ - Danielle Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-05 00:00:00.000000000 Z
11
+ date: 2024-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opengl-bindings
@@ -155,7 +155,7 @@ description: Mittsu makes 3D graphics easier by providing an abstraction over Op
155
155
  the difference between a VAO and a VBO (besides the letter). Simply think of something
156
156
  awesome and make it!
157
157
  email:
158
- - jellymann@gmail.com
158
+ - danini@hey.com
159
159
  executables: []
160
160
  extensions: []
161
161
  extra_rdoc_files: []
@@ -406,11 +406,11 @@ files:
406
406
  - lib/mittsu/utils.rb
407
407
  - lib/mittsu/version.rb
408
408
  - mittsu.gemspec
409
- homepage: https://github.com/jellymann/mittsu
409
+ homepage: https://github.com/danini-the-panini/mittsu
410
410
  licenses:
411
411
  - MIT
412
412
  metadata:
413
- bug_tracker: https://github.com/jellymann/mittsu/issues
413
+ bug_tracker: https://github.com/danini-the-panini/mittsu/issues
414
414
  post_install_message:
415
415
  rdoc_options: []
416
416
  require_paths:
@@ -427,7 +427,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
427
427
  version: '0'
428
428
  requirements:
429
429
  - OpenGL 3.3+ capable hardware and drivers
430
- rubygems_version: 3.2.3
430
+ rubygems_version: 3.5.23
431
431
  signing_key:
432
432
  specification_version: 4
433
433
  summary: 3D Graphics Library for Ruby