mittsu 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build-workflow.yml +5 -44
- data/Gemfile +0 -4
- data/README.md +16 -130
- data/bin/console +0 -4
- data/lib/mittsu/cameras/cube_camera.rb +1 -1
- data/lib/mittsu/core/geometry.rb +3 -3
- data/lib/mittsu/core/object_3d.rb +29 -47
- data/lib/mittsu/core/uniform.rb +23 -0
- data/lib/mittsu/core.rb +1 -0
- data/lib/mittsu/loaders/obj_loader.rb +11 -5
- data/lib/mittsu/loaders/stl_loader.rb +186 -0
- data/lib/mittsu/loaders.rb +1 -0
- data/lib/mittsu/math/box3.rb +4 -4
- data/lib/mittsu/objects/line.rb +1 -3
- data/lib/mittsu/objects/mesh.rb +9 -12
- data/lib/mittsu/objects/point_cloud.rb +3 -3
- data/lib/mittsu/textures/render_target.rb +93 -0
- data/lib/mittsu/textures/render_target_cube.rb +8 -0
- data/lib/mittsu/textures/texture.rb +1 -1
- data/lib/mittsu/textures.rb +2 -0
- data/lib/mittsu/version.rb +1 -1
- data/lib/mittsu.rb +0 -1
- data/mittsu.gemspec +8 -12
- metadata +33 -204
- data/install-glfw.ps1 +0 -13
- data/lib/mittsu/renderers/generic_lib.rb +0 -122
- data/lib/mittsu/renderers/glfw_lib.rb +0 -62
- data/lib/mittsu/renderers/glfw_window.rb +0 -233
- data/lib/mittsu/renderers/opengl/core/buffer_geometry.rb +0 -11
- data/lib/mittsu/renderers/opengl/core/geometry.rb +0 -346
- data/lib/mittsu/renderers/opengl/core/object_3d.rb +0 -134
- data/lib/mittsu/renderers/opengl/lights/ambient_light.rb +0 -26
- data/lib/mittsu/renderers/opengl/lights/directional_light.rb +0 -35
- data/lib/mittsu/renderers/opengl/lights/hemisphere_light.rb +0 -39
- data/lib/mittsu/renderers/opengl/lights/light.rb +0 -55
- data/lib/mittsu/renderers/opengl/lights/point_light.rb +0 -36
- data/lib/mittsu/renderers/opengl/lights/spot_light.rb +0 -47
- data/lib/mittsu/renderers/opengl/materials/line_basic_material.rb +0 -16
- data/lib/mittsu/renderers/opengl/materials/material.rb +0 -274
- data/lib/mittsu/renderers/opengl/materials/mesh_basic_material.rb +0 -21
- data/lib/mittsu/renderers/opengl/materials/mesh_lambert_material.rb +0 -33
- data/lib/mittsu/renderers/opengl/materials/mesh_phong_material.rb +0 -44
- data/lib/mittsu/renderers/opengl/materials/opengl_material_basics.rb +0 -57
- data/lib/mittsu/renderers/opengl/materials/point_cloud_material.rb +0 -27
- data/lib/mittsu/renderers/opengl/materials/shader_material.rb +0 -11
- data/lib/mittsu/renderers/opengl/objects/group.rb +0 -9
- data/lib/mittsu/renderers/opengl/objects/line.rb +0 -45
- data/lib/mittsu/renderers/opengl/objects/mesh.rb +0 -70
- data/lib/mittsu/renderers/opengl/objects/point_cloud.rb +0 -39
- data/lib/mittsu/renderers/opengl/objects/sprite.rb +0 -12
- data/lib/mittsu/renderers/opengl/opengl_buffer.rb +0 -13
- data/lib/mittsu/renderers/opengl/opengl_debug.rb +0 -81
- data/lib/mittsu/renderers/opengl/opengl_default_target.rb +0 -50
- data/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +0 -758
- data/lib/mittsu/renderers/opengl/opengl_geometry_like.rb +0 -132
- data/lib/mittsu/renderers/opengl/opengl_helper.rb +0 -161
- data/lib/mittsu/renderers/opengl/opengl_implementations.rb +0 -37
- data/lib/mittsu/renderers/opengl/opengl_lib.rb +0 -19
- data/lib/mittsu/renderers/opengl/opengl_light_renderer.rb +0 -43
- data/lib/mittsu/renderers/opengl/opengl_mittsu_params.rb +0 -53
- data/lib/mittsu/renderers/opengl/opengl_program.rb +0 -250
- data/lib/mittsu/renderers/opengl/opengl_shader.rb +0 -58
- data/lib/mittsu/renderers/opengl/opengl_state.rb +0 -205
- data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +0 -417
- data/lib/mittsu/renderers/opengl/plugins/sprite_fragment.glsl +0 -38
- data/lib/mittsu/renderers/opengl/plugins/sprite_plugin.rb +0 -250
- data/lib/mittsu/renderers/opengl/plugins/sprite_vertex.glsl +0 -31
- data/lib/mittsu/renderers/opengl/scenes/scene.rb +0 -9
- data/lib/mittsu/renderers/opengl/textures/compressed_texture.rb +0 -20
- data/lib/mittsu/renderers/opengl/textures/cube_texture.rb +0 -77
- data/lib/mittsu/renderers/opengl/textures/data_texture.rb +0 -21
- data/lib/mittsu/renderers/opengl/textures/texture.rb +0 -107
- data/lib/mittsu/renderers/opengl_render_target.rb +0 -201
- data/lib/mittsu/renderers/opengl_renderer.rb +0 -1028
- data/lib/mittsu/renderers/shaders/rbsl_loader.rb +0 -166
- data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_pars_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/alphatest_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/bumpmap_pars_fragment.glsl +0 -40
- data/lib/mittsu/renderers/shaders/shader_chunk/color_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/color_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/common.glsl +0 -60
- data/lib/mittsu/renderers/shaders/shader_chunk/default_vertex.glsl +0 -15
- data/lib/mittsu/renderers/shaders/shader_chunk/defaultnormal_vertex.glsl +0 -21
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_fragment.glsl +0 -62
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_fragment.glsl +0 -21
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_vertex.glsl +0 -7
- data/lib/mittsu/renderers/shaders/shader_chunk/envmap_vertex.glsl +0 -17
- data/lib/mittsu/renderers/shaders/shader_chunk/fog_fragment.glsl +0 -26
- data/lib/mittsu/renderers/shaders/shader_chunk/fog_pars_fragment.glsl +0 -15
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_fragment.glsl +0 -6
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_pars_vertex.glsl +0 -43
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_vertex.glsl +0 -196
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_fragment.glsl +0 -243
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_fragment.glsl +0 -58
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/linear_to_gamma_fragment.glsl +0 -2
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_fragment.glsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_vertex.glsl +0 -11
- data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_vertex.glsl +0 -15
- data/lib/mittsu/renderers/shaders/shader_chunk/map_fragment.glsl +0 -9
- data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_fragment.glsl +0 -11
- data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_vertex.glsl +0 -6
- data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_pars_fragment.glsl +0 -6
- data/lib/mittsu/renderers/shaders/shader_chunk/map_vertex.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/morphnormal_vertex.glsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_pars_vertex.glsl +0 -13
- data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_vertex.glsl +0 -20
- data/lib/mittsu/renderers/shaders/shader_chunk/normalmap_pars_fragment.glsl +0 -27
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_fragment.glsl +0 -216
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_fragment.glsl +0 -19
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_vertex.glsl +0 -6
- data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_vertex.glsl +0 -9
- data/lib/mittsu/renderers/shaders/shader_chunk/skinbase_vertex.glsl +0 -8
- data/lib/mittsu/renderers/shaders/shader_chunk/skinning_pars_vertex.glsl +0 -47
- data/lib/mittsu/renderers/shaders/shader_chunk/skinning_vertex.glsl +0 -20
- data/lib/mittsu/renderers/shaders/shader_chunk/skinnormal_vertex.glsl +0 -20
- data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_fragment.glsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_pars_fragment.glsl +0 -5
- data/lib/mittsu/renderers/shaders/shader_chunk/worldpos_vertex.glsl +0 -17
- data/lib/mittsu/renderers/shaders/shader_chunk.rb +0 -9
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_fragment.rbsl +0 -37
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_uniforms.rbslu +0 -3
- data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_vertex.rbsl +0 -33
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_fragment.rbsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_uniforms.rbslu +0 -2
- data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_vertex.rbsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_fragment.rbsl +0 -26
- data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_uniforms.rbslu +0 -0
- data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_vertex.rbsl +0 -12
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_fragment.rbsl +0 -56
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_uniforms.rbslu +0 -7
- data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_vertex.rbsl +0 -37
- data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_fragment.rbsl +0 -27
- data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_uniforms.rbslu +0 -2
- data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_vertex.rbsl +0 -25
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_fragment.rbsl +0 -45
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_uniforms.rbslu +0 -11
- data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_vertex.rbsl +0 -43
- data/lib/mittsu/renderers/shaders/shader_lib.rb +0 -43
- data/lib/mittsu/renderers/shaders/shader_templates/fragment.glsl.erb +0 -105
- data/lib/mittsu/renderers/shaders/shader_templates/vertex.glsl.erb +0 -143
- data/lib/mittsu/renderers/shaders/uniforms_lib.rb +0 -106
- data/lib/mittsu/renderers/shaders/uniforms_utils.rb +0 -31
- data/lib/mittsu/renderers.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 620d1bf034251f9514abec4fb1e28357bccbe984f517d6763c5f1e544e3c9728
|
4
|
+
data.tar.gz: 157868417127b487b51b8ccbc1bfa901063f557915a3f0f66f43f0a6cfe600da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 611d3f4d2aa790e21f04cd22b45b3a8ed3901dbc60e97e1a2f72574bdb846d12773b552397131cda37471f39ed97d4702f0976ca83438d2202f1439e0e722b6e
|
7
|
+
data.tar.gz: 0d2fd2ab7d43a2ebbe523103b33fc1ce8a0bcd3ce046f2c82fd2e633e8e2b6b80cfede3ffc7758a82d753d69afb7f75c3ce49f69aa278161dbb1586603c017a6
|
@@ -8,24 +8,20 @@ on:
|
|
8
8
|
- main
|
9
9
|
|
10
10
|
jobs:
|
11
|
-
|
12
|
-
name:
|
11
|
+
test:
|
12
|
+
name: Test
|
13
13
|
runs-on: ubuntu-latest
|
14
14
|
strategy:
|
15
15
|
matrix:
|
16
|
-
ruby: ['2.6', '2.7', '3.0', '3.1', 'head']
|
16
|
+
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', 'head']
|
17
17
|
steps:
|
18
|
-
- uses: actions/checkout@
|
18
|
+
- uses: actions/checkout@v4
|
19
19
|
- uses: ruby/setup-ruby@v1
|
20
20
|
with:
|
21
21
|
ruby-version: ${{ matrix.ruby }}
|
22
22
|
bundler-cache: true
|
23
|
-
- run: sudo apt-get update; sudo apt-get install cmake xorg-dev libgl1-mesa-dev
|
24
|
-
- run: bash install-glfw.sh
|
25
|
-
- run: gem install bundler
|
26
|
-
- run: bundle install --path vendor/bundle
|
27
23
|
- name: Test & publish code coverage
|
28
|
-
uses: paambaati/codeclimate-action@
|
24
|
+
uses: paambaati/codeclimate-action@v9.0.0
|
29
25
|
if: github.event_name == 'push'
|
30
26
|
env:
|
31
27
|
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
@@ -34,38 +30,3 @@ jobs:
|
|
34
30
|
- name: Test
|
35
31
|
if: github.event_name != 'push'
|
36
32
|
run: bundle exec rake test
|
37
|
-
|
38
|
-
macos:
|
39
|
-
name: macOS
|
40
|
-
runs-on: macos-latest
|
41
|
-
strategy:
|
42
|
-
matrix:
|
43
|
-
ruby: ['2.6', '2.7', '3.0', '3.1', 'head']
|
44
|
-
steps:
|
45
|
-
- uses: actions/checkout@v1
|
46
|
-
- uses: ruby/setup-ruby@v1
|
47
|
-
with:
|
48
|
-
ruby-version: ${{ matrix.ruby }}
|
49
|
-
bundler-cache: true
|
50
|
-
- run: brew install glfw
|
51
|
-
- run: bundle install --path vendor/bundle
|
52
|
-
- run: bundle exec rake test
|
53
|
-
|
54
|
-
windows:
|
55
|
-
name: Windows
|
56
|
-
runs-on: windows-latest
|
57
|
-
env:
|
58
|
-
MITTSU_LIBGLFW_PATH: c:\projects\mittsu\glfw-3.3.1.bin.WIN32\lib-mingw
|
59
|
-
strategy:
|
60
|
-
matrix:
|
61
|
-
ruby: ['2.6', '2.7', '3.0', '3.1', 'head']
|
62
|
-
steps:
|
63
|
-
- uses: actions/checkout@v1
|
64
|
-
- uses: ruby/setup-ruby@v1
|
65
|
-
with:
|
66
|
-
ruby-version: ${{ matrix.ruby }}
|
67
|
-
bundler-cache: true
|
68
|
-
- run: .\install-glfw.ps1
|
69
|
-
- run: gem install bundler
|
70
|
-
- run: bundle install --path vendor/bundle
|
71
|
-
- run: bundle exec rake test
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
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/
|
5
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/
|
4
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/339a016dc2e7fc51c82a/test_coverage)](https://codeclimate.com/github/danini-the-panini/mittsu/test_coverage)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/339a016dc2e7fc51c82a/maintainability)](https://codeclimate.com/github/danini-the-panini/mittsu/maintainability)
|
6
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
|
|
10
|
-
Mittsu
|
10
|
+
Mittsu is a 3D Graphics Library for Ruby, based heavily on Three.js
|
11
11
|
|
12
12
|
## GIFs!
|
13
13
|
|
@@ -19,26 +19,6 @@ Mittsu makes 3D graphics easier by providing an abstraction over OpenGL, and is
|
|
19
19
|
|
20
20
|
## Installation
|
21
21
|
|
22
|
-
Install the prerequisites:
|
23
|
-
|
24
|
-
Mittsu depends on Ruby 2.x, OpenGL 3.3+, and GLFW 3.1.x
|
25
|
-
|
26
|
-
```bash
|
27
|
-
# OSX
|
28
|
-
$ brew install glfw3
|
29
|
-
|
30
|
-
# Ubuntu
|
31
|
-
$ sudo apt-get install libglfw3
|
32
|
-
```
|
33
|
-
|
34
|
-
**NOTE:** On Windows, you will have to manually specify the glfw3.dll path in an environment variable
|
35
|
-
(you can download it [here](http://www.glfw.org/download.html))
|
36
|
-
```bash
|
37
|
-
# ex) set MITTSU_LIBGLFW_PATH=C:\Users\username\lib-mingw-w64
|
38
|
-
> set MITTSU_LIBGLFW_PATH=C:\path\to\glfw3.dll
|
39
|
-
> ruby your_awesome_mittsu_app.rb
|
40
|
-
```
|
41
|
-
|
42
22
|
Add this line to your application's Gemfile:
|
43
23
|
|
44
24
|
```ruby
|
@@ -55,22 +35,14 @@ Or install it yourself as:
|
|
55
35
|
|
56
36
|
## Usage
|
57
37
|
|
58
|
-
|
59
|
-
|
60
|
-
Copy-Paste and Run:
|
38
|
+
Create a basic scene with a perspective camera and a green box:
|
61
39
|
|
62
40
|
```ruby
|
63
41
|
require 'mittsu'
|
64
42
|
|
65
|
-
SCREEN_WIDTH = 800
|
66
|
-
SCREEN_HEIGHT = 600
|
67
|
-
ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
|
68
|
-
|
69
|
-
renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: 'Hello, World!'
|
70
|
-
|
71
43
|
scene = Mittsu::Scene.new
|
72
44
|
|
73
|
-
camera = Mittsu::PerspectiveCamera.new(75.0,
|
45
|
+
camera = Mittsu::PerspectiveCamera.new(75.0, 1.0, 0.1, 1000.0)
|
74
46
|
camera.position.z = 5.0
|
75
47
|
|
76
48
|
box = Mittsu::Mesh.new(
|
@@ -79,116 +51,30 @@ box = Mittsu::Mesh.new(
|
|
79
51
|
)
|
80
52
|
|
81
53
|
scene.add(box)
|
82
|
-
|
83
|
-
renderer.window.run do
|
84
|
-
box.rotation.x += 0.1
|
85
|
-
box.rotation.y += 0.1
|
86
|
-
|
87
|
-
renderer.render(scene, camera)
|
88
|
-
end
|
89
|
-
```
|
90
|
-
|
91
|
-
### Step by Step
|
92
|
-
|
93
|
-
First, we need to require Mittsu in order to use it:
|
94
|
-
```ruby
|
95
|
-
require 'mittsu'
|
96
|
-
```
|
97
|
-
|
98
|
-
Then, we'll define some constants to help us with setting up our 3D environment:
|
99
|
-
```ruby
|
100
|
-
SCREEN_WIDTH = 800
|
101
|
-
SCREEN_HEIGHT = 600
|
102
|
-
ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f
|
103
|
-
```
|
104
|
-
|
105
|
-
The aspect ratio will be used for setting up the camera later.
|
106
|
-
|
107
|
-
Once we have all that we can create the canvas we will use to draw our graphics onto. In Mittsu this is called a renderer. It provides a window and an OpenGL context:
|
108
|
-
|
109
|
-
```ruby
|
110
|
-
renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: 'Hello, World!'
|
111
|
-
```
|
112
|
-
This will give us an 800x600 window with the title `Hello, World!`.
|
113
|
-
|
114
|
-
Now that we have our canvas, let's start setting up the scene we wish to draw onto it:
|
115
|
-
|
116
|
-
```ruby
|
117
|
-
scene = Mittsu::Scene.new
|
118
54
|
```
|
119
55
|
|
120
|
-
|
121
|
-
|
122
|
-
We can't draw a 3D scene without knowing where we're looking:
|
123
|
-
|
124
|
-
```ruby
|
125
|
-
camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)
|
126
|
-
```
|
127
|
-
|
128
|
-
This camera has a 75° field-of-view (FOV), the aspect ratio of the window (which we defined earlier), and shows everything between a distance of 0.1 to 1000.0 away from the camera.
|
129
|
-
|
130
|
-
The camera starts off at the origin `[0,0,0]` and faces the negative Z-axis. We'll position it somewhere along the positive Z-axis so that it is looking at the center of the scene from a short distance:
|
56
|
+
## More Resources
|
131
57
|
|
132
|
-
|
133
|
-
camera.position.z = 5.0
|
134
|
-
```
|
135
|
-
|
136
|
-
Our scene isn't going to be very exciting if there is nothing in it, so we'll create a box:
|
137
|
-
|
138
|
-
```ruby
|
139
|
-
box = Mittsu::Mesh.new(
|
140
|
-
Mittsu::BoxGeometry.new(1.0, 1.0, 1.0),
|
141
|
-
Mittsu::MeshBasicMaterial.new(color: 0x00ff00)
|
142
|
-
)
|
143
|
-
```
|
144
|
-
|
145
|
-
A `Mesh` in Mittsu is the combination of a `Geometry` (the shape of the object) and a `Material` (the "look" of the object). Here we've created a 1x1x1 box that is colored green.
|
146
|
-
|
147
|
-
Box in hand, we make it part of our scene:
|
148
|
-
|
149
|
-
```ruby
|
150
|
-
scene.add(box)
|
151
|
-
```
|
152
|
-
|
153
|
-
Here comes the fun part... the render loop!
|
154
|
-
|
155
|
-
```ruby
|
156
|
-
renderer.window.run do
|
157
|
-
```
|
158
|
-
|
159
|
-
The given block is called every frame. This is where you can tell the renderer what scene to draw, and do any updates to the objects in your scene.
|
160
|
-
|
161
|
-
Just to make things a bit more interesting, we'll make the box rotate around its X and Y axes, so that it spins like crazy.
|
162
|
-
|
163
|
-
```ruby
|
164
|
-
box.rotation.x += 0.1
|
165
|
-
box.rotation.y += 0.1
|
166
|
-
```
|
167
|
-
|
168
|
-
Last but not least, we tell the renderer to draw our scene this frame, which will tell the graphics processor to draw our green box with its updated rotation.
|
169
|
-
|
170
|
-
```ruby
|
171
|
-
renderer.render(scene, camera)
|
172
|
-
```
|
173
|
-
|
174
|
-
Easy peasy! :)
|
58
|
+
Mittsu follows a similar structure to THREE.js, so you can generally use [the same documentation](http://threejs.org/docs/) for a description of the various classes and how they work.
|
175
59
|
|
176
|
-
|
177
|
-
end
|
178
|
-
```
|
60
|
+
If you want to actually render scenes, you'll need a renderer. There is a reference OpenGL renderer [here](https://github.com/danini-the-panini/mittsu-opengl).
|
179
61
|
|
62
|
+
## See also
|
180
63
|
|
181
|
-
|
64
|
+
- [Tank Demo](https://github.com/danini-the-panini/mittsu-tank-demo)
|
65
|
+
- [OpenGL Renderer](https://github.com/danini-the-panini/mittsu-opengl)
|
66
|
+
- [Mesh Analysis](https://github.com/manyfold3d/mittsu-mesh_analysis)
|
67
|
+
- [3MF Support](https://github.com/manyfold3d/mittsu-3mf)
|
182
68
|
|
183
|
-
|
69
|
+
## Where is Mittsu used?
|
184
70
|
|
185
|
-
|
71
|
+
- [Manyfold](https://github.com/manyfold3d/manyfold) - A self-hosted digital asset manager for 3d print files.
|
186
72
|
|
187
73
|
## Where you can help
|
188
74
|
|
189
75
|
1. Testing!
|
190
76
|
|
191
|
-
Currently the only unit tests are for most of the maths library
|
77
|
+
Currently the only unit tests are for most of the maths library.
|
192
78
|
|
193
79
|
2. Refactoring!
|
194
80
|
|
data/bin/console
CHANGED
@@ -6,9 +6,5 @@ require "mittsu"
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
9
|
require "irb"
|
14
10
|
IRB.start
|
@@ -40,7 +40,7 @@ module Mittsu
|
|
40
40
|
@camera_nz.look_at(Mittsu::Vector3.new(0.0, 0.0, -1.0))
|
41
41
|
self.add(@camera_nz)
|
42
42
|
|
43
|
-
@render_target = Mittsu::
|
43
|
+
@render_target = Mittsu::RenderTargetCube(cube_resolution, format: Mittsu::RGBFormat, mag_filter: Mittsu::LinearFilter, min_filter: Mittsu::LinearFilter)
|
44
44
|
end
|
45
45
|
|
46
46
|
def update_cube_map(renderer, scene)
|
data/lib/mittsu/core/geometry.rb
CHANGED
@@ -397,7 +397,7 @@ module Mittsu
|
|
397
397
|
end
|
398
398
|
|
399
399
|
def merge_mesh(mesh)
|
400
|
-
if mesh
|
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 <<
|
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
|
-
|
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
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
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
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Mittsu
|
2
|
+
class Uniform
|
3
|
+
attr_accessor :type, :value, :needs_update, :array
|
4
|
+
|
5
|
+
def initialize(type, value)
|
6
|
+
super()
|
7
|
+
@type, @value = type, value
|
8
|
+
@needs_update = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def clone
|
12
|
+
new_value = case self.value
|
13
|
+
when Color, Vector2, Vector3, Vector4, Matrix4#, Texture # TODO: when Texture exists
|
14
|
+
self.value.clone
|
15
|
+
when Array
|
16
|
+
self.value.dup
|
17
|
+
else
|
18
|
+
self.value
|
19
|
+
end
|
20
|
+
Uniform.new(self.type, new_value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/mittsu/core.rb
CHANGED
@@ -53,7 +53,7 @@ module Mittsu
|
|
53
53
|
|
54
54
|
when FACE_PATTERN then parse_face(line)
|
55
55
|
|
56
|
-
when OBJECT_PATTERN then
|
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
|
109
|
-
|
110
|
-
|
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
|
-
|
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
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
3
|
+
module Mittsu
|
4
|
+
class STLLoader
|
5
|
+
include EventDispatcher
|
6
|
+
|
7
|
+
FLOAT = /[\d|.|+|\-|e]+/
|
8
|
+
NORMAL_PATTERN = /normal\s+(#{FLOAT})\s+(#{FLOAT})\s+(#{FLOAT})/
|
9
|
+
VERTEX_PATTERN = /^\s*vertex\s+(#{FLOAT})\s+(#{FLOAT})\s+(#{FLOAT})/
|
10
|
+
|
11
|
+
def initialize(manager = DefaultLoadingManager)
|
12
|
+
@manager = manager
|
13
|
+
@_listeners = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def load(url)
|
17
|
+
loader = FileLoader.new(@manager)
|
18
|
+
|
19
|
+
data = loader.load(url)
|
20
|
+
parse(data)
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse(data)
|
24
|
+
reset_loader_vars
|
25
|
+
stream = StringIO.new(data, "rb")
|
26
|
+
# Load STL header (first 80 bytes max)
|
27
|
+
header = stream.read(80)
|
28
|
+
if header.slice(0,5) === "solid"
|
29
|
+
stream.rewind
|
30
|
+
parse_ascii(stream)
|
31
|
+
else
|
32
|
+
parse_binary(stream)
|
33
|
+
end
|
34
|
+
@group
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def reset_loader_vars
|
40
|
+
@vertex_hash = {}
|
41
|
+
@vertex_count = 0
|
42
|
+
@line_num = 0
|
43
|
+
@group = Group.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_ascii(stream)
|
47
|
+
while line = read_line(stream)
|
48
|
+
case line
|
49
|
+
when /^\s*solid/
|
50
|
+
parse_ascii_solid(stream)
|
51
|
+
else
|
52
|
+
raise_error
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse_ascii_solid(stream)
|
58
|
+
vertices = []
|
59
|
+
faces = []
|
60
|
+
while line = read_line(stream)
|
61
|
+
case line
|
62
|
+
when /^\s*facet/
|
63
|
+
facet_vertices, face = parse_ascii_facet(line, stream)
|
64
|
+
vertices += facet_vertices
|
65
|
+
faces << face
|
66
|
+
when /^\s*endsolid/
|
67
|
+
break
|
68
|
+
else
|
69
|
+
raise_error
|
70
|
+
end
|
71
|
+
end
|
72
|
+
add_mesh vertices, faces
|
73
|
+
end
|
74
|
+
|
75
|
+
def parse_ascii_facet(line, stream)
|
76
|
+
vertices = []
|
77
|
+
normal = nil
|
78
|
+
if line.match NORMAL_PATTERN
|
79
|
+
normal = Vector3.new($1, $2, $3)
|
80
|
+
end
|
81
|
+
while line = read_line(stream)
|
82
|
+
case line
|
83
|
+
when /^\s*outer loop/
|
84
|
+
nil # Ignored
|
85
|
+
when /^\s*endloop/
|
86
|
+
nil # Ignored
|
87
|
+
when VERTEX_PATTERN
|
88
|
+
vertices << Vector3.new($1, $2, $3)
|
89
|
+
when /^\s*endfacet/
|
90
|
+
break
|
91
|
+
else
|
92
|
+
raise_error
|
93
|
+
end
|
94
|
+
end
|
95
|
+
return nil if vertices.length != 3
|
96
|
+
# Merge with existing vertices
|
97
|
+
face, new_vertices = face_with_merged_vertices(vertices)
|
98
|
+
face.normal = normal
|
99
|
+
return new_vertices, face
|
100
|
+
end
|
101
|
+
|
102
|
+
def parse_binary(stream)
|
103
|
+
vertices = []
|
104
|
+
faces = []
|
105
|
+
num_faces = stream.read(4).unpack('L<').first
|
106
|
+
num_faces.times do |i|
|
107
|
+
# Face normal
|
108
|
+
normal = read_binary_vector(stream)
|
109
|
+
# Vertices
|
110
|
+
face_vertices = []
|
111
|
+
face_vertices << read_binary_vector(stream)
|
112
|
+
face_vertices << read_binary_vector(stream)
|
113
|
+
face_vertices << read_binary_vector(stream)
|
114
|
+
# Throw away the attribute bytes
|
115
|
+
stream.read(2)
|
116
|
+
# Store data
|
117
|
+
face, new_vertices = face_with_merged_vertices(face_vertices)
|
118
|
+
face.normal = normal
|
119
|
+
faces << face
|
120
|
+
vertices += new_vertices
|
121
|
+
end
|
122
|
+
add_mesh vertices, faces
|
123
|
+
end
|
124
|
+
|
125
|
+
def face_with_merged_vertices(vertices)
|
126
|
+
new_vertices = []
|
127
|
+
indices = []
|
128
|
+
vertices.each do |v|
|
129
|
+
index, is_new = vertex_index(v)
|
130
|
+
indices << index
|
131
|
+
if is_new
|
132
|
+
new_vertices << v
|
133
|
+
@vertex_count += 1
|
134
|
+
end
|
135
|
+
end
|
136
|
+
# Return face and new vertex list
|
137
|
+
return Face3.new(
|
138
|
+
indices[0],
|
139
|
+
indices[1],
|
140
|
+
indices[2]
|
141
|
+
), new_vertices
|
142
|
+
end
|
143
|
+
|
144
|
+
def vertex_index(vertex)
|
145
|
+
key = vertex_key(vertex)
|
146
|
+
if i = @vertex_hash[key]
|
147
|
+
return i, false
|
148
|
+
else
|
149
|
+
return (@vertex_hash[key] = @vertex_count), true
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def vertex_key(vertex)
|
154
|
+
vertex.elements.pack("D*")
|
155
|
+
end
|
156
|
+
|
157
|
+
def add_mesh(vertices, faces)
|
158
|
+
geometry = Geometry.new
|
159
|
+
geometry.vertices = vertices
|
160
|
+
geometry.faces = faces
|
161
|
+
geometry.compute_bounding_sphere
|
162
|
+
@group.add Mesh.new(geometry)
|
163
|
+
end
|
164
|
+
|
165
|
+
def read_binary_vector(stream)
|
166
|
+
Vector3.new(
|
167
|
+
read_le_float(stream),
|
168
|
+
read_le_float(stream),
|
169
|
+
read_le_float(stream)
|
170
|
+
)
|
171
|
+
end
|
172
|
+
|
173
|
+
def read_le_float(stream)
|
174
|
+
stream.read(4).unpack('e').first
|
175
|
+
end
|
176
|
+
|
177
|
+
def read_line(stream)
|
178
|
+
@line_num += 1
|
179
|
+
stream.gets
|
180
|
+
end
|
181
|
+
|
182
|
+
def raise_error
|
183
|
+
raise "Mittsu::STLLoader: Unhandled line #{@line_num}"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
data/lib/mittsu/loaders.rb
CHANGED