@jscad/regl-renderer 2.5.2 → 2.5.5
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 +24 -0
- package/demo-cli.js +2 -2
- package/demo-web.js +2 -2
- package/dist/jscad-regl-renderer.min.js +4 -4
- package/package.json +5 -5
- package/src/cameras/camera.js +0 -14
- package/src/cameras/perspectiveCamera.js +0 -1
- package/src/controls/orbitControls.js +0 -32
- package/src/geometry-utils-V1/entitiesFromSolids.js +0 -4
- package/src/geometry-utils-V2/geom2ToGeometries.test.js +1 -1
- package/src/geometry-utils-V2/geom3ToGeometries.js +2 -3
- package/src/geometry-utils-V2/path2ToGeometries.test.js +1 -1
- package/src/rendering/commands/drawExps/drawNormals2.js +0 -2
- package/src/rendering/commands/drawLines/index.js +1 -3
- package/src/rendering/commands/drawMesh/index.js +1 -3
- package/src/rendering/render.js +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
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.5](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/regl-renderer@2.5.4...@jscad/regl-renderer@2.5.5) (2022-03-06)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @jscad/regl-renderer
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.5.4](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/regl-renderer@2.5.3...@jscad/regl-renderer@2.5.4) (2022-02-19)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @jscad/regl-renderer
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [2.5.3](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/regl-renderer@2.5.2...@jscad/regl-renderer@2.5.3) (2021-12-26)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @jscad/regl-renderer
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
6
30
|
## [2.5.2](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/regl-renderer@2.5.1...@jscad/regl-renderer@2.5.2) (2021-12-11)
|
|
7
31
|
|
|
8
32
|
**Note:** Version bump only for package @jscad/regl-renderer
|
package/demo-cli.js
CHANGED
|
@@ -79,7 +79,7 @@ const options = {
|
|
|
79
79
|
show: true
|
|
80
80
|
},
|
|
81
81
|
size: [500, 500],
|
|
82
|
-
ticks: [25, 5]
|
|
82
|
+
ticks: [25, 5]
|
|
83
83
|
// color: [0, 0, 1, 1],
|
|
84
84
|
// subColor: [0, 0, 1, 0.5]
|
|
85
85
|
},
|
|
@@ -88,7 +88,7 @@ const options = {
|
|
|
88
88
|
drawCmd: 'drawAxis',
|
|
89
89
|
show: true
|
|
90
90
|
},
|
|
91
|
-
size: 300
|
|
91
|
+
size: 300
|
|
92
92
|
// alwaysVisible: false,
|
|
93
93
|
// xColor: [0, 0, 1, 1],
|
|
94
94
|
// yColor: [1, 0, 1, 1],
|
package/demo-web.js
CHANGED
|
@@ -55,7 +55,7 @@ const options = {
|
|
|
55
55
|
show: true
|
|
56
56
|
},
|
|
57
57
|
size: [500, 500],
|
|
58
|
-
ticks: [25, 5]
|
|
58
|
+
ticks: [25, 5]
|
|
59
59
|
// color: [0, 0, 1, 1],
|
|
60
60
|
// subColor: [0, 0, 1, 0.5]
|
|
61
61
|
},
|
|
@@ -64,7 +64,7 @@ const options = {
|
|
|
64
64
|
drawCmd: 'drawAxis',
|
|
65
65
|
show: true
|
|
66
66
|
},
|
|
67
|
-
size: 300
|
|
67
|
+
size: 300
|
|
68
68
|
// alwaysVisible: false,
|
|
69
69
|
// xColor: [0, 0, 1, 1],
|
|
70
70
|
// yColor: [1, 0, 1, 1],
|
|
@@ -266,7 +266,7 @@ const boundingBox=r=>{if(0===r.length)return[[0,0,0],[0,0,0]];const e=Array.isAr
|
|
|
266
266
|
const vec3=require("gl-vec3"),{flatten:flatten}=require("@jscad/array-utils"),boundingBox=require("./boundingBox"),computeBounds=(...e)=>{let c;(e=flatten(e)).forEach(e=>{let t=boundingBox(e.positions);t=t.map(c=>vec3.transformMat4(c,c,e.transforms)),c?(vec3.min(c[0],c[0],t[0]),vec3.max(c[1],c[1],t[1])):c=t});const t=vec3.min(vec3.create(),c[1],c[0]),a=vec3.max(vec3.create(),c[1],c[0]),n=vec3.subtract(vec3.create(),a,t);let r=vec3.scale(vec3.create(),n,.5);return r=vec3.add(r,t,r),{dia:vec3.distance(r,a),center:[...r],min:[...t],max:[...a],size:[...n]}};module.exports=computeBounds;
|
|
267
267
|
|
|
268
268
|
},{"./boundingBox":88,"@jscad/array-utils":4,"gl-vec3":59}],90:[function(require,module,exports){
|
|
269
|
-
const vec3=require("gl-vec3"),mat4=require("gl-mat4"),fromOrthographicToPerspective=e=>{const{near:t,far:r,fov:o,zoom:a}=e
|
|
269
|
+
const vec3=require("gl-vec3"),mat4=require("gl-mat4"),fromOrthographicToPerspective=e=>{const{near:t,far:r,fov:o,zoom:a}=e,{viewport:i}=e,c=require("./perspectiveCamera").setProjection(e,{width:i[2],height:i[3]}),{projectionType:p}=require("./perspectiveCamera").cameraState;return Object.assign({},e,c,{projectionType:p},{near:t,far:r,fov:o})},fromPerspectiveToOrthographic=e=>{const{fov:t,aspect:r}=e,o=.3*vec3.length(vec3.subtract([],e.position,e.target)),a=Math.tan(t)*o*r,i=Math.tan(t)*o,{near:c,far:p,viewport:s}=e,n={zoom:1,near:c,far:p},v=require("./orthographicCamera").cameraState,h=require("./orthographicCamera").setProjection(n,{width:a,height:i});return Object.assign({},v,e,h,{projectionType:v.projectionType,viewport:s})},toPerspectiveView=({camera:e})=>{const t=vec3.distance(e.position,e.target),r=[t,t,t];return{view:mat4.lookAt(mat4.create(),r,e.target,e.up),position:r}},toPresetView=(e,{camera:t})=>{const r=vec3.distance(t.position,t.target),o=vec3.add(vec3.create(),{top:[0,-1e-6,1],bottom:[0,0,-1],front:[0,1,0],back:[0,-1,0],left:[-1,0,0],right:[1,0,0],undefined:[0,0,0]}[e].map(e=>e*r),t.target);return{view:mat4.lookAt(mat4.create(),o,t.target,t.up),position:o}};module.exports={toPerspectiveView:toPerspectiveView,toPresetView:toPresetView,fromOrthographicToPerspective:fromOrthographicToPerspective,fromPerspectiveToOrthographic:fromPerspectiveToOrthographic};
|
|
270
270
|
|
|
271
271
|
},{"./orthographicCamera":91,"./perspectiveCamera":92,"gl-mat4":26,"gl-vec3":59}],91:[function(require,module,exports){
|
|
272
272
|
const mat4=require("gl-mat4"),cameraState={view:mat4.identity(new Float32Array(16)),projection:mat4.identity(new Float32Array(16)),matrix:mat4.identity(new Float32Array(16)),near:1,far:1300,up:[0,0,1],eye:new Float32Array(3),position:[150,250,200],target:[0,0,0],fov:Math.PI/4,aspect:1,viewport:[0,0,0,0],zoom:1,projectionType:"orthographic"},cameraProps={},setProjection=(t,e)=>{const{width:a,height:r}=e,o=a/r,i=[0,0,a,r],n=t.zoom,c=-a*n,m=a*n,p=-r*n,s=r*n;return{projection:mat4.ortho([],c,m,p,s,t.near,t.far),aspect:o,viewport:i}};module.exports={cameraState:cameraState,cameraProps:cameraProps,setProjection:setProjection};
|
|
@@ -275,7 +275,7 @@ const mat4=require("gl-mat4"),cameraState={view:mat4.identity(new Float32Array(1
|
|
|
275
275
|
const mat4=require("gl-mat4"),vec3=require("gl-vec3"),cameraState={view:mat4.identity(new Float32Array(16)),projection:mat4.identity(new Float32Array(16)),matrix:mat4.identity(new Float32Array(16)),near:1,far:18e3,up:[0,0,1],eye:new Float32Array(3),position:[450,550,700],target:[0,0,0],fov:Math.PI/4,aspect:1,viewport:[0,0,0,0],projectionType:"perspective"},cameraProps={},defaults=Object.assign({},cameraState,cameraProps),setProjection=(e,t,a)=>{const r=a.width/a.height,o=mat4.perspective(mat4.identity([]),t.fov,r,t.near,t.far),i=[0,0,a.width,a.height],c=e||{};return c.projection=o,c.aspect=r,c.viewport=i,c},update=(e,t)=>{t||(t=e);const{position:a,target:r,up:o}=t,i=vec3.subtract([],a,r),c=vec3.add(vec3.create(),r,i),n=mat4.lookAt(mat4.create(),c,r,o),p=e||{};return p.position=c,p.view=n,p};module.exports={cameraState:cameraState,cameraProps:cameraProps,defaults:defaults,setProjection:setProjection,update:update};
|
|
276
276
|
|
|
277
277
|
},{"gl-mat4":26,"gl-vec3":59}],93:[function(require,module,exports){
|
|
278
|
-
const vec3=require("gl-vec3"),mat4=require("gl-mat4"),{max:max,min:min,sqrt:sqrt,PI:PI,sin:sin,cos:cos,atan2:atan2}=Math,computeBounds=require("../bound-utils/computeBounds"),controlsProps={limits:{minDistance:.01,maxDistance:1e4},drag:.27,EPS:1e-6,zoomToFit:{auto:!0,targets:"all",tightness:1.5},userControl:{zoom:!0,zoomSpeed:1,rotate:!0,rotateSpeed:1,pan:!0,panSpeed:1},autoRotate:{enabled:!1,speed:1},autoAdjustPlanes:!0},controlsState={thetaDelta:0,phiDelta:0,scale:1},defaults=Object.assign({},controlsState,controlsProps),update=({controls:t,camera:e},a)=>{const{EPS:o,drag:s}=t,{position:r,target:n}=e,c=t.up?t.up:e.up;let i=t.thetaDelta;const l=t.phiDelta,m=t.scale,p=vec3.subtract([],r,n);let u,d;1===c[2]?(u=atan2(p[0],p[1]),d=atan2(sqrt(p[0]*p[0]+p[1]*p[1]),p[2])):(u=atan2(p[0],p[2]),d=atan2(sqrt(p[0]*p[0]+p[2]*p[2]),p[1])),t.autoRotate.enabled&&t.userControl.rotate&&(i+=2*Math.PI/60/60*t.autoRotate.speed),u+=i,d=max(o,min(PI-o,d+=l));const h=max(t.limits.minDistance,min(t.limits.maxDistance,vec3.length(p)*m));1===c[2]?(p[0]=h*sin(d)*sin(u),p[2]=h*cos(d),p[1]=h*sin(d)*cos(u)):(p[0]=h*sin(d)*sin(u),p[1]=h*cos(d),p[2]=h*sin(d)*cos(u));const g=vec3.add(vec3.create(),n,p),v=mat4.lookAt(mat4.create(),g,n,c),D=1-max(min(s,1),.01);return{controls:{thetaDelta:i*D,phiDelta:l*D,scale:1,changed:vec3.distance(r,g)>.001},camera:{position:g,view:v}}},rotate=({controls:t,camera:e,speed:a=1},o)=>{let{thetaDelta:s,phiDelta:r}=t;return t.userControl.rotate&&(s+=o[0]*a,r+=o[1]*a),{controls:{thetaDelta:s,phiDelta:r},camera:e}},zoom=({controls:t,camera:e,speed:a=1},o=0)=>{let{scale:s}=t;if(t.userControl.zoom&&e&&void 0!==o&&0!==o&&!isNaN(o)){const r=(o=o/o*(0===Math.sign(o)?1:Math.sign(o))*a)+t.scale,n=vec3.distance(e.position,e.target)*r;if(n>t.limits.minDistance&&n<t.limits.maxDistance&&(s+=o),"orthographic"===e.projectionType){const t=.3*vec3.length(vec3.subtract([],e.position,e.target)),a=Math.tan(e.fov)*t*e.aspect,o=Math.tan(e.fov)*t;e=require("../cameras/orthographicCamera").setProjection(e,{width:a,height:o})}}return{controls:{scale:s},camera:e}},pan=({controls:t,camera:e,speed:a=1},o)=>{const s=require("camera-unproject"),{projection:r,view:n,viewport:c}=e,i=mat4.multiply([],r,n),l=mat4.invert([],i),m=[c[2],c[3],0],p=[c[2]-o[0],c[3]+o[1],0],u=s([],m,c,l),d=s([],p,c,l),h=vec3.distance(e.position,e.eye),g=vec3.subtract([],u,d).map(e=>e*a*h*t.scale);return{controls:t,camera:{position:vec3.add(vec3.create(),e.position,g),target:vec3.add(vec3.create(),e.target,g)}}},zoomToFit=({controls:t,camera:e,entities:a})=>{const{zoomToFit:o}=t;if("all"!==o.targets)return{controls:t,camera:e};if(0===a.length)return{controls:t,camera:e};const s=a.map(t=>t.geometry),r=computeBounds(s),{fov:n,target:c,position:i}=e,{tightness:l}=Object.assign({},o,controlsProps.zoomToFit),m=r.dia*l/Math.tan(n/2)/vec3.distance(c,i);return{camera:{target:r.center},controls:{scale:m}}},reset=({controls:t,camera:e},a)=>{return{camera:{position:a.camera.position,target:a.camera.target,projection:mat4.perspective([],e.fov,e.aspect,e.near,e.far),view:a.camera.view},controls:{thetaDelta:a.controls.thetaDelta,phiDelta:a.controls.phiDelta,scale:a.controls.scale}}}
|
|
278
|
+
const vec3=require("gl-vec3"),mat4=require("gl-mat4"),{max:max,min:min,sqrt:sqrt,PI:PI,sin:sin,cos:cos,atan2:atan2}=Math,computeBounds=require("../bound-utils/computeBounds"),controlsProps={limits:{minDistance:.01,maxDistance:1e4},drag:.27,EPS:1e-6,zoomToFit:{auto:!0,targets:"all",tightness:1.5},userControl:{zoom:!0,zoomSpeed:1,rotate:!0,rotateSpeed:1,pan:!0,panSpeed:1},autoRotate:{enabled:!1,speed:1},autoAdjustPlanes:!0},controlsState={thetaDelta:0,phiDelta:0,scale:1},defaults=Object.assign({},controlsState,controlsProps),update=({controls:t,camera:e},a)=>{const{EPS:o,drag:s}=t,{position:r,target:n}=e,c=t.up?t.up:e.up;let i=t.thetaDelta;const l=t.phiDelta,m=t.scale,p=vec3.subtract([],r,n);let u,d;1===c[2]?(u=atan2(p[0],p[1]),d=atan2(sqrt(p[0]*p[0]+p[1]*p[1]),p[2])):(u=atan2(p[0],p[2]),d=atan2(sqrt(p[0]*p[0]+p[2]*p[2]),p[1])),t.autoRotate.enabled&&t.userControl.rotate&&(i+=2*Math.PI/60/60*t.autoRotate.speed),u+=i,d=max(o,min(PI-o,d+=l));const h=max(t.limits.minDistance,min(t.limits.maxDistance,vec3.length(p)*m));1===c[2]?(p[0]=h*sin(d)*sin(u),p[2]=h*cos(d),p[1]=h*sin(d)*cos(u)):(p[0]=h*sin(d)*sin(u),p[1]=h*cos(d),p[2]=h*sin(d)*cos(u));const g=vec3.add(vec3.create(),n,p),v=mat4.lookAt(mat4.create(),g,n,c),D=1-max(min(s,1),.01);return{controls:{thetaDelta:i*D,phiDelta:l*D,scale:1,changed:vec3.distance(r,g)>.001},camera:{position:g,view:v}}},rotate=({controls:t,camera:e,speed:a=1},o)=>{let{thetaDelta:s,phiDelta:r}=t;return t.userControl.rotate&&(s+=o[0]*a,r+=o[1]*a),{controls:{thetaDelta:s,phiDelta:r},camera:e}},zoom=({controls:t,camera:e,speed:a=1},o=0)=>{let{scale:s}=t;if(t.userControl.zoom&&e&&void 0!==o&&0!==o&&!isNaN(o)){const r=(o=o/o*(0===Math.sign(o)?1:Math.sign(o))*a)+t.scale,n=vec3.distance(e.position,e.target)*r;if(n>t.limits.minDistance&&n<t.limits.maxDistance&&(s+=o),"orthographic"===e.projectionType){const t=.3*vec3.length(vec3.subtract([],e.position,e.target)),a=Math.tan(e.fov)*t*e.aspect,o=Math.tan(e.fov)*t;e=require("../cameras/orthographicCamera").setProjection(e,{width:a,height:o})}}return{controls:{scale:s},camera:e}},pan=({controls:t,camera:e,speed:a=1},o)=>{const s=require("camera-unproject"),{projection:r,view:n,viewport:c}=e,i=mat4.multiply([],r,n),l=mat4.invert([],i),m=[c[2],c[3],0],p=[c[2]-o[0],c[3]+o[1],0],u=s([],m,c,l),d=s([],p,c,l),h=vec3.distance(e.position,e.eye),g=vec3.subtract([],u,d).map(e=>e*a*h*t.scale);return{controls:t,camera:{position:vec3.add(vec3.create(),e.position,g),target:vec3.add(vec3.create(),e.target,g)}}},zoomToFit=({controls:t,camera:e,entities:a})=>{const{zoomToFit:o}=t;if("all"!==o.targets)return{controls:t,camera:e};if(0===a.length)return{controls:t,camera:e};const s=a.map(t=>t.geometry),r=computeBounds(s),{fov:n,target:c,position:i}=e,{tightness:l}=Object.assign({},o,controlsProps.zoomToFit),m=r.dia*l/Math.tan(n/2)/vec3.distance(c,i);return{camera:{target:r.center},controls:{scale:m}}},reset=({controls:t,camera:e},a)=>{return{camera:{position:a.camera.position,target:a.camera.target,projection:mat4.perspective([],e.fov,e.aspect,e.near,e.far),view:a.camera.view},controls:{thetaDelta:a.controls.thetaDelta,phiDelta:a.controls.phiDelta,scale:a.controls.scale}}};module.exports={controlsProps:controlsProps,controlsState:controlsState,defaults:defaults,update:update,rotate:rotate,zoom:zoom,pan:pan,zoomToFit:zoomToFit,reset:reset};
|
|
279
279
|
|
|
280
280
|
},{"../bound-utils/computeBounds":89,"../cameras/orthographicCamera":91,"camera-unproject":9,"gl-mat4":26,"gl-vec3":59}],94:[function(require,module,exports){
|
|
281
281
|
const{flatten:flatten,toArray:toArray}=require("@jscad/array-utils"),{meshColor:meshColor}=require("../rendering/renderDefaults"),geom2ToGeometries=require("./geom2ToGeometries"),geom3ToGeometries=require("./geom3ToGeometries"),path2ToGeometries=require("./path2ToGeometries"),assembleEntities=e=>{return e.map(e=>{return{geometry:e,visuals:{drawCmd:"2d"===e.type?"drawLines":"drawMesh",show:!0,transparent:e.isTransparent,useVertexColors:!0}}})},entitiesFromSolids=(e,...o)=>{const r={color:meshColor,smoothNormals:!0},{color:t,smoothNormals:s}=Object.assign({},r,e);o=(o=flatten(toArray(o))).filter(e=>e&&e instanceof Object);const i=[];return o.forEach(e=>{let o=[];"sides"in e?o=geom2ToGeometries({color:t},e):"points"in e?o=path2ToGeometries({color:t},e):"polygons"in e&&(o=geom3ToGeometries({smoothLighting:s,normalThreshold:.3,color:t},e)),i.push(...assembleEntities(o))}),i};module.exports=entitiesFromSolids;
|
|
@@ -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
|
|
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;
|
|
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 t={color:meshColor,geometry:void 0};let{geometry:o,color:s}=Object.assign({},t,r);"color"in o&&(s=o.color);const a=!!(o.indices&&o.indices.length>0),i=!!(o.normals&&o.normals.length>0)
|
|
308
|
+
const mat4=require("gl-mat4"),{meshColor:meshColor}=require("../../renderDefaults"),drawLines=(e,r={})=>{const t={color:meshColor,geometry:void 0};let{geometry:o,color:s}=Object.assign({},t,r);"color"in o&&(s=o.color);const a=!!(o.indices&&o.indices.length>0),i=!!(o.normals&&o.normals.length>0),l={primitive:"lines",vert:require("./meshShaders").vert,frag:require("./colorOnlyShaders").frag,uniforms:{model:(e,r)=>r.model||o.transforms||mat4.create(),ucolor:(e,r)=>r&&r.color?r.color:s},attributes:{position:e.buffer({usage:"static",type:"float",data:o.positions})}};return a&&(l.elements=e.elements({usage:"static",type:"uint16",data:o.indices})),i&&(l.attributes.normal=e.buffer({usage:"static",type:"float",data:o.normals})),e(l)};module.exports=drawLines;
|
|
309
309
|
|
|
310
310
|
},{"../../renderDefaults":110,"./colorOnlyShaders":102,"./meshShaders":104,"gl-mat4":26}],104:[function(require,module,exports){
|
|
311
311
|
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.5.
|
|
3
|
+
"version": "2.5.5",
|
|
4
4
|
"description": "Renderer for JSCAD Geometries",
|
|
5
5
|
"repository": "https://github.com/jscad/OpenJSCAD.org",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
},
|
|
28
28
|
"types": "types",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@jscad/array-utils": "2.1.
|
|
30
|
+
"@jscad/array-utils": "2.1.2",
|
|
31
31
|
"camera-unproject": "1.0.1",
|
|
32
32
|
"gl-mat4": "1.2.0",
|
|
33
33
|
"gl-vec3": "1.1.3",
|
|
34
34
|
"regl": "2.1.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@jscad/img-utils": "2.0.
|
|
38
|
-
"@jscad/modeling": "2.
|
|
37
|
+
"@jscad/img-utils": "2.0.2",
|
|
38
|
+
"@jscad/modeling": "2.8.0",
|
|
39
39
|
"ava": "3.15.0",
|
|
40
40
|
"browserify": "16.5.1",
|
|
41
41
|
"budo": "11.6.4",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"typescript": "^4.0.0",
|
|
44
44
|
"uglifyify": "5.0.2"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "92fb9c75eb070fca5f5ee8c2bab6614b1f54514e"
|
|
47
47
|
}
|
package/src/cameras/camera.js
CHANGED
|
@@ -3,8 +3,6 @@ const mat4 = require('gl-mat4')
|
|
|
3
3
|
|
|
4
4
|
const fromOrthographicToPerspective = (orthographicCamera) => {
|
|
5
5
|
const { near, far, fov, zoom } = orthographicCamera
|
|
6
|
-
console.log('fov', fov, 'zoom', zoom)
|
|
7
|
-
// : fov / zoom
|
|
8
6
|
// recompute projection matrix to use perspective camera projection matrix
|
|
9
7
|
const { viewport } = orthographicCamera
|
|
10
8
|
const projection = require('./perspectiveCamera').setProjection(orthographicCamera, { width: viewport[2], height: viewport[3] })
|
|
@@ -17,29 +15,17 @@ const fromPerspectiveToOrthographic = (perspectiveCamera) => {
|
|
|
17
15
|
|
|
18
16
|
// set the orthographic view rectangle to 0,0,width,height
|
|
19
17
|
// see here : http://stackoverflow.com/questions/13483775/set-zoomvalue-of-a-perspective-equal-to-perspective
|
|
20
|
-
// const target = perspectiveCamera.target === undefined ? vec3.create() : perspectiveCamera.target
|
|
21
18
|
|
|
22
19
|
const distance = vec3.length(vec3.subtract([], perspectiveCamera.position, perspectiveCamera.target)) * 0.3
|
|
23
20
|
const width = Math.tan(fov) * distance * aspect
|
|
24
21
|
const height = Math.tan(fov) * distance
|
|
25
22
|
|
|
26
|
-
// const halfWidth = width
|
|
27
|
-
// const halfHeight = height
|
|
28
|
-
|
|
29
|
-
// const left = halfWidth
|
|
30
|
-
// const right = -halfWidth
|
|
31
|
-
// const top = -halfHeight
|
|
32
|
-
// const bottom = halfHeight
|
|
33
|
-
|
|
34
|
-
// we need to compute zoom from distance ? or pass it from controls ?
|
|
35
|
-
|
|
36
23
|
// we re-use near, far, & projection matrix of orthographicCamera
|
|
37
24
|
const { near, far, viewport } = perspectiveCamera
|
|
38
25
|
const fCam = { zoom: 1, near, far }
|
|
39
26
|
const orthographicCamera = require('./orthographicCamera').cameraState
|
|
40
27
|
const projection = require('./orthographicCamera').setProjection(fCam, { width, height })
|
|
41
28
|
return Object.assign({}, orthographicCamera, perspectiveCamera, projection, { projectionType: orthographicCamera.projectionType, viewport })
|
|
42
|
-
// return Object.assign({}, orthoCam, projection, {near, far, left, right, top, bottom, target})
|
|
43
29
|
}
|
|
44
30
|
|
|
45
31
|
const toPerspectiveView = ({ camera }) => {
|
|
@@ -22,7 +22,6 @@ const cameraProps = {}
|
|
|
22
22
|
const defaults = Object.assign({}, cameraState, cameraProps)
|
|
23
23
|
|
|
24
24
|
const setProjection = (output, camera, input) => {
|
|
25
|
-
// console.log('input', input, 'camera', camera)
|
|
26
25
|
// context.viewportWidth / context.viewportHeight,
|
|
27
26
|
const aspect = input.width / input.height
|
|
28
27
|
|
|
@@ -80,9 +80,6 @@ const update = ({ controls, camera }, output) => {
|
|
|
80
80
|
let theta
|
|
81
81
|
let phi
|
|
82
82
|
|
|
83
|
-
// console.log('target', target)
|
|
84
|
-
// console.log(matrix)
|
|
85
|
-
|
|
86
83
|
if (up[2] === 1) {
|
|
87
84
|
// angle from z-axis around y-axis, upVector : z
|
|
88
85
|
theta = atan2(offset[0], offset[1])
|
|
@@ -327,35 +324,6 @@ const reset = ({ controls, camera }, desiredState) => {
|
|
|
327
324
|
return options
|
|
328
325
|
}
|
|
329
326
|
|
|
330
|
-
// FIXME: upgrade or obsolete
|
|
331
|
-
const setFocus = ({ controls, camera }, focusPoint) => {
|
|
332
|
-
const sub = (a, b) => a.map((a1, i) => a1 - b[i])
|
|
333
|
-
const add = (a, b) => a.map((a1, i) => a1 + b[i]) // NOTE: NO typedArray.map support on old browsers, polyfilled
|
|
334
|
-
const camTarget = camera.target
|
|
335
|
-
const diff = sub(focusPoint, camTarget) // [ focusPoint[0] - camTarget[0],
|
|
336
|
-
const zOffset = [0, 0, diff[2] * 0.5]
|
|
337
|
-
camera.target = add(camTarget, zOffset)
|
|
338
|
-
camera.position = add(camera.position, zOffset)
|
|
339
|
-
return camera
|
|
340
|
-
|
|
341
|
-
// old 'zoom to fit' update code
|
|
342
|
-
/* if (targetTgt && positionTgt) {
|
|
343
|
-
const posDiff = vec3.subtract([], positionTgt, newPosition)
|
|
344
|
-
const tgtDiff = vec3.subtract([], targetTgt, newTarget)
|
|
345
|
-
// console.log('posDiff', newPosition, positionTgt, newTarget, targetTgt)
|
|
346
|
-
if (vec3.length(posDiff) > 0.1 && vec3.length(tgtDiff) > 0.1) {
|
|
347
|
-
newPosition = vec3.scaleAndAdd(newPosition, newPosition, posDiff, 0.1)
|
|
348
|
-
newTarget = vec3.scaleAndAdd(newTarget, newTarget, tgtDiff, 0.1)
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
if (settings.autoAdjustPlanes) {
|
|
352
|
-
var distance = vec3.squaredDistance(newTarget, newPosition)
|
|
353
|
-
near = Math.min(Math.max(5, distance * 0.0015), 100) // these are empirical values , after a LOT of testing
|
|
354
|
-
projection = mat4.perspective([], camera.fov, camera.aspect, camera.near, camera.far)
|
|
355
|
-
}
|
|
356
|
-
} */
|
|
357
|
-
}
|
|
358
|
-
|
|
359
327
|
module.exports = {
|
|
360
328
|
controlsProps,
|
|
361
329
|
controlsState,
|
|
@@ -34,10 +34,6 @@ const entitiesFromSolids = (params, solids) => {
|
|
|
34
34
|
// generate multiple geometries if positions count is >65535
|
|
35
35
|
geometry = flatten(geometry)[0]
|
|
36
36
|
|
|
37
|
-
// const time = (performance.now() - start) / 1000
|
|
38
|
-
// console.log(`Total time for geometry conversion: ${time} s`)
|
|
39
|
-
// console.log('geometry', geometry)
|
|
40
|
-
|
|
41
37
|
// bounds
|
|
42
38
|
const bounds = computeBounds({ geometry })// FXIME : ACTUALLY deal with arrays as inputs see above
|
|
43
39
|
|
|
@@ -7,14 +7,13 @@ const maxIndex = 65535
|
|
|
7
7
|
* Convert the given solid into one or more geometries for rendering.
|
|
8
8
|
* @param {Object} options - options for conversion
|
|
9
9
|
* @param {Array} options.color - RGBA of solid
|
|
10
|
-
* @param {Float} options.normalThreshold - threshold beyond which to split normals
|
|
11
10
|
* @param {Boolean} options.smoothLighting - set to true in order to use interpolated vertex normals
|
|
12
11
|
* this creates nice round spheres but does not represent the shape of the actual model
|
|
13
12
|
* @param {geom3} solid - the solid to convert
|
|
14
13
|
* @return {Array} list of new geometries
|
|
15
14
|
*/
|
|
16
15
|
const geom3ToGeometries = (options, solid) => {
|
|
17
|
-
let { color, smoothLighting
|
|
16
|
+
let { color, smoothLighting } = options
|
|
18
17
|
|
|
19
18
|
if ('color' in solid) color = solid.color
|
|
20
19
|
|
|
@@ -97,7 +96,7 @@ const smoothing = () => {
|
|
|
97
96
|
const color = []
|
|
98
97
|
let isTransparent = true
|
|
99
98
|
const smoothLighting = true
|
|
100
|
-
const normalThreshold = 0.5
|
|
99
|
+
const normalThreshold = 0.5 // threshold beyond which to split normals
|
|
101
100
|
const positions = []
|
|
102
101
|
const normals = []
|
|
103
102
|
const indices = []
|
|
@@ -14,9 +14,7 @@ const drawLines = (regl, params = {}) => {
|
|
|
14
14
|
const hasIndices = !!(geometry.indices && geometry.indices.length > 0)
|
|
15
15
|
const hasNormals = !!(geometry.normals && geometry.normals.length > 0)
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let commandParams = {
|
|
17
|
+
const commandParams = {
|
|
20
18
|
primitive: 'lines',
|
|
21
19
|
vert: require('./meshShaders').vert,
|
|
22
20
|
frag: require('./colorOnlyShaders').frag,
|
|
@@ -28,15 +28,13 @@ const drawMesh = (regl, params = { extras: {} }) => {
|
|
|
28
28
|
const frag = hasVertexColors ? require('./vColorShaders').frag : require('./meshShaders').frag
|
|
29
29
|
const modelMatrixInv = mat4.invert(mat4.create(), transforms)
|
|
30
30
|
|
|
31
|
-
// console.log('type', geometry.type, 'color', color, hasVertexColors)
|
|
32
|
-
|
|
33
31
|
let commandParams = {
|
|
34
32
|
primitive: 'triangles',
|
|
35
33
|
vert,
|
|
36
34
|
frag,
|
|
37
35
|
|
|
38
36
|
uniforms: {
|
|
39
|
-
model: (context, props) => transforms
|
|
37
|
+
model: (context, props) => transforms,
|
|
40
38
|
ucolor: (context, props) => (props && props.color) ? props.color : color,
|
|
41
39
|
// semi hack, woraround to enable/disable vertex colors !!!
|
|
42
40
|
vColorToggler: (context, props) => (props && props.useVertexColors && props.useVertexColors === true) ? 1.0 : 0.0,
|
package/src/rendering/render.js
CHANGED
|
@@ -27,7 +27,6 @@ const prepareRender = (params) => {
|
|
|
27
27
|
|
|
28
28
|
// create the main draw command
|
|
29
29
|
const command = (props) => {
|
|
30
|
-
// console.log('params in render', props)
|
|
31
30
|
props.rendering = Object.assign({}, renderDefaults, props.rendering)
|
|
32
31
|
|
|
33
32
|
// props is the first parameter, the second one is a function, doing the actual rendering
|
|
@@ -58,7 +57,6 @@ const prepareRender = (params) => {
|
|
|
58
57
|
drawCmd = props.drawCommands[visuals.drawCmd](regl, entity)
|
|
59
58
|
drawCache2.set(visuals.cacheId, drawCmd)
|
|
60
59
|
}
|
|
61
|
-
// console.log('drawing with', drawCmd, entity)
|
|
62
60
|
const drawParams = { // FIXME: horrible, tidy up !!: what is needed/should be passed to render pass ?
|
|
63
61
|
...entity,
|
|
64
62
|
...visuals,
|