Skip to content

Commit d09504d

Browse files
committed
Update 4.7.6
1 parent 7111c70 commit d09504d

File tree

16 files changed

+532
-227
lines changed

16 files changed

+532
-227
lines changed

README.md

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,34 +121,77 @@ Also, the FPS depends on many factors, such as the material (CEL is faster) and
121121
> Warning: BJS - Max number of touches exceeded. Ignoring touches in excess of 2.<br>This problem is related to Babylon.js and nothing can be done.
122122
123123
## FAQ
124-
Why can't I freely transform 3D objects like in other 3D software?
124+
125+
#### Why isn't there a layering feature and a layer list?
126+
> There is, you can have 16,777,216 layers (groups or color groups), because the layering system in this app is determined by colors, even a change in the brightness of a color creates a new group that can contain hundreds of voxels.<br>
127+
> So groups are automatically created, merged, or deleted based on color. You can even hide, delete, select, paint, transform, or duplicate color groups.
128+
129+
> *Note, however, that you can only have 255 colors to send and receive from MagicaVoxel.*
130+
131+
#### Why can't I freely transform 3D objects like in other 3D software?
132+
> There are no objects, you work with a grid of voxels, the XFORM feature only mimics the transformation of 3D objects, you just grab a piece of connected voxels and move them.
133+
134+
#### Can two voxels be in the same position?
135+
> Never, even if they have different colors, the system will automatically delete one.
136+
137+
#### Why isn't there an option to export raw voxels as GLB?
138+
> GLB has a special use in this application, you can save and retrieve voxel data using baked meshes, exporting raw voxels to GLB leads to interference and errors when loading it using the "Load Bakes" option.
139+
140+
#### What are the methods for saving and loading voxel data?
125141
```
126-
There are no objects, you work with a grid of voxels,
127-
the XFORM feature only mimics the transformation of 3D objects,
128-
you just grab a piece of connected voxels and move them.
142+
There are currently 4 methods to store voxel data:
143+
144+
1- Save to JSON (primary, human-readable, fastest)
145+
2- Export baked meshes to GLB (and Load Bakes, supports Blender and other 3D apps, slower)
146+
3- Save snapshots to ZIP archive (easy to share, browser storage limits, speed is variable)
147+
4- Save to VOX format (supported by many 3D apps and engines, very fast)
129148
```
130-
Why isn't there an option to export raw voxels as GLB?
149+
150+
#### How to add more post-processing shaders?
151+
> Post-process shaders are automatically recognized, so all the work is done in the "**index.html**" file, just create a script tag called "fx{**Example**}FragmentShader", and add the value "**fxExample**" to "**pref_scene_postfx**". *(the prefix "**fx**" is required)*
131152
```
132-
GLB has a special use in this application,
133-
you can save and retrieve voxel data using baked meshes,
134-
exporting raw voxels to GLB leads to interference and errors
135-
when loading it using the "Load Bakes" option.
153+
<label style="margin-right: 10px">PostFX</label> <select id="pref_scene_postfx">
154+
<option value="none">None</option>
155+
<option value="fxOutline">Outline</option>
156+
<option value="fxExample">Example</option>
157+
...
158+
</select>
159+
160+
<script type="x-shader/x-fragment" id="fxExampleFragmentShader">
161+
#ifdef GL_ES
162+
precision highp float;
163+
#endif
164+
165+
varying vec2 vUV;
166+
167+
uniform vec2 uRes;
168+
uniform float uTime;
169+
uniform int uSamples;
170+
uniform vec3 uCamPos;
171+
uniform vec3 uLightPos;
172+
uniform sampler2D textureSampler;
173+
174+
// shader content
175+
</script>
136176
```
137-
How to merge vertices after export to GLB?
177+
178+
#### How to merge vertices after export to GLB?
138179
```
139180
1- Open exported GLB file in Blender
140181
2- Go to "Modeling" tab and choose vertex selection mode
141182
3- Select all vertices (Ctrl + A)
142183
4- Mesh > Clean Up > Merge by Distance
143184
```
144-
How to run Blender importer script?
185+
186+
#### How to run Blender importer script?
145187
```
146188
1- Save project to JSON
147189
2- Open Blender and go to "Scripting" tab
148190
3- Click "Open" and select "blender-importer.py"
149191
4- Run the script and select a JSON file
150192
```
151-
How to go back to the previous version?
193+
194+
#### How to go back to the previous version?
152195
```
153196
git clone https://github.com/nimadez/voxel-builder
154197
cd voxel-builder

media/screenshot.png

7.51 KB
Loading

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "voxel-builder",
3-
"version": "4.7.5",
3+
"version": "4.7.6",
44
"description": "Voxel-based 3D modeling application",
55
"main": "electron.js",
66
"scripts": {
@@ -11,7 +11,7 @@
1111
"license": "MIT",
1212
"devDependencies": {
1313
"electron": "^38.0.0",
14-
"babylonjs": "8.49.6",
14+
"babylonjs": "8.50.0",
1515
"three": "0.182.0",
1616
"three-mesh-bvh": "0.9.7",
1717
"three-gpu-pathtracer": "0.0.23",

scripts/blender-importer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env python3
22
#
3-
# Blender 4.x.x
3+
# Blender 4.x.x / 5.x.x
44
# Run script inside Blender and select .JSON file
55

6+
67
import os
78
import json
89
import bpy

src/assets/tex_checker.svg

Lines changed: 3 additions & 3 deletions
Loading

src/index.html

Lines changed: 144 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@
313313
<li class="category">ABOUT</li>
314314
<li class="about">
315315
<div><span style="color: orange">V</span>OXEL BUILDER</div>
316-
&#8627; 4.7.5 BETA
316+
&#8627; 4.7.6 BETA
317317
<br>&#8627; <a href="https://github.com/nimadez/voxel-builder/" target="_blank">GitHub</a>
318318
<br>&#8627; <a href="https://github.com/nimadez/voxel-builder/releases" target="_blank">Changelog</a>
319319
<br>DEVELOPER
@@ -382,6 +382,13 @@
382382
<option value="2">Checker</option>
383383
</select>
384384
</li>
385+
<li class="row">
386+
<label style="margin-right: 10px">PostFX</label> <select id="pref_scene_postfx">
387+
<option value="none">None</option>
388+
<option value="fxOutline">Outline</option>
389+
</select>
390+
</li>
391+
<li class="row_input" title="PostFX Samples"><label>Samples</label> <input type="range" id="pref_scene_postfx_samples" class="ignorekeys" value="2" min="1" max="8" step="1"></li>
385392
<li class="spacer"></li>
386393
<li><input type="checkbox" id="pref_scene_pointcloud"> <label for="pref_scene_pointcloud">Point Cloud</label></li>
387394
<li class="spacer"></li>
@@ -854,5 +861,141 @@
854861
</script>
855862
<script src="main.js" type="module"></script>
856863
<script src="libs/utils/jszip.min.js"></script>
864+
<script type="x-shader/x-vertex" id="uniVertexShader">
865+
precision highp float;
866+
867+
attribute vec3 position;
868+
attribute vec3 normal;
869+
attribute vec2 uv;
870+
attribute vec4 color;
871+
872+
varying vec3 vPosition;
873+
varying vec3 vPositionW;
874+
varying vec3 vNormalW;
875+
varying vec2 vUv;
876+
varying vec4 vColor;
877+
878+
uniform mat4 viewProjection;
879+
880+
#include<instancesDeclaration>
881+
882+
void main() {
883+
#include<instancesVertex>
884+
885+
vec4 worldPos = finalWorld * vec4(position, 1.0);
886+
gl_Position = viewProjection * worldPos;
887+
888+
#include<vertexColorMixing>
889+
890+
vPosition = normalize(gl_Position.xyz);
891+
vPositionW = vec3(worldPos);
892+
vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
893+
vUv = uv;
894+
}
895+
</script>
896+
<script type="x-shader/x-fragment" id="celFragmentShader">
897+
precision highp float;
898+
899+
varying vec3 vPosition;
900+
varying vec3 vPositionW;
901+
varying vec3 vNormalW;
902+
varying vec2 vUv;
903+
varying vec4 vColor;
904+
905+
uniform vec3 uCamPos;
906+
uniform vec3 uLightPos;
907+
uniform vec3 uLightCol;
908+
uniform int uTextureId;
909+
uniform sampler2D uTexture;
910+
911+
void main() {
912+
vec3 N = normalize(vNormalW);
913+
vec3 V = normalize(uCamPos - vPositionW);
914+
vec3 L = normalize(uLightPos - vPositionW);
915+
916+
vec2 grid = abs(fract(vUv - 0.5) - 0.5) / fwidth(vUv);
917+
float line = min(grid.x, grid.y);
918+
line = 1.0 - min(line, 1.0);
919+
920+
float amb = clamp(0.9 + 0.25 * N.y, 0.0, 1.0);
921+
if (dot(N, L) < 0.0)
922+
amb *= 1.2;
923+
924+
float dif = 1.0 * max(0.5, dot(N, L));
925+
dif += 0.5 * max(0.0, dot(N, -L));
926+
927+
float ao = pow(max(0.0, dot(N, L)) + 0.05, 4.0);
928+
float curvature = abs(dot(N, vPosition));
929+
ao = mix(0.5, 1.0, ao);
930+
ao = mix(ao, 0.25, curvature * 0.5);
931+
932+
vec3 brdf = vec3(0);
933+
brdf += 1.0 * amb * ao;
934+
brdf += 1.0 * dif * uLightCol;
935+
936+
vec3 col = vColor.rgb;
937+
col *= brdf;
938+
939+
if (uTextureId == 1)
940+
col = mix(col, vec3(0), line * 0.22);
941+
942+
col = pow(col, vec3(0.4545));
943+
944+
if (uTextureId > 1)
945+
col *= texture2D(uTexture, vUv).rgb;
946+
947+
gl_FragColor = vec4(col, 1.0);
948+
}
949+
</script>
950+
<script type="x-shader/x-fragment" id="fxOutlineFragmentShader">
951+
#ifdef GL_ES
952+
precision highp float;
953+
#endif
954+
955+
varying vec2 vUV;
956+
957+
uniform vec2 uRes;
958+
uniform sampler2D textureSampler;
959+
960+
// image based edge detection
961+
vec3 sobel(sampler2D tex, vec2 uv) {
962+
vec3 Gx = vec3(0);
963+
vec3 Gy = vec3(0);
964+
vec3 e = vec3(0.0, 1.0, -1.0);
965+
vec2 tx = 1.0 / uRes.xy;
966+
967+
Gx += texture(tex, uv + tx * e.zz).rgb * 1.0;
968+
Gx += texture(tex, uv + tx * e.zx).rgb * 2.0;
969+
Gx += texture(tex, uv + tx * e.zy).rgb * 1.0;
970+
971+
Gx += texture(tex, uv + tx * e.yy).rgb * -1.0;
972+
Gx += texture(tex, uv + tx * e.yx).rgb * -2.0;
973+
Gx += texture(tex, uv + tx * e.yz).rgb * -1.0;
974+
975+
Gy += texture(tex, uv + tx * e.zy).rgb * 1.0;
976+
Gy += texture(tex, uv + tx * e.xy).rgb * 2.0;
977+
Gy += texture(tex, uv + tx * e.yy).rgb * 1.0;
978+
979+
Gy += texture(tex, uv + tx * e.zz).rgb * -1.0;
980+
Gy += texture(tex, uv + tx * e.xz).rgb * -2.0;
981+
Gy += texture(tex, uv + tx * e.yz).rgb * -1.0;
982+
983+
return sqrt(Gx*Gx + Gy*Gy);
984+
}
985+
986+
void main(void) {
987+
vec2 uv = gl_FragCoord.xy / uRes.xy;
988+
989+
vec3 sb = sobel(textureSampler, uv);
990+
float mx = max(max(sb.r, sb.g), sb.b);
991+
float aa = smoothstep(1.0, 0.0, mx);
992+
float edge = step(mx, 0.5);
993+
994+
vec3 col = texture2D(textureSampler, vUV).rgb;
995+
col = mix(col, col * edge * aa, 1.0);
996+
997+
gl_FragColor = vec4(col, 1.0);
998+
}
999+
</script>
8571000
</body>
8581001
</html>

src/libs/babylon.inspector.bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/libs/babylon.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/modules/babylon.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ export const EffectShadersStore = BABYLON.Effect.ShadersStore;
6666
export const CounterClockWiseSideOrientation = BABYLON.Material.CounterClockWiseSideOrientation;
6767

6868

69+
// Vector2
70+
71+
72+
export function Vector2(x = 0, y = 0) {
73+
return new BABYLON.Vector2(x, y);
74+
}
75+
76+
6977
// Vector3
7078

7179

@@ -230,6 +238,10 @@ export function RenderTargetTexture(name, width, height, scene) {
230238
}, scene);
231239
}
232240

241+
export function PostProcess(name, camera, parameters) {
242+
return new BABYLON.PostProcess(name, name, parameters, null, 1, camera);
243+
}
244+
233245

234246
// Nodes and Gizmos
235247

0 commit comments

Comments
 (0)