@jscad/regl-renderer 2.5.6 → 2.5.9
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
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
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.5.9](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/regl-renderer@2.5.8...@jscad/regl-renderer@2.5.9) (2022-04-24)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **regl-render:** removed unnecessary preventDefault in demo.html ([#1068](https://github.com/jscad/OpenJSCAD.org/issues/1068)) ([b2ff7c3](https://github.com/jscad/OpenJSCAD.org/commit/b2ff7c33cd3a8a0fc242b42f5e4bb2690eaef081))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Performance Improvements
|
|
15
|
+
|
|
16
|
+
* **modeling:** faster geom2.toOutlines ([#1064](https://github.com/jscad/OpenJSCAD.org/issues/1064)) ([5cb2f65](https://github.com/jscad/OpenJSCAD.org/commit/5cb2f652fa099593e6ec133fe879ecf8a09705e9))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [2.5.8](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/regl-renderer@2.5.7...@jscad/regl-renderer@2.5.8) (2022-04-03)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @jscad/regl-renderer
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [2.5.7](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/regl-renderer@2.5.6...@jscad/regl-renderer@2.5.7) (2022-04-03)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @jscad/regl-renderer
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
6
38
|
## [2.5.6](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/regl-renderer@2.5.5...@jscad/regl-renderer@2.5.6) (2022-03-13)
|
|
7
39
|
|
|
8
40
|
**Note:** Version bump only for package @jscad/regl-renderer
|
package/demo.html
CHANGED
|
@@ -201,13 +201,11 @@ const downHandler = (ev) => {
|
|
|
201
201
|
lastX = ev.pageX
|
|
202
202
|
lastY = ev.pageY
|
|
203
203
|
containerElement.setPointerCapture(ev.pointerId)
|
|
204
|
-
ev.preventDefault()
|
|
205
204
|
}
|
|
206
205
|
|
|
207
206
|
const upHandler = (ev) => {
|
|
208
207
|
pointerDown = false
|
|
209
208
|
containerElement.releasePointerCapture(ev.pointerId)
|
|
210
|
-
ev.preventDefault()
|
|
211
209
|
}
|
|
212
210
|
|
|
213
211
|
const wheelHandler = (ev) => {
|
|
@@ -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 r=e.sides;if(0===r.length)return[];"color"in e&&(t=e.color);const n=t[3]<1,s=Math.floor(r.length/maxIndex)+1,a=[];for(let o=0;o<s;o++){const s=o*maxIndex,m=Math.min(s+maxIndex,r.length),l=[];for(let o=s;o<m;o++){const e=r[o];l.push([e[0][0],e[0][1],0]),l.push([e[1][0],e[1][1],0])}const c=l.map(o=>[0,0,-1]),i=l.map((o,e)=>e),h=e.transforms?mat4.clone(e.transforms):mat4.create();a.push({type:"2d",positions:l,normals:c,indices:i,transforms:h,color:t,isTransparent:n})}return a};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=!0;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]
|
|
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=!0;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;
|
|
@@ -317,7 +317,7 @@ const mat4=require("gl-mat4"),{meshColor:meshColor}=require("../../renderDefault
|
|
|
317
317
|
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};
|
|
318
318
|
|
|
319
319
|
},{}],107:[function(require,module,exports){
|
|
320
|
-
const vColorVert="\nprecision mediump float;\n\nuniform float camNear, camFar;\nuniform mat4 model, view, projection, unormal;\n\nattribute vec3 position, normal;\nattribute vec4 color;\n\nattribute float ao;\nvarying float ambientAo;\n\nvarying vec3 surfaceNormal, surfacePosition;\nvarying vec4 _worldSpacePosition;\nvarying vec4 vColor;\n\nvoid main() {\n surfacePosition = (unormal * vec4(position, 1.0)).xyz;\n surfaceNormal = normalize((unormal * vec4(normal, 1.0)).xyz); //vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);\n vec4 worldSpacePosition = model * vec4(position, 1);\n _worldSpacePosition = worldSpacePosition;\n //gl_Position = projection * view * worldSpacePosition;\n\n vColor = color;\n\n //ambientAo = (1. - ao) * (0.5 * max(normal.x, 0.) + 0.5);\n\n vec4 glPosition = projection * view * model * vec4(position, 1);\n gl_Position = glPosition;\n //gl_Position = zBufferAdjust(glPosition, camNear, camFar);\n}\n",vColorFrag="\nprecision mediump float;\nvarying vec3 surfaceNormal, surfacePosition;\n\nuniform float ambientLightAmount;\nuniform float diffuseLightAmount;\nuniform float specularLightAmount;\n\nuniform vec3 lightDirection;\nuniform vec4 lightColor;\nuniform vec3 opacity;\nuniform float uMaterialShininess;\n\nvarying vec4 vColor;\nuniform vec4 ucolor;\nuniform float vColorToggler;\n\nuniform vec2 printableArea;\nvec4 errorColor = vec4(0.15, 0.15, 0.15, 0.3);//vec4(0.15, 0.15, 0.15, 0.3);\nvarying vec4 _worldSpacePosition;\nvarying float ambientAo;\n\nvoid main () {\n vec4 depth = gl_FragCoord;\n vec4 endColor = vColor * vColorToggler + ucolor * (1.0 - vColorToggler);\n\n vec3 ambient = ambientLightAmount * endColor.rgb ; //ambientAo * \n\n float diffuseWeight = dot(surfaceNormal, lightDirection);\n vec3 diffuse = diffuseLightAmount * endColor.rgb * clamp(diffuseWeight , 0.0, 1.0 );\n\n //specular\n \n vec4 specularColor = vec4(lightColor);\n vec3 eyeDirection = normalize(surfacePosition.xyz);\n vec3 reflectionDirection = reflect(-lightDirection, -surfaceNormal);\n float specularLightWeight = pow(max(dot(reflectionDirection, eyeDirection), 0.0), uMaterialShininess);\n vec3 specular = specularColor.rgb * specularLightWeight * specularLightAmount;\n\n
|
|
320
|
+
const vColorVert="\nprecision mediump float;\n\nuniform float camNear, camFar;\nuniform mat4 model, view, projection, unormal;\n\nattribute vec3 position, normal;\nattribute vec4 color;\n\nattribute float ao;\nvarying float ambientAo;\n\nvarying vec3 surfaceNormal, surfacePosition;\nvarying vec4 _worldSpacePosition;\nvarying vec4 vColor;\n\nvoid main() {\n surfacePosition = (unormal * vec4(position, 1.0)).xyz;\n surfaceNormal = normalize((unormal * vec4(normal, 1.0)).xyz); //vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);\n vec4 worldSpacePosition = model * vec4(position, 1);\n _worldSpacePosition = worldSpacePosition;\n //gl_Position = projection * view * worldSpacePosition;\n\n vColor = color;\n\n //ambientAo = (1. - ao) * (0.5 * max(normal.x, 0.) + 0.5);\n\n vec4 glPosition = projection * view * model * vec4(position, 1);\n gl_Position = glPosition;\n //gl_Position = zBufferAdjust(glPosition, camNear, camFar);\n}\n",vColorFrag="\nprecision mediump float;\nvarying vec3 surfaceNormal, surfacePosition;\n\nuniform float ambientLightAmount;\nuniform float diffuseLightAmount;\nuniform float specularLightAmount;\n\nuniform vec3 lightDirection;\nuniform vec4 lightColor;\nuniform vec3 opacity;\nuniform float uMaterialShininess;\n\nvarying vec4 vColor;\nuniform vec4 ucolor;\nuniform float vColorToggler;\n\nuniform vec2 printableArea;\nvec4 errorColor = vec4(0.15, 0.15, 0.15, 0.3);//vec4(0.15, 0.15, 0.15, 0.3);\nvarying vec4 _worldSpacePosition;\nvarying float ambientAo;\n\nvoid main () {\n vec4 depth = gl_FragCoord;\n vec4 endColor = vColor * vColorToggler + ucolor * (1.0 - vColorToggler);\n\n vec3 ambient = ambientLightAmount * endColor.rgb ; //ambientAo * \n\n float diffuseWeight = dot(surfaceNormal, lightDirection);\n vec3 diffuse = diffuseLightAmount * endColor.rgb * clamp(diffuseWeight , 0.0, 1.0 );\n\n //specular\n \n vec4 specularColor = vec4(lightColor);\n vec3 eyeDirection = normalize(surfacePosition.xyz);\n vec3 reflectionDirection = reflect(-lightDirection, -surfaceNormal);\n float specularLightWeight = pow(max(dot(reflectionDirection, eyeDirection), 0.0), uMaterialShininess);\n vec3 specular = specularColor.rgb * specularLightWeight * specularLightAmount;\n\n gl_FragColor = vec4((ambient + diffuse + specular), endColor.a);\n}\n";module.exports={frag:vColorFrag,vert:vColorVert};
|
|
321
321
|
|
|
322
322
|
},{}],108:[function(require,module,exports){
|
|
323
323
|
const renderContext=require("./renderContext"),renderDefaults=require("./renderDefaults"),prepareRender=e=>{const r=Object.assign({},{},e.glOptions,{onDone:(e,r)=>{if(e)throw e}}),n=require("regl")(r),a=new Map;return function(e){var r;n.poll(),(r=e).rendering=Object.assign({},renderDefaults,r.rendering),renderContext(n)(r,e=>{n.clear({color:r.rendering.background,depth:1}),r.entities&&r.entities.sort((e,r)=>{const n="transparent"in e.visuals&&e.visuals.transparent;return n===("transparent"in r.visuals&&r.visuals.transparent)?0:n?1:-1}).forEach(e=>{const{visuals:t}=e;if((!("show"in t)||t.show)&&t.drawCmd&&r.drawCommands[t.drawCmd]){let s;t.cacheId?s=a.get(t.cacheId):(t.cacheId=a.size,s=r.drawCommands[t.drawCmd](n,e),a.set(t.cacheId,s)),s({...e,...t,camera:r.camera})}})})}};module.exports=prepareRender;
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/regl-renderer",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.9",
|
|
4
4
|
"description": "Renderer for JSCAD Geometries",
|
|
5
|
+
"homepage": "https://openjscad.xyz/",
|
|
5
6
|
"repository": "https://github.com/jscad/OpenJSCAD.org",
|
|
6
7
|
"main": "src/index.js",
|
|
7
8
|
"unpkg": "dist/jscad-regl-renderer.min.js",
|
|
@@ -27,15 +28,15 @@
|
|
|
27
28
|
},
|
|
28
29
|
"types": "types",
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@jscad/array-utils": "2.1.
|
|
31
|
+
"@jscad/array-utils": "2.1.4",
|
|
31
32
|
"camera-unproject": "1.0.1",
|
|
32
33
|
"gl-mat4": "1.2.0",
|
|
33
34
|
"gl-vec3": "1.1.3",
|
|
34
35
|
"regl": "2.1.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@jscad/img-utils": "2.0.
|
|
38
|
-
"@jscad/modeling": "2.9.
|
|
38
|
+
"@jscad/img-utils": "2.0.5",
|
|
39
|
+
"@jscad/modeling": "2.9.3",
|
|
39
40
|
"ava": "3.15.0",
|
|
40
41
|
"browserify": "16.5.1",
|
|
41
42
|
"budo": "11.6.4",
|
|
@@ -43,5 +44,5 @@
|
|
|
43
44
|
"typescript": "^4.0.0",
|
|
44
45
|
"uglifyify": "5.0.2"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "85fa1fcdfb2d516a201ecf31da242e64b5b3274e"
|
|
47
48
|
}
|
|
@@ -49,9 +49,8 @@ const geom3ToGeometries = (options, solid) => {
|
|
|
49
49
|
|
|
50
50
|
const polygonIndices = []
|
|
51
51
|
for (let j = 0; j < vertices.length; j++) {
|
|
52
|
-
const
|
|
52
|
+
const position = vertices[j]
|
|
53
53
|
|
|
54
|
-
const position = [vertex[0], vertex[1], vertex[2]]
|
|
55
54
|
positions.push(position)
|
|
56
55
|
normals.push(normal)
|
|
57
56
|
colors.push(faceColor)
|
|
@@ -110,12 +109,11 @@ const smoothing = () => {
|
|
|
110
109
|
const normal = calculateNormal(polygon)
|
|
111
110
|
if (faceColor && faceColor[3] !== 1) isTransparent = true
|
|
112
111
|
const polygonIndices = []
|
|
113
|
-
// we need unique tupples of normal + position
|
|
112
|
+
// we need unique tupples of normal + position, that gives us a specific index (indices)
|
|
114
113
|
// if the angle between a given normal and another normal is less than X they are considered the same
|
|
115
114
|
for (let j = 0; j < vertices.length; j++) {
|
|
116
115
|
let index
|
|
117
|
-
const
|
|
118
|
-
const position = [vertex[0], vertex[1], vertex[2]]
|
|
116
|
+
const position = vertices[j]
|
|
119
117
|
if (smoothLighting) {
|
|
120
118
|
const candidateTupple = { normal, position }
|
|
121
119
|
const existingTupple = fuzyNormalAndPositionLookup(normalPositionLookup, candidateTupple, normalThreshold)
|
|
@@ -69,20 +69,7 @@ void main () {
|
|
|
69
69
|
float specularLightWeight = pow(max(dot(reflectionDirection, eyeDirection), 0.0), uMaterialShininess);
|
|
70
70
|
vec3 specular = specularColor.rgb * specularLightWeight * specularLightAmount;
|
|
71
71
|
|
|
72
|
-
/*float light2Multiplier = 0.2;
|
|
73
|
-
float diffuseWeight2 = dot(surfaceNormal, vec3(-lightDirection.x, lightDirection.y, lightDirection.z));
|
|
74
|
-
vec3 diffuse2 = diffuseLightAmount * endColor.rgb * clamp(diffuseWeight2 , 0.0, 1.0 ) * light2Multiplier;
|
|
75
|
-
|
|
76
|
-
float light3Multiplier = 0.2;
|
|
77
|
-
float diffuseWeight3 = dot(surfaceNormal, vec3(lightDirection.x, -lightDirection.y, lightDirection.z));
|
|
78
|
-
vec3 diffuse3 = diffuseLightAmount * endColor.rgb * clamp(diffuseWeight3 , 0.0, 1.0 ) * light3Multiplier;
|
|
79
|
-
|
|
80
|
-
float light4Multiplier = 0.2;
|
|
81
|
-
float diffuseWeight4 = dot(surfaceNormal, vec3(-lightDirection.x, -lightDirection.y, lightDirection.z));
|
|
82
|
-
vec3 diffuse4 = diffuseLightAmount * endColor.rgb * clamp(diffuseWeight4 , 0.0, 1.0 ) * light4Multiplier;*/
|
|
83
|
-
|
|
84
72
|
gl_FragColor = vec4((ambient + diffuse + specular), endColor.a);
|
|
85
|
-
//gl_FragColor = vec4((ambient + diffuse + diffuse2 + diffuse3 + diffuse4), endColor.a);
|
|
86
73
|
}
|
|
87
74
|
`
|
|
88
75
|
|