@jscad/regl-renderer 2.6.4 → 2.6.6
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.
- package/CHANGELOG.md +19 -0
- package/dist/jscad-regl-renderer.min.js +3 -3
- package/package.json +3 -3
- package/src/geometry-utils-V2/entitiesFromSolids.test.js +1 -1
- package/src/geometry-utils-V2/geom3ToGeometries.js +1 -1
- package/src/geometry-utils-V2/geom3ToGeometries.test.js +2 -2
- package/src/rendering/commands/drawLines/index.js +1 -2
- package/src/rendering/commands/drawMesh/index.js +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.6.6](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/regl-renderer@2.6.5...@jscad/regl-renderer@2.6.6) (2023-04-30)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @jscad/regl-renderer
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.6.5](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/regl-renderer@2.6.4...@jscad/regl-renderer@2.6.5) (2023-01-09)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **regl-renderer:** corrected rendering of overlapping transparent solid objects ([9a66b2a](https://github.com/jscad/OpenJSCAD.org/commit/9a66b2abaccb6f047c5e4c4505218e7bbac69018))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [2.6.4](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/regl-renderer@2.6.3...@jscad/regl-renderer@2.6.4) (2022-11-26)
|
|
7
26
|
|
|
8
27
|
**Note:** Version bump only for package @jscad/regl-renderer
|
|
@@ -284,7 +284,7 @@ const{flatten:flatten,toArray:toArray}=require("@jscad/array-utils"),{meshColor:
|
|
|
284
284
|
const mat4=require("gl-mat4"),maxIndex=Math.floor(32767.5),geom2ToGeometries=(o,e)=>{let{color:t}=o;const n=e.sides;if(0===n.length)return[];"color"in e&&(t=e.color);const r=t[3]<1,s=[],l=Math.floor(n.length/maxIndex)+1,a=(o,e)=>{s.push(o,e||o)},m=[];for(let o=0;o<l;o++){const l=o*maxIndex,c=Math.min(l+maxIndex,n.length),h=[];for(let o=l;o<c;o++){const e=n[o];if(e.color){if(0===s.length&&h.length>0){const o=h.length;for(let e=0;e<o;e++)s.push(t)}a(e.color,e.endColor)}else s.length&&a(t);h.push([e[0][0],e[0][1],0]),h.push([e[1][0],e[1][1],0])}const i=h.map(o=>[0,0,-1]),f=h.map((o,e)=>e),p=e.transforms?mat4.clone(e.transforms):mat4.create();m.push({type:"2d",positions:h,normals:i,indices:f,transforms:p,color:t,colors:s,isTransparent:r})}return m};module.exports=geom2ToGeometries;
|
|
285
285
|
|
|
286
286
|
},{"gl-mat4":26}],96:[function(require,module,exports){
|
|
287
|
-
const vec3=require("gl-vec3"),mat4=require("gl-mat4"),maxIndex=65535,geom3ToGeometries=(o,e)=>{let{color:t,smoothLighting:n}=o;"color"in e&&(t=e.color);const r=e.polygons,l=e.transforms?mat4.clone(e.transforms):mat4.create(),s=[];let c=0;for(;c<r.length;){let o=0,e=c;for(let t=c;t<r.length&&!((o+=r[t].vertices.length)>65535);t++)e++;const n=[],i=[],a=[],p=[],m
|
|
287
|
+
const vec3=require("gl-vec3"),mat4=require("gl-mat4"),maxIndex=65535,geom3ToGeometries=(o,e)=>{let{color:t,smoothLighting:n}=o;"color"in e&&(t=e.color);const r=e.polygons,l=e.transforms?mat4.clone(e.transforms):mat4.create(),s=[];let c=0;for(;c<r.length;){let o=0,e=c;for(let t=c;t<r.length&&!((o+=r[t].vertices.length)>65535);t++)e++;const n=[],i=[],a=[],p=[],m=t[3]<1;for(let o=c;o<e;o++){const e=r[o],l=e.vertices,s=calculateNormal(e),c=polygonColor(e,t),m=[];for(let o=0;o<l.length;o++){const e=l[o];n.push(e),i.push(s),p.push(c);const t=n.length-1;m.push(t)}for(let o=2;o<m.length;o++)a.push([m[0],m[o-1],m[o]])}const u={type:"3d",positions:n,normals:i,indices:a,colors:p,transforms:l,isTransparent:m};s.push(u),c=e}return s},smoothing=()=>{const o=[],e=[];let t=!0;const n=[],r=[],l=[],s=[],c=[];let i=0;for(let a=0;a<o.length;a++){const p=o[a],m=p.vertices,u=polygonColor(p,e),h=calculateNormal(p);u&&1!==u[3]&&(t=!0);const g=[];for(let o=0;o<m.length;o++){let e;const t=m[o];{const o={normal:h,position:t},l=fuzyNormalAndPositionLookup(c,o,.5);if(l)e=l.index;else{const l=c[o.position],a=[{normal:o.normal,index:i}];c[o.position]=l?c[o.position].concat(a):a,e=i,u&&s.push(u),r.push(h),n.push(t),i+=1}}g.push(e)}for(let o=2;o<g.length;o++)l.push([g[0],g[o-1],g[o]])}},polygonColor=(o,e)=>{let t=e;return o.color&&(t=o.color),t&&t.length<4&&t.push(1),t},calculateNormal=o=>{if(o.plane)return vec3.clone(o.plane);const e=o.vertices,t=vec3.create();vec3.subtract(t,e[1],e[0]);const n=vec3.create();vec3.subtract(n,e[2],e[0]);const r=vec3.create();return vec3.cross(r,t,n),vec3.normalize(r,r),r},areNormalsSimilar=(o,e,t)=>vec3.distance(o,e)<=t,fuzyNormalAndPositionLookup=(o,e,t)=>{const n=o[e.position];if(n)for(let o=0;o<n.length;o++){const r=n[o].normal;if(areNormalsSimilar(r,e.normal,t))return{tupple:{position:e.position,normal:r},index:n[o].index}}};module.exports=geom3ToGeometries;
|
|
288
288
|
|
|
289
289
|
},{"gl-mat4":26,"gl-vec3":59}],97:[function(require,module,exports){
|
|
290
290
|
const mat4=require("gl-mat4"),maxIndex=Math.floor(32767.5)-2,path2ToGeometries=(o,t)=>{let{color:e}=o;const s=t.points;if(0===s.length)return[];"color"in t&&(e=t.color);const n=e[3]<1,r=Math.floor(s.length/maxIndex)+1,a=[];for(let o=0;o<r;o++){const l=o*maxIndex,m=Math.min(l+maxIndex,s.length),c=[];let i;for(let o=l;o<m;o++){const t=s[o];i&&(c.push([i[0],i[1],0]),c.push([t[0],t[1],0])),i=t}if(o+1===r&&t.isClosed&&i){const o=s[0];c.push([i[0],i[1],0]),c.push([o[0],o[1],0])}const p=c.map(o=>[0,0,-1]),h=c.map((o,t)=>t),f=t.transforms?mat4.clone(t.transforms):mat4.create();a.push({type:"2d",positions:c,normals:p,indices:h,transforms:f,color:e,isTransparent:n})}return a};module.exports=path2ToGeometries;
|
|
@@ -305,7 +305,7 @@ const makeDrawMultiGrid=(e,i)=>{const{size:s,ticks:r}=Object.assign({},{size:[50
|
|
|
305
305
|
const vColorFrag="\nprecision mediump float;\nuniform vec4 ucolor;\n\nvoid main () {\n gl_FragColor = ucolor;\n}\n";module.exports={frag:vColorFrag};
|
|
306
306
|
|
|
307
307
|
},{}],103:[function(require,module,exports){
|
|
308
|
-
const mat4=require("gl-mat4"),{meshColor:meshColor}=require("../../renderDefaults"),drawLines=(e,r={})=>{const
|
|
308
|
+
const mat4=require("gl-mat4"),{meshColor:meshColor}=require("../../renderDefaults"),drawLines=(e,r={})=>{const o={color:meshColor,geometry:void 0};let{geometry:t,color:s,transparent:a}=Object.assign({},o,r);"color"in t&&(s=t.color);const l=!!(t.indices&&t.indices.length>0),i=!!(t.normals&&t.normals.length>0),n=!!(t.colors&&t.colors.length>0),c={primitive:"lines",vert:n?require("./vColorShaders").vert:require("./meshShaders").vert,frag:n?require("./vColorShaders").frag:require("./colorOnlyShaders").frag,uniforms:{model:(e,r)=>r.model||t.transforms||mat4.create(),ucolor:(e,r)=>r&&r.color?r.color:s},attributes:{position:e.buffer({usage:"static",type:"float",data:t.positions})}};return a&&(c.blend={enable:!0,func:{src:"src alpha",dst:"one minus src alpha"}}),n&&(c.attributes.color=e.buffer({usage:"static",type:"float",data:t.colors})),l&&(c.elements=e.elements({usage:"static",type:"uint16",data:t.indices})),i&&(c.attributes.normal=e.buffer({usage:"static",type:"float",data:t.normals})),e(c)};module.exports=drawLines;
|
|
309
309
|
|
|
310
310
|
},{"../../renderDefaults":111,"./colorOnlyShaders":102,"./meshShaders":104,"./vColorShaders":105,"gl-mat4":26}],104:[function(require,module,exports){
|
|
311
311
|
const meshVert="\nprecision mediump float;\n\nuniform float camNear, camFar;\nuniform mat4 model, view, projection;\n\nattribute vec3 position, normal;\n\n\nvarying vec3 surfaceNormal, surfacePosition;\nvarying vec4 _worldSpacePosition;\n\n\nvoid main() {\n\n\n surfacePosition = position;\n surfaceNormal = normal;\n vec4 worldSpacePosition = model * vec4(position, 1);\n _worldSpacePosition = worldSpacePosition;\n\n vec4 glPosition = projection * view * model * vec4(position, 1);\n gl_Position = glPosition;\n}\n",meshFrag="\nprecision mediump float;\nvarying vec3 surfaceNormal;\nuniform float ambientLightAmount;\nuniform float diffuseLightAmount;\nuniform vec4 ucolor;\nuniform vec3 lightDirection;\nuniform vec3 opacity;\n\nvarying vec4 _worldSpacePosition;\n\nuniform vec2 printableArea;\n\nvec4 errorColor = vec4(0.15, 0.15, 0.15, 0.3);\n\nvoid main () {\n vec4 depth = gl_FragCoord;\n\n float v = 0.8; // shadow value\n vec4 endColor = ucolor;\n\n vec3 ambient = ambientLightAmount * endColor.rgb;\n float cosTheta = dot(surfaceNormal, lightDirection);\n vec3 diffuse = diffuseLightAmount * endColor.rgb * clamp(cosTheta , 0.0, 1.0 );\n\n float cosTheta2 = dot(surfaceNormal, vec3(-lightDirection.x, -lightDirection.y, lightDirection.z));\n vec3 diffuse2 = diffuseLightAmount * endColor.rgb * clamp(cosTheta2 , 0.0, 1.0 );\n\n gl_FragColor = vec4((ambient + diffuse + diffuse2 * v), endColor.a);\n}";module.exports={vert:meshVert,frag:meshFrag};
|
|
@@ -314,7 +314,7 @@ const meshVert="\nprecision mediump float;\n\nuniform float camNear, camFar;\nun
|
|
|
314
314
|
const vColorVert="\nprecision mediump float;\n\nuniform float camNear, camFar;\nuniform mat4 model, view, projection;\n\nattribute vec3 position, normal;\nattribute vec4 color;\n\nvarying vec3 surfaceNormal, surfacePosition;\nvarying vec4 _worldSpacePosition;\nvarying vec4 vColor;\n\nvoid main() {\n vColor = color;\n\n surfacePosition = position;\n surfaceNormal = normal;\n vec4 worldSpacePosition = model * vec4(position, 1);\n _worldSpacePosition = worldSpacePosition;\n\n vec4 glPosition = projection * view * model * vec4(position, 1);\n gl_Position = glPosition;\n}\n",vColorFrag="\nprecision mediump float;\nvarying vec4 vColor;\n\nvoid main () {\n gl_FragColor = vColor;\n}\n";module.exports={frag:vColorFrag,vert:vColorVert};
|
|
315
315
|
|
|
316
316
|
},{}],106:[function(require,module,exports){
|
|
317
|
-
const mat4=require("gl-mat4"),{meshColor:meshColor}=require("../../renderDefaults"),drawMesh=(e,r={extras:{}})=>{const t={useVertexColors:!0,dynamicCulling:!0,geometry:void 0,color:meshColor},{geometry:
|
|
317
|
+
const mat4=require("gl-mat4"),{meshColor:meshColor}=require("../../renderDefaults"),drawMesh=(e,r={extras:{}})=>{const t={useVertexColors:!0,dynamicCulling:!0,geometry:void 0,color:meshColor,visuals:{}},{geometry:s,dynamicCulling:a,useVertexColors:o,color:l,visuals:n}=Object.assign({},t,r),i=e.buffer([]),u=!!(s.indices&&s.indices.length>0),c=!!(s.normals&&s.normals.length>0),m="transparent"in n&&n.transparent,g=!!(o&&s.colors&&s.colors.length>0),d=s.transforms||mat4.create(),f=mat4.determinant(d)<0,h=a&&f?"front":"back",p=g?require("./vColorShaders").vert:require("./meshShaders").vert,b=g?require("./vColorShaders").frag:require("./meshShaders").frag,v=mat4.invert(mat4.create(),d);let C={primitive:"triangles",vert:p,frag:b,uniforms:{model:(e,r)=>d,ucolor:(e,r)=>r&&r.color?r.color:l,vColorToggler:(e,r)=>r&&r.useVertexColors&&!0===r.useVertexColors?1:0,unormal:(e,r)=>{const t=mat4.invert(mat4.create(),r.camera.view);return mat4.multiply(t,v,t),mat4.transpose(t,t),t}},attributes:{position:e.buffer({usage:"static",type:"float",data:s.positions}),ao:i},cull:{enable:!0,face:h}};return m&&(C.blend={enable:!0,func:{src:"src alpha",dst:"one minus src alpha"}}),s.cells?C.elements=s.cells:u?C.elements=e.elements({usage:"static",type:"uint16",data:s.indices}):s.triangles?C.elements=s.triangles:C.count=s.positions.length/3,c&&(C.attributes.normal=e.buffer({usage:"static",type:"float",data:s.normals})),g&&(C.attributes.color=e.buffer({usage:"static",type:"float",data:s.colors})),e(C=Object.assign({},C,r.extras))};module.exports=drawMesh;
|
|
318
318
|
|
|
319
319
|
},{"../../renderDefaults":111,"./meshShaders":107,"./vColorShaders":108,"gl-mat4":26}],107:[function(require,module,exports){
|
|
320
320
|
const meshFrag="\nprecision mediump float;\nvarying vec3 surfaceNormal;\nuniform float ambientLightAmount;\nuniform float diffuseLightAmount;\nuniform vec4 ucolor;\nuniform vec3 lightDirection;\nuniform vec3 opacity;\n\nvarying vec4 _worldSpacePosition;\n\nuniform vec2 printableArea;\n\nvec4 errorColor = vec4(0.15, 0.15, 0.15, 0.3);\n\nvoid main () {\n vec4 depth = gl_FragCoord;\n\n float v = 0.8; // shadow value\n vec4 endColor = ucolor;\n\n vec3 ambient = ambientLightAmount * endColor.rgb;\n float cosTheta = dot(surfaceNormal, lightDirection);\n vec3 diffuse = diffuseLightAmount * endColor.rgb * clamp(cosTheta , 0.0, 1.0 );\n\n float cosTheta2 = dot(surfaceNormal, vec3(-lightDirection.x, -lightDirection.y, lightDirection.z));\n vec3 diffuse2 = diffuseLightAmount * endColor.rgb * clamp(cosTheta2 , 0.0, 1.0 );\n\n gl_FragColor = vec4((ambient + diffuse + diffuse2 * v), endColor.a);\n}",meshVert="\nprecision mediump float;\n\nuniform float camNear, camFar;\nuniform mat4 model, view, projection;\n\nattribute vec3 position, normal;\n\nvarying vec3 surfaceNormal, surfacePosition;\nvarying vec4 _worldSpacePosition;\n\nvoid main() {\n surfacePosition = position;\n surfaceNormal = normal;\n vec4 worldSpacePosition = model * vec4(position, 1);\n _worldSpacePosition = worldSpacePosition;\n\n vec4 glPosition = projection * view * model * vec4(position, 1);\n gl_Position = glPosition;\n}\n";module.exports={vert:meshVert,frag:meshFrag};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/regl-renderer",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.6",
|
|
4
4
|
"description": "Renderer for JSCAD Geometries",
|
|
5
5
|
"homepage": "https://openjscad.xyz/",
|
|
6
6
|
"repository": "https://github.com/jscad/OpenJSCAD.org",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@jscad/img-utils": "2.0.5",
|
|
39
|
-
"@jscad/modeling": "2.11.
|
|
39
|
+
"@jscad/modeling": "2.11.1",
|
|
40
40
|
"ava": "3.15.0",
|
|
41
41
|
"browserify": "16.5.1",
|
|
42
42
|
"budo": "11.6.4",
|
|
43
43
|
"nyc": "15.1.0",
|
|
44
44
|
"uglifyify": "5.0.2"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "4313974b50957018d2edd010e3a251f59bea46a4"
|
|
47
47
|
}
|
|
@@ -38,7 +38,7 @@ const geom3ToGeometries = (options, solid) => {
|
|
|
38
38
|
const normals = []
|
|
39
39
|
const indices = []
|
|
40
40
|
const colors = []
|
|
41
|
-
const isTransparent =
|
|
41
|
+
const isTransparent = (color[3] < 1.0)
|
|
42
42
|
|
|
43
43
|
for (let i = setstart; i < setend; i++) {
|
|
44
44
|
const polygon = polygons[i]
|
|
@@ -43,7 +43,7 @@ test('geom3ToGeometries (solid with polygons)', (t) => {
|
|
|
43
43
|
[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4],
|
|
44
44
|
[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]
|
|
45
45
|
],
|
|
46
|
-
isTransparent:
|
|
46
|
+
isTransparent: false,
|
|
47
47
|
transforms: defaultTransforms,
|
|
48
48
|
indices: [
|
|
49
49
|
[0, 1, 2], [0, 2, 3],
|
|
@@ -88,7 +88,7 @@ test('geom3ToGeometries (solid with polygons)', (t) => {
|
|
|
88
88
|
|
|
89
89
|
// with color
|
|
90
90
|
solid.color = [0, 0, 1, 1]
|
|
91
|
-
expected[0].isTransparent =
|
|
91
|
+
expected[0].isTransparent = false
|
|
92
92
|
expected[0].colors = [
|
|
93
93
|
[0, 0, 1, 1], [0, 0, 1, 1], [0, 0, 1, 1], [0, 0, 1, 1],
|
|
94
94
|
[0, 0, 1, 1], [0, 0, 1, 1], [0, 0, 1, 1], [0, 0, 1, 1],
|
|
@@ -7,16 +7,17 @@ const drawMesh = (regl, params = { extras: {} }) => {
|
|
|
7
7
|
useVertexColors: true,
|
|
8
8
|
dynamicCulling: true,
|
|
9
9
|
geometry: undefined,
|
|
10
|
-
color: meshColor
|
|
10
|
+
color: meshColor,
|
|
11
|
+
visuals: {}
|
|
11
12
|
}
|
|
12
|
-
const { geometry, dynamicCulling, useVertexColors, color,
|
|
13
|
-
|
|
13
|
+
const { geometry, dynamicCulling, useVertexColors, color, visuals } = Object.assign({}, defaults, params)
|
|
14
14
|
// let ambientOcclusion = vao(geometry.indices, geometry.positions, 64, 64)
|
|
15
15
|
const ambientOcclusion = regl.buffer([])
|
|
16
16
|
|
|
17
17
|
// vertex colors or not ?
|
|
18
18
|
const hasIndices = !!(geometry.indices && geometry.indices.length > 0)
|
|
19
19
|
const hasNormals = !!(geometry.normals && geometry.normals.length > 0)
|
|
20
|
+
const transparent = 'transparent' in visuals ? visuals.transparent : false
|
|
20
21
|
const hasVertexColors = !!(useVertexColors && geometry.colors && geometry.colors.length > 0)
|
|
21
22
|
const transforms = geometry.transforms || mat4.create()
|
|
22
23
|
const flip = mat4.determinant(transforms) < 0
|
|
@@ -53,8 +54,7 @@ const drawMesh = (regl, params = { extras: {} }) => {
|
|
|
53
54
|
cull: {
|
|
54
55
|
enable: true,
|
|
55
56
|
face: cullFace
|
|
56
|
-
}
|
|
57
|
-
depth: { enable: !transparent }
|
|
57
|
+
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
// blending is a bit tricky
|