voxelamming 0.2.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/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +95 -0
- data/Rakefile +8 -0
- data/index.html +139 -0
- data/lib/matrix_util.rb +65 -0
- data/lib/voxelamming/version.rb +5 -0
- data/lib/voxelamming.rb +549 -0
- data/sig/voxelamming.rbs +4 -0
- metadata +74 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fd127d3be01c9626c89f8c30261e386d693f003e4fd5d98ada6e429d768d64df
|
|
4
|
+
data.tar.gz: 424aaa454b52aeee6fd8a4d2c986422e31824e1e66949d4d4dedf94806038799
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8affe5c143e5f915ff5d19bf9763c01474ea091431c3d77e62dc0d2b2728cbe8f19e03dcd74a5b86f6460baac0a1f157a57929debacc9d92e38918b81ab300a9
|
|
7
|
+
data.tar.gz: 9705d0420d514da88f9551ccdb74b06f5260fbb18afef47f89fe74589917897e85aa5c84560388a24c3f7b017da0d3681d63e94edabfb9cd5a87743a702e4608
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
[INSERT CONTACT METHOD].
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 creativival
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# VoxelammingGem
|
|
2
|
+
|
|
3
|
+
This Ruby package converts Python code into JSON format and sends it to the Voxelamming app using WebSockets, allowing users to create 3D voxel models by writing Ruby scripts.
|
|
4
|
+
|
|
5
|
+
## What's Voxelamming?
|
|
6
|
+
|
|
7
|
+
<p align="center"><img src="https://creativival.github.io/voxelamming/image/voxelamming_icon.png" alt="Voxelamming Logo" width="200"/></p>
|
|
8
|
+
|
|
9
|
+
Voxelamming is an AR programming learning app. Even programming beginners can learn programming visually and enjoyably. Voxelamming supports iPhones and iPads with iOS 16 or later, and Apple Vision Pro.
|
|
10
|
+
|
|
11
|
+
## Resources
|
|
12
|
+
|
|
13
|
+
* **Homepage:** https://creativival.github.io/voxelamming/index.en
|
|
14
|
+
* **Samples:** https://github.com/creativival/voxelamming/tree/main/sample/ruby
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
gem install voxelamming
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
require 'voxelamming'
|
|
27
|
+
|
|
28
|
+
room_name = '1000'
|
|
29
|
+
build_box = Voxelamming::BuildBox.new(room_name)
|
|
30
|
+
|
|
31
|
+
build_box.set_box_size(0.5)
|
|
32
|
+
build_box.set_build_interval(0.01)
|
|
33
|
+
|
|
34
|
+
for i in 0...100
|
|
35
|
+
build_box.create_box(-1, i, 0, r: 0, g: 1, b: 1)
|
|
36
|
+
build_box.create_box(0, i, 0, r: 1, g: 0, b: 0)
|
|
37
|
+
build_box.create_box(1, i, 0, r: 1, g: 1, b: 0)
|
|
38
|
+
build_box.create_box(2, i, 0, r: 0, g: 1, b: 1)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
for i in 0...50
|
|
42
|
+
build_box.remove_box(0, i * 2, 0)
|
|
43
|
+
build_box.remove_box(1, i * 2 + 1, 0)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
build_box.send_data
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This code snippet demonstrates a simple example where a red voxel is created at a specific location. You can use various functions provided by the `BuildBox` class to build more complex models.
|
|
50
|
+
|
|
51
|
+
#### Method description
|
|
52
|
+
|
|
53
|
+
| Method name | Description | Arguments |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| `set_room_name(room_name)` | Sets the room name for communicating with the device. | `room_name`: Room name (string) |
|
|
56
|
+
| `set_box_size(size)` | Sets the size of the voxel (default: 1.0). | `size`: Size (float) |
|
|
57
|
+
| `set_build_interval(interval)` | Sets the placement interval of the voxels (default: 0.01 seconds). | `interval`: Interval (float) |
|
|
58
|
+
| `change_shape(shape)` | Changes the shape of the voxel. | `shape`: Shape ("box", "square", "plane") |
|
|
59
|
+
| `change_material(is_metallic, roughness)` | Changes the material of the voxel. | `is_metallic`: Whether to make it metallic (boolean), `roughness`: Roughness (float) |
|
|
60
|
+
| `create_box(x, y, z, r, g, b, alpha)` | Places a voxel. | `x`, `y`, `z`: Position (float), `r`, `g`, `b`, `alpha`: Color (float, 0-1) |
|
|
61
|
+
| `create_box(x, y, z, texture)` | Places a voxel with texture. | `x`, `y`, `z`: Position (float), `texture`: Texture name (string) |
|
|
62
|
+
| `remove_box(x, y, z)` | Removes a voxel. | `x`, `y`, `z`: Position (float) |
|
|
63
|
+
| `write_sentence(sentence, x, y, z, r, g, b, alpha)` | Draws a string with voxels. | `sentence`: String (string), `x`, `y`, `z`: Position (float), `r`, `g`, `b`, `alpha`: Color (float, 0-1) |
|
|
64
|
+
| `set_light(x, y, z, r, g, b, alpha, intensity, interval, light_type)` | Places a light. | `x`, `y`, `z`: Position (float), `r`, `g`, `b`, `alpha`: Color (float, 0-1), `intensity`: Intensity (float), `interval`: Blinking interval (float), `light_type`: Type of light ("point", "spot", "directional") |
|
|
65
|
+
| `set_command(command)` | Executes a command. | `command`: Command ("axis", "japaneseCastle", "float", "liteRender") |
|
|
66
|
+
| `draw_line(x1, y1, z1, x2, y2, z2, r, g, b, alpha)` | Draws a line between two points. | `x1`, `y1`, `z1`: Starting point (float), `x2`, `y2`, `z2`: Ending point (float), `r`, `g`, `b`, `alpha`: Color (float, 0-1) |
|
|
67
|
+
| `send_data(name)` | Sends voxel data to the device; if the name argument is set, the voxel data can be stored and reproduced as history. | |
|
|
68
|
+
| `clear_data()` | Initializes voxel data. | |
|
|
69
|
+
| `transform(x, y, z, pitch, yaw, roll)` | Moves and rotates the coordinate system of the voxel. | `x`, `y`, `z`: Translation amount (float), `pitch`, `yaw`, `roll`: Rotation amount (float) |
|
|
70
|
+
| `animate(x, y, z, pitch, yaw, roll, scale, interval)` | Animates a voxel. | `x`, `y`, `z`: Translation amount (float), `pitch`, `yaw`, `roll`: Rotation amount (float), `scale`: Scale (float), `interval`: Interval (float) |
|
|
71
|
+
| `animate_global(x, y, z, pitch, yaw, roll, scale, interval)` | Animates all voxels. | `x`, `y`, `z`: Translation amount (float), `pitch`, `yaw`, `roll`: Rotation amount (float), `scale`: Scale (float), `interval`: Interval (float) |
|
|
72
|
+
| `push_matrix()` | Saves the current coordinate system to the stack. | |
|
|
73
|
+
| `pop_matrix()` | Restores the coordinate system from the stack. | |
|
|
74
|
+
| `frame_in()` | Starts recording a frame. | |
|
|
75
|
+
| `frame_out()` | Ends recording a frame. | |
|
|
76
|
+
| `set_frame_fps(fps)` | Sets the frame rate (default: 2). | `fps`: Frame rate (int) |
|
|
77
|
+
| `set_frame_repeats(repeats)` | Sets the number of frame repetitions (default: 10). | `repeats`: Number of repetitions (int) |
|
|
78
|
+
|
|
79
|
+
## Development
|
|
80
|
+
|
|
81
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
82
|
+
|
|
83
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
84
|
+
|
|
85
|
+
## Contributing
|
|
86
|
+
|
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/creativival/voxelamming_ruby_gem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/voxelamming_gem/blob/master/CODE_OF_CONDUCT.md).
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
92
|
+
|
|
93
|
+
## Code of Conduct
|
|
94
|
+
|
|
95
|
+
Everyone interacting in the VoxelammingGem project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/voxelamming_gem/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/index.html
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<title>VoxelammingGem</title>
|
|
6
|
+
<style>
|
|
7
|
+
body {
|
|
8
|
+
font-family: sans-serif;
|
|
9
|
+
line-height: 1.6;
|
|
10
|
+
margin: 2rem auto;
|
|
11
|
+
max-width: 800px;
|
|
12
|
+
padding: 0 1rem;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
h1, h2, h3 {
|
|
16
|
+
margin-top: 1.5rem;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
a {
|
|
20
|
+
color: #0645ad;
|
|
21
|
+
text-decoration: none;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
a:hover {
|
|
25
|
+
text-decoration: underline;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
img {
|
|
29
|
+
max-width: 100%;
|
|
30
|
+
height: auto;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
pre {
|
|
34
|
+
background-color: #f5f5f5;
|
|
35
|
+
border: 1px solid #ccc;
|
|
36
|
+
overflow-x: auto;
|
|
37
|
+
padding: 1rem;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
code {
|
|
41
|
+
font-family: monospace;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
table {
|
|
45
|
+
border-collapse: collapse;
|
|
46
|
+
width: 100%;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
th, td {
|
|
50
|
+
border: 1px solid #ccc;
|
|
51
|
+
padding: 0.5rem;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
th {
|
|
55
|
+
background-color: #f0f0f0;
|
|
56
|
+
font-weight: bold;
|
|
57
|
+
}
|
|
58
|
+
</style>
|
|
59
|
+
</head>
|
|
60
|
+
<body>
|
|
61
|
+
<h1><a href="#voxelamminggem" id="voxelamminggem"></a>VoxelammingGem</h1>
|
|
62
|
+
<p>This Ruby package converts Python code into JSON format and sends it to the Voxelamming app using WebSockets, allowing users to create 3D voxel models by writing Ruby scripts.</p>
|
|
63
|
+
<h2><a href="#whats-voxelamming" id="whats-voxelamming"></a>What's Voxelamming?</h2>
|
|
64
|
+
<p align="center"><img src="https://creativival.github.io/voxelamming/image/voxelamming_icon.png" alt="Voxelamming Logo" width="200"/></p>
|
|
65
|
+
<p>Voxelamming is an AR programming learning app. Even programming beginners can learn programming visually and enjoyably. Voxelamming supports iPhones and iPads with iOS 16 or later, and Apple Vision Pro.</p>
|
|
66
|
+
<h2><a href="#resources" id="resources"></a>Resources</h2>
|
|
67
|
+
<ul>
|
|
68
|
+
<li><strong>Homepage:</strong> <a href="https://creativival.github.io/voxelamming/index.en">https://creativival.github.io/voxelamming/index.en</a></li>
|
|
69
|
+
<li><strong>Samples:</strong> <a href="https://github.com/creativival/voxelamming/tree/main/sample/ruby">https://github.com/creativival/voxelamming/tree/main/sample/ruby</a></li>
|
|
70
|
+
</ul>
|
|
71
|
+
<h2><a href="#installation" id="installation"></a>Installation</h2>
|
|
72
|
+
<pre><code class="bash">gem install voxelamming
|
|
73
|
+
</code></pre>
|
|
74
|
+
<h2><a href="#usage" id="usage"></a>Usage</h2>
|
|
75
|
+
<pre><code class="ruby">require 'voxelamming'
|
|
76
|
+
|
|
77
|
+
room_name = '1000'
|
|
78
|
+
build_box = Voxelamming::BuildBox.new(room_name)
|
|
79
|
+
|
|
80
|
+
build_box.set_box_size(0.5)
|
|
81
|
+
build_box.set_build_interval(0.01)
|
|
82
|
+
|
|
83
|
+
for i in 0...100
|
|
84
|
+
build_box.create_box(-1, i, 0, r: 0, g: 1, b: 1)
|
|
85
|
+
build_box.create_box(0, i, 0, r: 1, g: 0, b: 0)
|
|
86
|
+
build_box.create_box(1, i, 0, r: 1, g: 1, b: 0)
|
|
87
|
+
build_box.create_box(2, i, 0, r: 0, g: 1, b: 1)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
for i in 0...50
|
|
91
|
+
build_box.remove_box(0, i * 2, 0)
|
|
92
|
+
build_box.remove_box(1, i * 2 + 1, 0)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
build_box.send_data
|
|
96
|
+
</code></pre>
|
|
97
|
+
<p>This code snippet demonstrates a simple example where a red voxel is created at a specific location. You can use various functions provided by the <code>BuildBox</code> class to build more complex models.</p>
|
|
98
|
+
<h4><a href="#method-description" id="method-description"></a>Method description</h4>
|
|
99
|
+
<table>
|
|
100
|
+
<thead>
|
|
101
|
+
<tr><th> Method name </th><th> Description </th><th> Arguments </th></tr>
|
|
102
|
+
</thead>
|
|
103
|
+
<tbody>
|
|
104
|
+
<tr><td> <code>set_room_name(room_name)</code> </td><td> Sets the room name for communicating with the device. </td><td> <code>room_name</code>: Room name (string) </td></tr>
|
|
105
|
+
<tr><td> <code>set_box_size(size)</code> </td><td> Sets the size of the voxel (default: 1.0). </td><td> <code>size</code>: Size (float) </td></tr>
|
|
106
|
+
<tr><td> <code>set_build_interval(interval)</code> </td><td> Sets the placement interval of the voxels (default: 0.01 seconds). </td><td> <code>interval</code>: Interval (float) </td></tr>
|
|
107
|
+
<tr><td> <code>change_shape(shape)</code> </td><td> Changes the shape of the voxel. </td><td> <code>shape</code>: Shape ("box", "square", "plane") </td></tr>
|
|
108
|
+
<tr><td> <code>change_material(is_metallic, roughness)</code> </td><td> Changes the material of the voxel. </td><td> <code>is_metallic</code>: Whether to make it metallic (boolean), <code>roughness</code>: Roughness (float) </td></tr>
|
|
109
|
+
<tr><td> <code>create_box(x, y, z, r, g, b, alpha)</code> </td><td> Places a voxel. </td><td> <code>x</code>, <code>y</code>, <code>z</code>: Position (float), <code>r</code>, <code>g</code>, <code>b</code>, <code>alpha</code>: Color (float, 0-1) </td></tr>
|
|
110
|
+
<tr><td> <code>create_box(x, y, z, texture)</code> </td><td> Places a voxel with texture. </td><td> <code>x</code>, <code>y</code>, <code>z</code>: Position (float), <code>texture</code>: Texture name (string) </td></tr>
|
|
111
|
+
<tr><td> <code>remove_box(x, y, z)</code> </td><td> Removes a voxel. </td><td> <code>x</code>, <code>y</code>, <code>z</code>: Position (float) </td></tr>
|
|
112
|
+
<tr><td> <code>write_sentence(sentence, x, y, z, r, g, b, alpha)</code> </td><td> Draws a string with voxels. </td><td> <code>sentence</code>: String (string), <code>x</code>, <code>y</code>, <code>z</code>: Position (float), <code>r</code>, <code>g</code>, <code>b</code>, <code>alpha</code>: Color (float, 0-1) </td></tr>
|
|
113
|
+
<tr><td> <code>set_light(x, y, z, r, g, b, alpha, intensity, interval, light_type)</code> </td><td> Places a light. </td><td> <code>x</code>, <code>y</code>, <code>z</code>: Position (float), <code>r</code>, <code>g</code>, <code>b</code>, <code>alpha</code>: Color (float, 0-1), <code>intensity</code>: Intensity (float), <code>interval</code>: Blinking interval (float), <code>light_type</code>: Type of light ("point", "spot", "directional") </td></tr>
|
|
114
|
+
<tr><td> <code>set_command(command)</code> </td><td> Executes a command. </td><td> <code>command</code>: Command ("axis", "japaneseCastle", "float", "liteRender") </td></tr>
|
|
115
|
+
<tr><td> <code>draw_line(x1, y1, z1, x2, y2, z2, r, g, b, alpha)</code> </td><td> Draws a line between two points. </td><td> <code>x1</code>, <code>y1</code>, <code>z1</code>: Starting point (float), <code>x2</code>, <code>y2</code>, <code>z2</code>: Ending point (float), <code>r</code>, <code>g</code>, <code>b</code>, <code>alpha</code>: Color (float, 0-1) </td></tr>
|
|
116
|
+
<tr><td> <code>send_data(name)</code> </td><td> Sends voxel data to the device; if the name argument is set, the voxel data can be stored and reproduced as history. </td><td> </td></tr>
|
|
117
|
+
<tr><td> <code>clear_data()</code> </td><td> Initializes voxel data. </td><td> </td></tr>
|
|
118
|
+
<tr><td> <code>transform(x, y, z, pitch, yaw, roll)</code> </td><td> Moves and rotates the coordinate system of the voxel. </td><td> <code>x</code>, <code>y</code>, <code>z</code>: Translation amount (float), <code>pitch</code>, <code>yaw</code>, <code>roll</code>: Rotation amount (float) </td></tr>
|
|
119
|
+
<tr><td> <code>animate(x, y, z, pitch, yaw, roll, scale, interval)</code> </td><td> Animates a voxel. </td><td> <code>x</code>, <code>y</code>, <code>z</code>: Translation amount (float), <code>pitch</code>, <code>yaw</code>, <code>roll</code>: Rotation amount (float), <code>scale</code>: Scale (float), <code>interval</code>: Interval (float) </td></tr>
|
|
120
|
+
<tr><td> <code>animate_global(x, y, z, pitch, yaw, roll, scale, interval)</code> </td><td> Animates all voxels. </td><td> <code>x</code>, <code>y</code>, <code>z</code>: Translation amount (float), <code>pitch</code>, <code>yaw</code>, <code>roll</code>: Rotation amount (float), <code>scale</code>: Scale (float), <code>interval</code>: Interval (float) </td></tr>
|
|
121
|
+
<tr><td> <code>push_matrix()</code> </td><td> Saves the current coordinate system to the stack. </td><td> </td></tr>
|
|
122
|
+
<tr><td> <code>pop_matrix()</code> </td><td> Restores the coordinate system from the stack. </td><td> </td></tr>
|
|
123
|
+
<tr><td> <code>frame_in()</code> </td><td> Starts recording a frame. </td><td> </td></tr>
|
|
124
|
+
<tr><td> <code>frame_out()</code> </td><td> Ends recording a frame. </td><td> </td></tr>
|
|
125
|
+
<tr><td> <code>set_frame_fps(fps)</code> </td><td> Sets the frame rate (default: 2). </td><td> <code>fps</code>: Frame rate (int) </td></tr>
|
|
126
|
+
<tr><td> <code>set_frame_repeats(repeats)</code> </td><td> Sets the number of frame repetitions (default: 10). </td><td> <code>repeats</code>: Number of repetitions (int) </td></tr>
|
|
127
|
+
</tbody>
|
|
128
|
+
</table>
|
|
129
|
+
<h2><a href="#development" id="development"></a>Development</h2>
|
|
130
|
+
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rake test</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
|
|
131
|
+
<p>To install this gem onto your local machine, run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and the created tag, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
|
|
132
|
+
<h2><a href="#contributing" id="contributing"></a>Contributing</h2>
|
|
133
|
+
<p>Bug reports and pull requests are welcome on GitHub at <a href="https://github.com/[USERNAME]/voxelamming_gem">https://github.com/[USERNAME]/voxelamming_gem</a>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the <a href="https://github.com/[USERNAME]/voxelamming_gem/blob/master/CODE_OF_CONDUCT.md">code of conduct</a>.</p>
|
|
134
|
+
<h2><a href="#license" id="license"></a>License</h2>
|
|
135
|
+
<p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
|
|
136
|
+
<h2><a href="#code-of-conduct" id="code-of-conduct"></a>Code of Conduct</h2>
|
|
137
|
+
<p>Everyone interacting in the VoxelammingGem project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the <a href="https://github.com/[USERNAME]/voxelamming_gem/blob/master/CODE_OF_CONDUCT.md">code of conduct</a>.</p>
|
|
138
|
+
</body>
|
|
139
|
+
</html>
|
data/lib/matrix_util.rb
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
include Math
|
|
2
|
+
|
|
3
|
+
def get_rotation_matrix(pitch, yaw, roll)
|
|
4
|
+
pitch, yaw, roll = [pitch, yaw, roll].map { |angle| degrees_to_radians(angle) }
|
|
5
|
+
# Pitch (Rotation around X-axis)
|
|
6
|
+
rx = [
|
|
7
|
+
[1, 0, 0],
|
|
8
|
+
[0, cos(pitch), -sin(pitch)],
|
|
9
|
+
[0, sin(pitch), cos(pitch)]
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
# Yaw (Rotation around Y-axis)
|
|
13
|
+
ry = [
|
|
14
|
+
[cos(yaw), 0, sin(yaw)],
|
|
15
|
+
[0, 1, 0],
|
|
16
|
+
[-sin(yaw), 0, cos(yaw)]
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
# Roll (Rotation around Z-axis)
|
|
20
|
+
rz = [
|
|
21
|
+
[cos(roll), -sin(roll), 0],
|
|
22
|
+
[sin(roll), cos(roll), 0],
|
|
23
|
+
[0, 0, 1]
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
# Multiplication of matrices in the order Rx * Rz * Ry
|
|
27
|
+
r = matrix_multiply(rx, matrix_multiply(rz, ry))
|
|
28
|
+
return r
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def matrix_multiply(a, b)
|
|
32
|
+
result = Array.new(3) { Array.new(3, 0) }
|
|
33
|
+
for i in 0...3
|
|
34
|
+
for j in 0...3
|
|
35
|
+
for k in 0...3
|
|
36
|
+
result[i][j] += a[i][k] * b[k][j]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
return result
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def transform_point_by_rotation_matrix(point, r)
|
|
44
|
+
x, y, z = point
|
|
45
|
+
x_new = r[0][0] * x + r[0][1] * y + r[0][2] * z
|
|
46
|
+
y_new = r[1][0] * x + r[1][1] * y + r[1][2] * z
|
|
47
|
+
z_new = r[2][0] * x + r[2][1] * y + r[2][2] * z
|
|
48
|
+
return [x_new, y_new, z_new]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def add_vectors(vector1, vector2)
|
|
52
|
+
vector1.zip(vector2).map { |v1, v2| v1 + v2 }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def transpose_3x3(matrix)
|
|
56
|
+
return [
|
|
57
|
+
[matrix[0][0], matrix[1][0], matrix[2][0]],
|
|
58
|
+
[matrix[0][1], matrix[1][1], matrix[2][1]],
|
|
59
|
+
[matrix[0][2], matrix[1][2], matrix[2][2]]
|
|
60
|
+
]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def degrees_to_radians(degrees)
|
|
64
|
+
degrees * Math::PI / 180.0
|
|
65
|
+
end
|
data/lib/voxelamming.rb
ADDED
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "voxelamming/version"
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'faye/websocket'
|
|
6
|
+
require 'eventmachine'
|
|
7
|
+
require 'date'
|
|
8
|
+
require_relative 'matrix_util'
|
|
9
|
+
require 'csv'
|
|
10
|
+
|
|
11
|
+
module Voxelamming
|
|
12
|
+
class Error < StandardError; end
|
|
13
|
+
|
|
14
|
+
# test
|
|
15
|
+
def self.greet(name)
|
|
16
|
+
puts "Hello, #{name}! I'm Ruby!"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Main process
|
|
20
|
+
class BuildBox
|
|
21
|
+
@@texture_names = ["grass", "stone", "dirt", "planks", "bricks"]
|
|
22
|
+
@@model_names = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto", "Sun",
|
|
23
|
+
"Moon", "ToyBiplane", "ToyCar", "Drummer", "Robot", "ToyRocket", "RocketToy1", "RocketToy2", "Skull"]
|
|
24
|
+
|
|
25
|
+
def initialize(room_name)
|
|
26
|
+
@room_name = room_name
|
|
27
|
+
@is_allowed_matrix = 0
|
|
28
|
+
@saved_matrices = []
|
|
29
|
+
@node_transform = [0, 0, 0, 0, 0, 0]
|
|
30
|
+
@matrix_transform = [0, 0, 0, 0, 0, 0]
|
|
31
|
+
@frame_transforms = []
|
|
32
|
+
@global_animation = [0, 0, 0, 0, 0, 0, 1, 0]
|
|
33
|
+
@animation = [0, 0, 0, 0, 0, 0, 1, 0]
|
|
34
|
+
@boxes = []
|
|
35
|
+
@frames = []
|
|
36
|
+
@sentence = []
|
|
37
|
+
@lights = []
|
|
38
|
+
@commands = []
|
|
39
|
+
@models = []
|
|
40
|
+
@model_moves = []
|
|
41
|
+
@size = 1
|
|
42
|
+
@shape = 'box'
|
|
43
|
+
@is_metallic = 0
|
|
44
|
+
@roughness = 0.5
|
|
45
|
+
@is_allowed_float = 0
|
|
46
|
+
@build_interval = 0.01
|
|
47
|
+
@is_framing = false
|
|
48
|
+
@frame_id = 0
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def clear_data
|
|
52
|
+
@is_allowed_matrix = 0
|
|
53
|
+
@saved_matrices = []
|
|
54
|
+
@node_transform = [0, 0, 0, 0, 0, 0]
|
|
55
|
+
@matrix_transform = [0, 0, 0, 0, 0, 0]
|
|
56
|
+
@frame_transforms = []
|
|
57
|
+
@global_animation = [0, 0, 0, 0, 0, 0, 1, 0]
|
|
58
|
+
@animation = [0, 0, 0, 0, 0, 0, 1, 0]
|
|
59
|
+
@boxes = []
|
|
60
|
+
@frames = []
|
|
61
|
+
@sentence = []
|
|
62
|
+
@lights = []
|
|
63
|
+
@commands = []
|
|
64
|
+
@models = []
|
|
65
|
+
@model_moves = []
|
|
66
|
+
@size = 1
|
|
67
|
+
@shape = 'box'
|
|
68
|
+
@is_metallic = 0
|
|
69
|
+
@roughness = 0.5
|
|
70
|
+
@is_allowed_float = 0
|
|
71
|
+
@build_interval = 0.01
|
|
72
|
+
@is_framing = false
|
|
73
|
+
@frame_id = 0
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def set_frame_fps(fps = 2)
|
|
77
|
+
@commands << "fps #{fps}"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def set_frame_repeats(repeats = 10)
|
|
81
|
+
@commands << "repeats #{repeats}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def frame_in
|
|
85
|
+
@is_framing = true
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def frame_out
|
|
89
|
+
@is_framing = false
|
|
90
|
+
@frame_id += 1
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def push_matrix
|
|
94
|
+
@is_allowed_matrix += 1
|
|
95
|
+
@saved_matrices.push(@matrix_transform)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def pop_matrix
|
|
99
|
+
@is_allowed_matrix -= 1
|
|
100
|
+
@matrix_transform = @saved_matrices.pop
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def transform(x, y, z, pitch: 0, yaw: 0, roll: 0)
|
|
104
|
+
if @is_allowed_matrix > 0
|
|
105
|
+
# 移動用のマトリックスを計算する
|
|
106
|
+
matrix = @saved_matrices.last
|
|
107
|
+
puts "before matrix: #{matrix}"
|
|
108
|
+
base_position = matrix[0..2]
|
|
109
|
+
|
|
110
|
+
if matrix.length == 6
|
|
111
|
+
base_rotation_matrix = get_rotation_matrix(matrix[3], matrix[4], matrix[5])
|
|
112
|
+
else
|
|
113
|
+
base_rotation_matrix = [matrix[3..5], matrix[6..8], matrix[9..11]]
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Compute the new position after transform
|
|
117
|
+
add_x, add_y, add_z = transform_point_by_rotation_matrix([x, y, z], transpose_3x3(base_rotation_matrix))
|
|
118
|
+
x, y, z = add_vectors(base_position, [add_x, add_y, add_z])
|
|
119
|
+
x, y, z = round_numbers([x, y, z])
|
|
120
|
+
|
|
121
|
+
# Compute the rotation after transform
|
|
122
|
+
translate_rotation_matrix = get_rotation_matrix(-pitch, -yaw, -roll)
|
|
123
|
+
rotate_matrix = matrix_multiply(translate_rotation_matrix, base_rotation_matrix)
|
|
124
|
+
@matrix_transform = [x, y, z, *rotate_matrix[0], *rotate_matrix[1], *rotate_matrix[2]]
|
|
125
|
+
else
|
|
126
|
+
x, y, z = round_numbers([x, y, z])
|
|
127
|
+
|
|
128
|
+
if @is_framing
|
|
129
|
+
@frame_transforms.append([x, y, z, pitch, yaw, roll, @frame_id])
|
|
130
|
+
else
|
|
131
|
+
@node_transform = [x, y, z, pitch, yaw, roll]
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def create_box(x, y, z, r: 1, g: 1, b: 1, alpha: 1, texture: '')
|
|
137
|
+
if @is_allowed_matrix > 0
|
|
138
|
+
# 移動用のマトリックスにより位置を計算する
|
|
139
|
+
matrix = @matrix_transform
|
|
140
|
+
base_position = matrix[0..2]
|
|
141
|
+
|
|
142
|
+
if matrix.length == 6
|
|
143
|
+
base_rotation_matrix = get_rotation_matrix(matrix[3], matrix[4], matrix[5])
|
|
144
|
+
else
|
|
145
|
+
base_rotation_matrix = [matrix[3..5], matrix[6..8], matrix[9..11]]
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Compute the new position after transform
|
|
149
|
+
add_x, add_y, add_z = transform_point_by_rotation_matrix([x, y, z], transpose_3x3(base_rotation_matrix))
|
|
150
|
+
x, y, z = add_vectors(base_position, [add_x, add_y, add_z])
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
x, y, z = round_numbers([x, y, z])
|
|
154
|
+
r, g, b, alpha = round_two_decimals([r, g, b, alpha])
|
|
155
|
+
|
|
156
|
+
# 重ねておくことを防止
|
|
157
|
+
remove_box(x, y, z)
|
|
158
|
+
if !@@texture_names.include?(texture)
|
|
159
|
+
texture_id = -1
|
|
160
|
+
else
|
|
161
|
+
texture_id = @@texture_names.index(texture)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
if @is_framing
|
|
165
|
+
@frames.append([x, y, z, r, g, b, alpha, texture_id, @frame_id])
|
|
166
|
+
else
|
|
167
|
+
@boxes.append([x, y, z, r, g, b, alpha, texture_id])
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def remove_box(x, y, z)
|
|
172
|
+
x, y, z = round_numbers([x, y, z])
|
|
173
|
+
|
|
174
|
+
if @is_framing
|
|
175
|
+
@frames.reject! { |frame| frame[0] == x && frame[1] == y && frame[2] == z && frame[8] == @frame_id }
|
|
176
|
+
else
|
|
177
|
+
@boxes.reject! { |box| box[0] == x && box[1] == y && box[2] == z }
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def animate_global(x, y, z, pitch: 0, yaw: 0, roll: 0, scale: 1, interval: 10)
|
|
182
|
+
x, y, z = round_numbers([x, y, z])
|
|
183
|
+
@global_animation = [x, y, z, pitch, yaw, roll, scale, interval]
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
def animate(x, y, z, pitch: 0, yaw: 0, roll: 0, scale: 1, interval: 10)
|
|
187
|
+
x, y, z = round_numbers([x, y, z])
|
|
188
|
+
@animation = [x, y, z, pitch, yaw, roll, scale, interval]
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def set_box_size(box_size)
|
|
192
|
+
@size = box_size
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def set_build_interval(interval)
|
|
196
|
+
@build_interval = interval
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def write_sentence(sentence, x, y, z, r: 1, g: 1, b: 1, alpha: 1)
|
|
200
|
+
x, y, z = round_numbers([x, y, z]).map(&:to_s)
|
|
201
|
+
r, g, b, alpha = round_two_decimals([r, g, b, alpha])
|
|
202
|
+
r, g, b, alpha = [r, g, b, alpha].map(&:floor).map(&:to_s)
|
|
203
|
+
@sentence = [sentence, x, y, z, r, g, b, alpha]
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def set_light(x, y, z, r: 1, g: 1, b: 1, alpha: 1, intensity: 1000, interval: 1, light_type: 'point')
|
|
207
|
+
x, y, z = round_numbers([x, y, z])
|
|
208
|
+
r, g, b, alpha = round_two_decimals([r, g, b, alpha])
|
|
209
|
+
|
|
210
|
+
if light_type == 'point'
|
|
211
|
+
light_type = 1
|
|
212
|
+
elsif light_type == 'spot'
|
|
213
|
+
light_type = 2
|
|
214
|
+
elsif light_type == 'directional'
|
|
215
|
+
light_type = 3
|
|
216
|
+
else
|
|
217
|
+
light_type = 1
|
|
218
|
+
end
|
|
219
|
+
@lights << [x, y, z, r, g, b, alpha, intensity, interval, light_type]
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def set_command(command)
|
|
223
|
+
@commands << command
|
|
224
|
+
|
|
225
|
+
if command == 'float'
|
|
226
|
+
@is_allowed_float = 1
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
def draw_line(x1, y1, z1, x2, y2, z2, r: 1, g: 1, b: 1, alpha: 1)
|
|
231
|
+
x1, y1, z1, x2, y2, z2 = [x1, y1, z1, x2, y2, z2].map(&:floor)
|
|
232
|
+
diff_x = x2 - x1
|
|
233
|
+
diff_y = y2 - y1
|
|
234
|
+
diff_z = z2 - z1
|
|
235
|
+
max_length = [diff_x.abs, diff_y.abs, diff_z.abs].max
|
|
236
|
+
|
|
237
|
+
return false if diff_x == 0 && diff_y == 0 && diff_z == 0
|
|
238
|
+
|
|
239
|
+
if diff_x.abs == max_length
|
|
240
|
+
if x2 > x1
|
|
241
|
+
(x1..x2).each do |x|
|
|
242
|
+
y = y1 + (x - x1) * diff_y.to_f / diff_x
|
|
243
|
+
z = z1 + (x - x1) * diff_z.to_f / diff_x
|
|
244
|
+
create_box(x, y, z, r: r, g: g, b: b, alpha: alpha)
|
|
245
|
+
end
|
|
246
|
+
else
|
|
247
|
+
x1.downto(x2 + 1) do |x|
|
|
248
|
+
y = y1 + (x - x1) * diff_y.to_f / diff_x
|
|
249
|
+
z = z1 + (x - x1) * diff_z.to_f / diff_x
|
|
250
|
+
create_box(x, y, z, r: r, g: g, b: b, alpha: alpha)
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
elsif diff_y.abs == max_length
|
|
254
|
+
if y2 > y1
|
|
255
|
+
(y1..y2).each do |y|
|
|
256
|
+
x = x1 + (y - y1) * diff_x.to_f / diff_y
|
|
257
|
+
z = z1 + (y - y1) * diff_z.to_f / diff_y
|
|
258
|
+
create_box(x, y, z, r: r, g: g, b: b, alpha: alpha)
|
|
259
|
+
end
|
|
260
|
+
else
|
|
261
|
+
y1.downto(y2 + 1) do |y|
|
|
262
|
+
x = x1 + (y - y1) * diff_x.to_f / diff_y
|
|
263
|
+
z = z1 + (y - y1) * diff_z.to_f / diff_y
|
|
264
|
+
create_box(x, y, z, r: r, g: g, b: b, alpha: alpha)
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
elsif diff_z.abs == max_length
|
|
268
|
+
if z2 > z1
|
|
269
|
+
(z1..z2).each do |z|
|
|
270
|
+
x = x1 + (z - z1) * diff_x.to_f / diff_z
|
|
271
|
+
y = y1 + (z - z1) * diff_y.to_f / diff_z
|
|
272
|
+
create_box(x, y, z, r: r, g: g, b: b, alpha: alpha)
|
|
273
|
+
end
|
|
274
|
+
else
|
|
275
|
+
z1.downto(z2 + 1) do |z|
|
|
276
|
+
x = x1 + (z - z1) * diff_x.to_f / diff_z
|
|
277
|
+
y = y1 + (z - z1) * diff_y.to_f / diff_z
|
|
278
|
+
create_box(x, y, z, r: r, g: g, b: b, alpha: alpha)
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
def change_shape(shape)
|
|
285
|
+
@shape = shape
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
def change_material(is_metallic: false, roughness: 0.5)
|
|
289
|
+
@is_metallic = is_metallic ? 1 : 0
|
|
290
|
+
@roughness = roughness
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
def create_model(model_name, x: 0, y: 0, z: 0, pitch: 0, yaw: 0, roll: 0, scale: 1, entity_name: '')
|
|
294
|
+
if @@model_names.include?(model_name)
|
|
295
|
+
x, y, z, pitch, yaw, roll, scale = round_two_decimals([x, y, z, pitch, yaw, roll, scale])
|
|
296
|
+
x, y, z, pitch, yaw, roll, scale = [x, y, z, pitch, yaw, roll, scale].map(&:to_s)
|
|
297
|
+
|
|
298
|
+
@models << [model_name, x, y, z, pitch, yaw, roll, scale, entity_name]
|
|
299
|
+
else
|
|
300
|
+
puts "No model name: #{model_name}"
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
def move_model(entity_name, x: 0, y: 0, z: 0, pitch: 0, yaw: 0, roll: 0, scale: 1)
|
|
305
|
+
x, y, z, pitch, yaw, roll, scale = round_two_decimals([x, y, z, pitch, yaw, roll, scale])
|
|
306
|
+
x, y, z, pitch, yaw, roll, scale = [x, y, z, pitch, yaw, roll, scale].map(&:to_s)
|
|
307
|
+
|
|
308
|
+
@model_moves << [entity_name, x, y, z, pitch, yaw, roll, scale]
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def send_data(name: '')
|
|
313
|
+
puts 'send_data'
|
|
314
|
+
now = DateTime.now
|
|
315
|
+
data_to_send = {
|
|
316
|
+
"nodeTransform": @node_transform,
|
|
317
|
+
"frameTransforms": @frame_transforms,
|
|
318
|
+
"globalAnimation": @global_animation,
|
|
319
|
+
"animation": @animation,
|
|
320
|
+
"boxes": @boxes,
|
|
321
|
+
"frames": @frames,
|
|
322
|
+
"sentence": @sentence,
|
|
323
|
+
"lights": @lights,
|
|
324
|
+
"commands": @commands,
|
|
325
|
+
"models": @models,
|
|
326
|
+
"modelMoves": @model_moves,
|
|
327
|
+
"size": @size,
|
|
328
|
+
"shape": @shape,
|
|
329
|
+
"interval": @build_interval,
|
|
330
|
+
"isMetallic": @is_metallic,
|
|
331
|
+
"roughness": @roughness,
|
|
332
|
+
"isAllowedFloat": @is_allowed_float,
|
|
333
|
+
"name": name,
|
|
334
|
+
"date": now.to_s
|
|
335
|
+
}.to_json
|
|
336
|
+
|
|
337
|
+
EM.run do
|
|
338
|
+
ws = Faye::WebSocket::Client.new('wss://websocket.voxelamming.com')
|
|
339
|
+
|
|
340
|
+
ws.on :open do |_event|
|
|
341
|
+
p [:open]
|
|
342
|
+
puts 'WebSocket connection open'
|
|
343
|
+
ws.send(@room_name)
|
|
344
|
+
puts "Joined room: #{@room_name}"
|
|
345
|
+
ws.send(data_to_send)
|
|
346
|
+
puts data_to_send
|
|
347
|
+
puts 'Sent data to server'
|
|
348
|
+
|
|
349
|
+
EM.add_timer(1) do
|
|
350
|
+
ws.close
|
|
351
|
+
EM.stop
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
ws.on :error do |event|
|
|
356
|
+
puts "WebSocket error: #{event.message}"
|
|
357
|
+
EM.stop
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
ws.on :close do |_event|
|
|
361
|
+
puts 'WebSocket connection closed'
|
|
362
|
+
EM.stop
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
def round_numbers(num_list)
|
|
368
|
+
if @is_allowed_float == 1
|
|
369
|
+
round_two_decimals(num_list)
|
|
370
|
+
else
|
|
371
|
+
num_list.map { |val| val.round(1).floor }
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
|
|
375
|
+
def round_two_decimals(num_list)
|
|
376
|
+
num_list.map { |val| val.round(2) }
|
|
377
|
+
end
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
# Turtle graphics
|
|
381
|
+
class Turtle
|
|
382
|
+
include Math
|
|
383
|
+
|
|
384
|
+
def initialize(build_box)
|
|
385
|
+
@build_box = build_box
|
|
386
|
+
@x = 0
|
|
387
|
+
@y = 0
|
|
388
|
+
@z = 0
|
|
389
|
+
@polar_theta = 90
|
|
390
|
+
@polar_phi = 0
|
|
391
|
+
@drawable = true
|
|
392
|
+
@color = [0, 0, 0, 1]
|
|
393
|
+
@size = 1
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
def forward(length)
|
|
397
|
+
z = @z + length * sin(radians(@polar_theta)) * cos(radians(@polar_phi))
|
|
398
|
+
x = @x + length * sin(radians(@polar_theta)) * sin(radians(@polar_phi))
|
|
399
|
+
y = @y + length * cos(radians(@polar_theta))
|
|
400
|
+
x, y, z = x.round(3), y.round(3), z.round(3)
|
|
401
|
+
|
|
402
|
+
if @drawable
|
|
403
|
+
@build_box.draw_line(@x, @y, @z, x, y, z, r: @color[0], g: @color[1], b: @color[2])
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
@x = x
|
|
407
|
+
@y = y
|
|
408
|
+
@z = z
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
def backward(length)
|
|
412
|
+
forward(-length)
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
def up(degree)
|
|
416
|
+
@polar_theta -= degree
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
def down(degree)
|
|
420
|
+
@polar_theta += degree
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
def right(degree)
|
|
424
|
+
@polar_phi -= degree
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
def left(degree)
|
|
428
|
+
@polar_phi += degree
|
|
429
|
+
end
|
|
430
|
+
|
|
431
|
+
def set_color(r, g, b, alpha = 1)
|
|
432
|
+
@color = [r, g, b, alpha]
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
def pen_down
|
|
436
|
+
@drawable = true
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
def pen_up
|
|
440
|
+
@drawable = false
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
def set_pos(x, y, z)
|
|
444
|
+
@x = x
|
|
445
|
+
@y = y
|
|
446
|
+
@z = z
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
def reset
|
|
450
|
+
@x = 0
|
|
451
|
+
@y = 0
|
|
452
|
+
@z = 0
|
|
453
|
+
@polar_theta = 90
|
|
454
|
+
@polar_phi = 0
|
|
455
|
+
@drawable = true
|
|
456
|
+
@color = [0, 0, 0, 1]
|
|
457
|
+
@size = 1
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
private
|
|
461
|
+
|
|
462
|
+
def radians(degrees)
|
|
463
|
+
degrees * Math::PI / 180
|
|
464
|
+
end
|
|
465
|
+
end
|
|
466
|
+
|
|
467
|
+
# Make model
|
|
468
|
+
def self.get_boxes_from_ply(ply_file)
|
|
469
|
+
box_positions = Set.new
|
|
470
|
+
File.open(ply_file, 'r') do |f|
|
|
471
|
+
lines = f.read
|
|
472
|
+
lines = lines.gsub("\r\n", "\n")
|
|
473
|
+
lines = lines.strip
|
|
474
|
+
positions = lines.split("\n").select { |ln| self.is_included_six_numbers(ln) }.map { |ln| ln.split.map(&:to_f) }
|
|
475
|
+
|
|
476
|
+
number_of_faces = positions.length / 4
|
|
477
|
+
(0...number_of_faces).each do |i|
|
|
478
|
+
vertex1 = positions[i * 4]
|
|
479
|
+
vertex2 = positions[i * 4 + 1]
|
|
480
|
+
vertex3 = positions[i * 4 + 2]
|
|
481
|
+
vertex4 = positions[i * 4 + 3] # no need
|
|
482
|
+
x = [vertex1[0], vertex2[0], vertex3[0]].min
|
|
483
|
+
y = [vertex1[1], vertex2[1], vertex3[1]].min
|
|
484
|
+
z = [vertex1[2], vertex2[2], vertex3[2]].min
|
|
485
|
+
r = vertex1[3] / 255.0
|
|
486
|
+
g = vertex1[4] / 255.0
|
|
487
|
+
b = vertex1[5] / 255.0
|
|
488
|
+
alpha = 1
|
|
489
|
+
|
|
490
|
+
# ボックスを置く方向を解析
|
|
491
|
+
if vertex1[0] == vertex2[0] && vertex2[0] == vertex3[0] # y-z plane
|
|
492
|
+
step = [vertex1[1], vertex2[1], vertex3[1]].max - y
|
|
493
|
+
x -= step if vertex1[1] != vertex2[1]
|
|
494
|
+
elsif vertex1[1] == vertex2[1] && vertex2[1] == vertex3[1] # z-x plane
|
|
495
|
+
step = [vertex1[2], vertex2[2], vertex3[2]].max - z
|
|
496
|
+
y -= step if vertex1[2] != vertex2[2]
|
|
497
|
+
else # x-y plane
|
|
498
|
+
step = [vertex1[0], vertex2[0], vertex3[0]].max - x
|
|
499
|
+
z -= step if vertex1[0] != vertex2[0]
|
|
500
|
+
end
|
|
501
|
+
|
|
502
|
+
# minimum unit: 0.1
|
|
503
|
+
position_x = (x * 10.0 / step).round / 10.0
|
|
504
|
+
position_y = (y * 10.0 / step).round / 10.0
|
|
505
|
+
position_z = (z * 10.0 / step).round / 10.0
|
|
506
|
+
box_positions.add([position_x, position_z, -position_y, r, g, b, alpha])
|
|
507
|
+
end
|
|
508
|
+
end
|
|
509
|
+
|
|
510
|
+
box_positions
|
|
511
|
+
end
|
|
512
|
+
|
|
513
|
+
def self.is_included_six_numbers(line)
|
|
514
|
+
line_list = line.split
|
|
515
|
+
return false if line_list.length != 6
|
|
516
|
+
|
|
517
|
+
line_list.all? { |num| Float(num) rescue false }
|
|
518
|
+
end
|
|
519
|
+
|
|
520
|
+
# Map
|
|
521
|
+
def self.get_map_data_from_csv(csv_file, height_scale, column_num = 257, row_num = 257)
|
|
522
|
+
# csvファイルから地図データを読み込み
|
|
523
|
+
heights = []
|
|
524
|
+
|
|
525
|
+
CSV.foreach(csv_file) do |row|
|
|
526
|
+
for h in row
|
|
527
|
+
h = h.to_f
|
|
528
|
+
h = h != 0 ? (h * height_scale).floor : -1
|
|
529
|
+
heights << h
|
|
530
|
+
end
|
|
531
|
+
end
|
|
532
|
+
# puts "heights: #{heights}"
|
|
533
|
+
|
|
534
|
+
max_height = heights.max.floor
|
|
535
|
+
box_positions = (0...row_num).map { |i| heights[i * column_num, column_num] }
|
|
536
|
+
puts "max_height: #{max_height}"
|
|
537
|
+
# puts "box_positions: #{box_positions}"
|
|
538
|
+
{ 'boxes' => box_positions, 'max_height' => max_height }
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
def self.get_box_color(height, max_height, high_color, low_color)
|
|
542
|
+
# 高さによって色を変える
|
|
543
|
+
r = (high_color[0] - low_color[0]) * height * 1.0 / max_height + low_color[0]
|
|
544
|
+
g = (high_color[1] - low_color[1]) * height * 1.0 / max_height + low_color[1]
|
|
545
|
+
b = (high_color[2] - low_color[2]) * height * 1.0 / max_height + low_color[2]
|
|
546
|
+
|
|
547
|
+
[r, g, b]
|
|
548
|
+
end
|
|
549
|
+
end
|
data/sig/voxelamming.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: voxelamming
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- creativival
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-08-10 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: faye-websocket
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.11.3
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.11.3
|
|
27
|
+
description: Voxelamming is an AR programming learning app. Even programming beginners
|
|
28
|
+
can learn programming visually and enjoyably. Voxelamming supports iPhones and iPads
|
|
29
|
+
with iOS 16 or later, and Apple Vision Pro.
|
|
30
|
+
email:
|
|
31
|
+
- creativival@gmail.com
|
|
32
|
+
executables: []
|
|
33
|
+
extensions: []
|
|
34
|
+
extra_rdoc_files: []
|
|
35
|
+
files:
|
|
36
|
+
- CODE_OF_CONDUCT.md
|
|
37
|
+
- LICENSE.txt
|
|
38
|
+
- README.md
|
|
39
|
+
- Rakefile
|
|
40
|
+
- index.html
|
|
41
|
+
- lib/matrix_util.rb
|
|
42
|
+
- lib/voxelamming.rb
|
|
43
|
+
- lib/voxelamming/version.rb
|
|
44
|
+
- sig/voxelamming.rbs
|
|
45
|
+
homepage: https://creativival.github.io/voxelamming
|
|
46
|
+
licenses:
|
|
47
|
+
- MIT
|
|
48
|
+
metadata:
|
|
49
|
+
allowed_push_host: https://rubygems.org
|
|
50
|
+
homepage_uri: https://creativival.github.io/voxelamming
|
|
51
|
+
source_code_uri: https://github.com/creativival/voxelamming_gem
|
|
52
|
+
changelog_uri: https://creativival.github.io/voxelamming_gem/CHANGELOG.md
|
|
53
|
+
post_install_message:
|
|
54
|
+
rdoc_options: []
|
|
55
|
+
require_paths:
|
|
56
|
+
- lib
|
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: 3.0.0
|
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '0'
|
|
67
|
+
requirements: []
|
|
68
|
+
rubygems_version: 3.5.16
|
|
69
|
+
signing_key:
|
|
70
|
+
specification_version: 4
|
|
71
|
+
summary: This Ruby package converts Ruby code into JSON format and sends it to the
|
|
72
|
+
Voxelamming app using WebSockets, allowing users to create 3D voxel models by writing
|
|
73
|
+
Ruby scripts..
|
|
74
|
+
test_files: []
|