@jscad/regl-renderer 2.5.8 → 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,22 @@
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
+
6
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)
7
23
 
8
24
  **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],t=[e[0],e[1],e[2]];n.push(t),i.push(s),p.push(c);const r=n.length-1;m.push(r)}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],l=[t[0],t[1],t[2]];{const o={normal:h,position:l},t=fuzyNormalAndPositionLookup(c,o,.5);if(t)e=t.index;else{const t=c[o.position],a=[{normal:o.normal,index:i}];c[o.position]=t?c[o.position].concat(a):a,e=i,u&&s.push(u),r.push(h),n.push(l),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;
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;
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@jscad/regl-renderer",
3
- "version": "2.5.8",
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.3",
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.4",
38
- "@jscad/modeling": "2.9.2",
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": "0cebde0166c104e3c08cc05d2c03d9defc7eca26"
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 vertex = vertices[j]
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 , that gives us a specific index (indices)
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 vertex = vertices[j]
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)