mittsu 0.4.1 → 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 +3 -38
- 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/uniform.rb +23 -0
- data/lib/mittsu/core.rb +1 -0
- data/lib/mittsu/loaders/stl_loader.rb +186 -0
- data/lib/mittsu/loaders.rb +1 -0
- 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 +28 -199
- data/install-glfw.ps1 +0 -13
- data/lib/mittsu/renderers/generic_lib.rb +0 -125
- data/lib/mittsu/renderers/glfw_lib.rb +0 -64
- 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,23 +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
16
|
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', 'head']
|
17
17
|
steps:
|
18
18
|
- uses: actions/checkout@v4
|
19
|
-
- uses: awalsh128/cache-apt-pkgs-action@v1
|
20
|
-
with:
|
21
|
-
packages: libglfw3
|
22
19
|
- uses: ruby/setup-ruby@v1
|
23
20
|
with:
|
24
21
|
ruby-version: ${{ matrix.ruby }}
|
25
22
|
bundler-cache: true
|
26
23
|
- name: Test & publish code coverage
|
27
|
-
uses: paambaati/codeclimate-action@
|
24
|
+
uses: paambaati/codeclimate-action@v9.0.0
|
28
25
|
if: github.event_name == 'push'
|
29
26
|
env:
|
30
27
|
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
@@ -33,35 +30,3 @@ jobs:
|
|
33
30
|
- name: Test
|
34
31
|
if: github.event_name != 'push'
|
35
32
|
run: bundle exec rake test
|
36
|
-
|
37
|
-
macos:
|
38
|
-
name: macOS
|
39
|
-
runs-on: macos-latest
|
40
|
-
strategy:
|
41
|
-
matrix:
|
42
|
-
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', 'head']
|
43
|
-
steps:
|
44
|
-
- uses: actions/checkout@v4
|
45
|
-
- run: brew install glfw
|
46
|
-
- uses: ruby/setup-ruby@v1
|
47
|
-
with:
|
48
|
-
ruby-version: ${{ matrix.ruby }}
|
49
|
-
bundler-cache: true
|
50
|
-
- run: bundle exec rake test
|
51
|
-
|
52
|
-
windows:
|
53
|
-
name: Windows
|
54
|
-
runs-on: windows-latest
|
55
|
-
env:
|
56
|
-
MITTSU_LIBGLFW_PATH: c:\projects\mittsu\glfw-3.3.1.bin.WIN32\lib-mingw
|
57
|
-
strategy:
|
58
|
-
matrix:
|
59
|
-
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3', 'head']
|
60
|
-
steps:
|
61
|
-
- uses: actions/checkout@v4
|
62
|
-
- run: .\install-glfw.ps1
|
63
|
-
- uses: ruby/setup-ruby@v1
|
64
|
-
with:
|
65
|
-
ruby-version: ${{ matrix.ruby }}
|
66
|
-
bundler-cache: true
|
67
|
-
- 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)
|
@@ -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
@@ -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
@@ -0,0 +1,93 @@
|
|
1
|
+
module Mittsu
|
2
|
+
class RenderTarget < Texture
|
3
|
+
include EventDispatcher
|
4
|
+
|
5
|
+
attr_accessor :width,
|
6
|
+
:height,
|
7
|
+
:wrap_s,
|
8
|
+
:wrap_t,
|
9
|
+
:mag_filter,
|
10
|
+
:min_filter,
|
11
|
+
:anisotropy,
|
12
|
+
:offset,
|
13
|
+
:repeat,
|
14
|
+
:format,
|
15
|
+
:type,
|
16
|
+
:depth_buffer,
|
17
|
+
:stencil_buffer,
|
18
|
+
:generate_mipmaps,
|
19
|
+
:share_depth_from
|
20
|
+
|
21
|
+
attr_reader :framebuffer
|
22
|
+
|
23
|
+
attr_writer :renderer
|
24
|
+
|
25
|
+
def initialize(width, height, options = {})
|
26
|
+
super(self, nil)
|
27
|
+
|
28
|
+
@width = width
|
29
|
+
@height = height
|
30
|
+
|
31
|
+
@wrap_s = options.fetch(:wrap_s, ClampToEdgeWrapping)
|
32
|
+
@wrap_t = options.fetch(:wrap_t, ClampToEdgeWrapping)
|
33
|
+
|
34
|
+
@mag_filter = options.fetch(:mag_filter, LinearFilter)
|
35
|
+
@min_filter = options.fetch(:min_filter, LinearMipMapLinearFilter)
|
36
|
+
|
37
|
+
@anisotropy = options.fetch(:anisotropy, 1.0);
|
38
|
+
|
39
|
+
@offset = Vector2.new(0.0, 0.0)
|
40
|
+
@repeat = Vector2.new(1.0, 1.0)
|
41
|
+
|
42
|
+
@format = options.fetch(:format, RGBAFormat)
|
43
|
+
@type = options.fetch(:type, UnsignedByteType)
|
44
|
+
|
45
|
+
@depth_buffer = options.fetch(:depth_buffer, true)
|
46
|
+
@stencil_buffer = options.fetch(:stencil_buffer, true)
|
47
|
+
|
48
|
+
@generate_mipmaps = true
|
49
|
+
|
50
|
+
@share_depth_from = options.fetch(:share_depth_from, nil)
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_size(width, height)
|
54
|
+
@width = width
|
55
|
+
@height = height
|
56
|
+
end
|
57
|
+
|
58
|
+
def needs_update?
|
59
|
+
false
|
60
|
+
end
|
61
|
+
|
62
|
+
def clone
|
63
|
+
RenderTarget.new(@width, @height).tap do |tmp|
|
64
|
+
tmp.renderer = @renderer
|
65
|
+
|
66
|
+
tmp.wrap_s = @wrap_s
|
67
|
+
tmp.wrap_t = @wrap_t
|
68
|
+
|
69
|
+
tmp.mag_filter = @mag_filter
|
70
|
+
tmp.min_filter = @min_filter
|
71
|
+
|
72
|
+
tmp.anisotropy = @anisotropy
|
73
|
+
|
74
|
+
tmp.offset.copy(@offset)
|
75
|
+
tmp.repeat.copy(@repeat)
|
76
|
+
|
77
|
+
tmp.format = @format
|
78
|
+
tmp.type = @type
|
79
|
+
|
80
|
+
tmp.depth_buffer = @depth_buffer
|
81
|
+
tmp.stencil_buffer = @stencil_buffer
|
82
|
+
|
83
|
+
tmp.generate_mipmaps = @generate_mipmaps
|
84
|
+
|
85
|
+
tmp.share_depth_from = @share_depth_from
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def dispose
|
90
|
+
dispatch_event(type: :dispose)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -39,7 +39,7 @@ module Mittsu
|
|
39
39
|
@generate_mipmaps = true
|
40
40
|
@premultiply_alpha = false
|
41
41
|
@filp_y = true
|
42
|
-
@unpack_alignment = 4 # valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/
|
42
|
+
@unpack_alignment = 4 # valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/GL.PixelStorei.xml)
|
43
43
|
|
44
44
|
@_needs_update = false
|
45
45
|
@on_update = nil
|
data/lib/mittsu/textures.rb
CHANGED
data/lib/mittsu/version.rb
CHANGED