@jscad/regl-renderer 2.6.7 → 3.0.0-alpha.0
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 +5 -189
- package/README.md +21 -11
- package/demo-cli.js +20 -16
- package/demo-web.js +6 -4
- package/demo.es.html +236 -0
- package/demo.html +21 -15
- package/dist/jscad-regl-renderer.es.js +13 -0
- package/dist/jscad-regl-renderer.min.js +13 -335
- package/package.json +41 -16
- package/rollup.config.js +27 -0
- package/src/bound-utils/boundingBox.js +1 -2
- package/src/bound-utils/boundingSphere.js +4 -5
- package/src/bound-utils/computeBounds.js +4 -6
- package/src/bound-utils/computeBounds.test.js +2 -2
- package/src/cameras/camera.js +15 -19
- package/src/cameras/index.js +8 -4
- package/src/cameras/orthographicCamera.js +4 -6
- package/src/cameras/perspectiveCamera.js +7 -9
- package/src/controls/index.js +6 -0
- package/src/controls/orbitControls.js +18 -27
- package/src/{geometry-utils-V2 → geometry-utils-V3}/entitiesFromSolids.js +7 -9
- package/src/{geometry-utils-V2 → geometry-utils-V3}/entitiesFromSolids.test.js +4 -4
- package/src/geometry-utils-V3/geom2ToGeometries.js +57 -0
- package/src/{geometry-utils-V2 → geometry-utils-V3}/geom2ToGeometries.test.js +16 -12
- package/src/{geometry-utils-V2 → geometry-utils-V3}/geom3ToGeometries.js +3 -5
- package/src/{geometry-utils-V2 → geometry-utils-V3}/geom3ToGeometries.test.js +2 -2
- package/src/{geometry-utils-V2 → geometry-utils-V3}/path2ToGeometries.js +4 -5
- package/src/{geometry-utils-V2 → geometry-utils-V3}/path2ToGeometries.test.js +2 -2
- package/src/index.js +5 -20
- package/src/rendering/commands/drawAxis/index.js +2 -4
- package/src/rendering/commands/drawExps/drawConnector/arcGeo.js +1 -3
- package/src/rendering/commands/drawExps/drawConnector/index.js +5 -7
- package/src/rendering/commands/drawExps/drawMesh.js +2 -4
- package/src/rendering/commands/drawExps/drawMeshNoNormals.js +2 -4
- package/src/rendering/commands/drawExps/drawNormals.js +2 -4
- package/src/rendering/commands/drawExps/drawNormals2.js +2 -4
- package/src/rendering/commands/drawGrid/{index.js → makeDrawGrid.js} +2 -4
- package/src/rendering/commands/drawGrid/{multi.js → makeDrawMultiGrid.js} +5 -5
- package/src/rendering/commands/drawLines/colorOnlyShaders.js +2 -2
- package/src/rendering/commands/drawLines/index.js +9 -7
- package/src/rendering/commands/drawLines/meshShaders.js +3 -3
- package/src/rendering/commands/drawLines/vColorShaders.js +3 -3
- package/src/rendering/commands/drawMesh/colorOnlyShaders.js +2 -2
- package/src/rendering/commands/drawMesh/index.js +8 -7
- package/src/rendering/commands/drawMesh/meshShaders.js +3 -3
- package/src/rendering/commands/drawMesh/vColorShaders.js +3 -3
- package/src/rendering/commands/index.js +11 -0
- package/src/rendering/render.js +10 -10
- package/src/rendering/renderContext.js +2 -4
- package/src/rendering/renderDefaults.js +9 -11
- package/src/utils.js +3 -6
- package/src/geometry-utils-V1/cagToGeometries.js +0 -52
- package/src/geometry-utils-V1/csgToGeometries.js +0 -220
- package/src/geometry-utils-V1/entitiesFromSolids.js +0 -75
- package/src/geometry-utils-V2/geom2ToGeometries.js +0 -66
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import mat4 from 'gl-mat4'
|
|
2
2
|
|
|
3
3
|
// The only data types accepted by WebGL (and OpenGL ES 2.0) for indices are unsigned bytes and unsigned shorts.
|
|
4
4
|
// Since an unsigned short has a range of 0-65535, this means that gl.DrawElements can only reference 65k vertices per draw call.
|
|
@@ -11,7 +11,7 @@ const maxIndex = Math.floor(65535 / 2) - 2 // two vertices per segment, less clo
|
|
|
11
11
|
* @param {path2} solid - the solid to convert
|
|
12
12
|
* @return {Array} list of new geometries
|
|
13
13
|
*/
|
|
14
|
-
const path2ToGeometries = (options, solid) => {
|
|
14
|
+
export const path2ToGeometries = (options, solid) => {
|
|
15
15
|
let { color } = options
|
|
16
16
|
|
|
17
17
|
const points = solid.points
|
|
@@ -43,7 +43,8 @@ const path2ToGeometries = (options, solid) => {
|
|
|
43
43
|
positions.push([point[0], point[1], 0])
|
|
44
44
|
}
|
|
45
45
|
// assemble the geometry
|
|
46
|
-
const
|
|
46
|
+
const normal = [0, 0, -1]
|
|
47
|
+
const normals = positions.map((x) => normal)
|
|
47
48
|
const indices = positions.map((x, i) => i) // FIXME: temporary, not really needed, need to change drawLines
|
|
48
49
|
const transforms = solid.transforms ? mat4.clone(solid.transforms) : mat4.create()
|
|
49
50
|
|
|
@@ -54,5 +55,3 @@ const path2ToGeometries = (options, solid) => {
|
|
|
54
55
|
}
|
|
55
56
|
return geometries
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
module.exports = path2ToGeometries
|
package/src/index.js
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
drawAxis: require('./rendering/commands/drawAxis'),
|
|
7
|
-
drawMesh: require('./rendering/commands/drawMesh'),
|
|
8
|
-
drawLines: require('./rendering/commands/drawLines')
|
|
9
|
-
},
|
|
10
|
-
cameras: {
|
|
11
|
-
camera: require('./cameras/camera'),
|
|
12
|
-
orthographic: require('./cameras/orthographicCamera'),
|
|
13
|
-
perspective: require('./cameras/perspectiveCamera')
|
|
14
|
-
},
|
|
15
|
-
controls: {
|
|
16
|
-
orbit: require('./controls/orbitControls')
|
|
17
|
-
},
|
|
18
|
-
entitiesFromSolids: require('./geometry-utils-V2/entitiesFromSolids')
|
|
19
|
-
|
|
20
|
-
}
|
|
1
|
+
export * as cameras from './cameras/index.js'
|
|
2
|
+
export * as commands from './rendering/commands/index.js'
|
|
3
|
+
export * as controls from './controls/index.js'
|
|
4
|
+
export { entitiesFromSolids } from './geometry-utils-V3/entitiesFromSolids.js'
|
|
5
|
+
export { prepareRender } from './rendering/render.js'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import * as mat4 from 'gl-mat4'
|
|
2
2
|
|
|
3
|
-
const drawAxis = (regl, params) => {
|
|
3
|
+
export const drawAxis = (regl, params) => {
|
|
4
4
|
const defaults = {
|
|
5
5
|
xColor: [1, 0, 0, 1],
|
|
6
6
|
yColor: [0, 1, 0, 1],
|
|
@@ -65,5 +65,3 @@ const drawAxis = (regl, params) => {
|
|
|
65
65
|
])
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
module.exports = drawAxis
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
const makeDrawMesh = require('../drawMeshNoNormals')
|
|
3
|
-
const makeArcGeometry = require('./arcGeo')
|
|
1
|
+
import mat4 from 'gl-mat4'
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
import { makeDrawAxis } from '../drawAxis.js'
|
|
4
|
+
import { makeDrawMesh } from '../drawMeshNoNormals.js'
|
|
5
|
+
import { makeArcGeometry } from './arcGeo.js'
|
|
6
6
|
|
|
7
|
-
const drawConnector = (regl, params) => {
|
|
7
|
+
export const drawConnector = (regl, params) => {
|
|
8
8
|
const argGeometry = makeArcGeometry({ innerRadius: 9, outerRadius: 10, startRadian: 0, endRadian: Math.PI * 2 })
|
|
9
9
|
const drawAxis = makeDrawAxis(regl, { alwaysVisible: false })
|
|
10
10
|
const drawArc = makeDrawMesh(regl, { geometry: argGeometry })
|
|
@@ -27,5 +27,3 @@ const drawConnector = (regl, params) => {
|
|
|
27
27
|
})
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
module.exports = drawConnector
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import mat4 from 'gl-mat4'
|
|
2
2
|
|
|
3
|
-
const drawMesh = (regl, params) => {
|
|
3
|
+
export const drawMesh = (regl, params) => {
|
|
4
4
|
const mesh = params.geometry
|
|
5
5
|
return regl({
|
|
6
6
|
vert: `
|
|
@@ -58,5 +58,3 @@ const drawMesh = (regl, params) => {
|
|
|
58
58
|
}
|
|
59
59
|
})
|
|
60
60
|
}
|
|
61
|
-
|
|
62
|
-
module.exports = drawMesh
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import mat4 from 'gl-mat4'
|
|
2
2
|
|
|
3
|
-
const drawMesh = (regl, params) => {
|
|
3
|
+
export const drawMesh = (regl, params) => {
|
|
4
4
|
const defaults = {
|
|
5
5
|
geometry: undefined
|
|
6
6
|
}
|
|
@@ -41,5 +41,3 @@ const drawMesh = (regl, params) => {
|
|
|
41
41
|
}
|
|
42
42
|
return regl(commandParams)
|
|
43
43
|
}
|
|
44
|
-
|
|
45
|
-
module.exports = drawMesh
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import mat4 from 'gl-mat4'
|
|
2
2
|
|
|
3
|
-
const drawNormals = (regl, params) => {
|
|
3
|
+
export const drawNormals = (regl, params) => {
|
|
4
4
|
const defaults = {
|
|
5
5
|
size: 20,
|
|
6
6
|
lineWidth: 5, // FIXME/ linewidth has been "deprecated" in multiple browsers etc, need a workaround,
|
|
@@ -72,5 +72,3 @@ const drawNormals = (regl, params) => {
|
|
|
72
72
|
const singleNormal = regl(commandParams)
|
|
73
73
|
return () => singleNormal(normaLines)
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
module.exports = drawNormals
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import mat4 from 'gl-mat4'
|
|
2
2
|
|
|
3
|
-
const drawNormals = (regl, params) => {
|
|
3
|
+
export const drawNormals = (regl, params) => {
|
|
4
4
|
const defaults = {
|
|
5
5
|
xColor: [1, 0, 0, 1],
|
|
6
6
|
// yColor: [0, 1, 0, 1],
|
|
@@ -69,5 +69,3 @@ const drawNormals = (regl, params) => {
|
|
|
69
69
|
const singleNormal = regl(commandParams)
|
|
70
70
|
return () => singleNormal(foo)
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
module.exports = drawNormals
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import * as mat4 from 'gl-mat4'
|
|
2
2
|
|
|
3
|
-
const makeDrawGrid = (regl, params = {}) => {
|
|
3
|
+
export const makeDrawGrid = (regl, params = {}) => {
|
|
4
4
|
const positions = []
|
|
5
5
|
const defaults = {
|
|
6
6
|
visuals: {
|
|
@@ -138,5 +138,3 @@ const makeDrawGrid = (regl, params = {}) => {
|
|
|
138
138
|
|
|
139
139
|
})
|
|
140
140
|
}
|
|
141
|
-
|
|
142
|
-
module.exports = makeDrawGrid
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { makeDrawGrid } from './makeDrawGrid.js'
|
|
2
|
+
|
|
3
|
+
export const makeDrawMultiGrid = (regl, params) => {
|
|
2
4
|
const defaults = {
|
|
3
5
|
size: [50, 50],
|
|
4
6
|
ticks: [10, 1]
|
|
5
7
|
}
|
|
6
8
|
const { size, ticks } = Object.assign({}, defaults, params)
|
|
7
|
-
const drawMainGrid =
|
|
8
|
-
const drawSubGrid =
|
|
9
|
+
const drawMainGrid = makeDrawGrid(regl, { size, ticks: ticks[0] })
|
|
10
|
+
const drawSubGrid = makeDrawGrid(regl, { size, ticks: ticks[1] })
|
|
9
11
|
const drawGrid = (props) => {
|
|
10
12
|
drawMainGrid(props)
|
|
11
13
|
drawSubGrid({ color: props.subColor, fadeOut: props.fadeOut })
|
|
12
14
|
}
|
|
13
15
|
return drawGrid
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
module.exports = makeDrawMultiGrid
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import * as mat4 from 'gl-mat4'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import * as vColorShaders from './vColorShaders.js'
|
|
4
|
+
import * as meshShaders from './meshShaders.js'
|
|
5
|
+
import * as colorOnlyShaders from './colorOnlyShaders.js'
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
import { meshColor } from '../../renderDefaults.js'
|
|
8
|
+
|
|
9
|
+
export const drawLines = (regl, params = {}) => {
|
|
6
10
|
const defaults = {
|
|
7
11
|
color: meshColor,
|
|
8
12
|
geometry: undefined
|
|
@@ -15,8 +19,8 @@ const drawLines = (regl, params = {}) => {
|
|
|
15
19
|
const hasNormals = !!(geometry.normals && geometry.normals.length > 0)
|
|
16
20
|
const hasVertexColors = !!(geometry.colors && geometry.colors.length > 0)
|
|
17
21
|
|
|
18
|
-
const vert = hasVertexColors ?
|
|
19
|
-
const frag = hasVertexColors ?
|
|
22
|
+
const vert = hasVertexColors ? vColorShaders.vert : meshShaders.vert
|
|
23
|
+
const frag = hasVertexColors ? vColorShaders.frag : colorOnlyShaders.frag
|
|
20
24
|
|
|
21
25
|
const commandParams = {
|
|
22
26
|
primitive: 'lines',
|
|
@@ -55,5 +59,3 @@ const drawLines = (regl, params = {}) => {
|
|
|
55
59
|
|
|
56
60
|
return regl(commandParams)
|
|
57
61
|
}
|
|
58
|
-
|
|
59
|
-
module.exports = drawLines
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const vert = `
|
|
2
2
|
precision mediump float;
|
|
3
3
|
|
|
4
4
|
uniform float camNear, camFar;
|
|
@@ -24,7 +24,7 @@ void main() {
|
|
|
24
24
|
}
|
|
25
25
|
`
|
|
26
26
|
|
|
27
|
-
const
|
|
27
|
+
const frag = `
|
|
28
28
|
precision mediump float;
|
|
29
29
|
varying vec3 surfaceNormal;
|
|
30
30
|
uniform float ambientLightAmount;
|
|
@@ -55,4 +55,4 @@ void main () {
|
|
|
55
55
|
gl_FragColor = vec4((ambient + diffuse + diffuse2 * v), endColor.a);
|
|
56
56
|
}`
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
export { vert, frag }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const vert = `
|
|
2
2
|
precision mediump float;
|
|
3
3
|
|
|
4
4
|
uniform float camNear, camFar;
|
|
@@ -24,7 +24,7 @@ void main() {
|
|
|
24
24
|
}
|
|
25
25
|
`
|
|
26
26
|
|
|
27
|
-
const
|
|
27
|
+
const frag = `
|
|
28
28
|
precision mediump float;
|
|
29
29
|
varying vec4 vColor;
|
|
30
30
|
|
|
@@ -32,4 +32,4 @@ void main () {
|
|
|
32
32
|
gl_FragColor = vColor;
|
|
33
33
|
}
|
|
34
34
|
`
|
|
35
|
-
|
|
35
|
+
export { frag, vert }
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import * as mat4 from 'gl-mat4'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import * as vColorShaders from './vColorShaders.js'
|
|
4
|
+
import * as meshShaders from './meshShaders.js'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
import { meshColor } from '../../renderDefaults.js'
|
|
7
|
+
|
|
8
|
+
export const drawMesh = (regl, params = { extras: {} }) => {
|
|
6
9
|
const defaults = {
|
|
7
10
|
useVertexColors: true,
|
|
8
11
|
dynamicCulling: true,
|
|
@@ -25,8 +28,8 @@ const drawMesh = (regl, params = { extras: {} }) => {
|
|
|
25
28
|
? (flip ? 'front' : 'back')
|
|
26
29
|
: 'back'
|
|
27
30
|
|
|
28
|
-
const vert = hasVertexColors ?
|
|
29
|
-
const frag = hasVertexColors ?
|
|
31
|
+
const vert = hasVertexColors ? vColorShaders.vert : meshShaders.vert
|
|
32
|
+
const frag = hasVertexColors ? vColorShaders.frag : meshShaders.frag
|
|
30
33
|
const modelMatrixInv = mat4.invert(mat4.create(), transforms)
|
|
31
34
|
|
|
32
35
|
let commandParams = {
|
|
@@ -87,5 +90,3 @@ const drawMesh = (regl, params = { extras: {} }) => {
|
|
|
87
90
|
commandParams = Object.assign({}, commandParams, params.extras)
|
|
88
91
|
return regl(commandParams)
|
|
89
92
|
}
|
|
90
|
-
|
|
91
|
-
module.exports = drawMesh
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const frag = `
|
|
2
2
|
precision mediump float;
|
|
3
3
|
varying vec3 surfaceNormal;
|
|
4
4
|
uniform float ambientLightAmount;
|
|
@@ -29,7 +29,7 @@ void main () {
|
|
|
29
29
|
gl_FragColor = vec4((ambient + diffuse + diffuse2 * v), endColor.a);
|
|
30
30
|
}`
|
|
31
31
|
|
|
32
|
-
const
|
|
32
|
+
const vert = `
|
|
33
33
|
precision mediump float;
|
|
34
34
|
|
|
35
35
|
uniform float camNear, camFar;
|
|
@@ -51,4 +51,4 @@ void main() {
|
|
|
51
51
|
}
|
|
52
52
|
`
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
export { vert, frag }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const vert = `
|
|
2
2
|
precision mediump float;
|
|
3
3
|
|
|
4
4
|
uniform float camNear, camFar;
|
|
@@ -30,7 +30,7 @@ void main() {
|
|
|
30
30
|
//gl_Position = zBufferAdjust(glPosition, camNear, camFar);
|
|
31
31
|
}
|
|
32
32
|
`
|
|
33
|
-
const
|
|
33
|
+
const frag = `
|
|
34
34
|
precision mediump float;
|
|
35
35
|
varying vec3 surfaceNormal, surfacePosition;
|
|
36
36
|
|
|
@@ -73,4 +73,4 @@ void main () {
|
|
|
73
73
|
}
|
|
74
74
|
`
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
export { frag, vert }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { makeDrawMultiGrid as drawGrid } from './drawGrid/makeDrawMultiGrid.js'
|
|
2
|
+
import { drawAxis } from './drawAxis/index.js'
|
|
3
|
+
import { drawMesh } from './drawMesh/index.js'
|
|
4
|
+
import { drawLines } from './drawLines/index.js'
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
drawGrid,
|
|
8
|
+
drawAxis,
|
|
9
|
+
drawMesh,
|
|
10
|
+
drawLines
|
|
11
|
+
}
|
package/src/rendering/render.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
const renderDefaults = require('./renderDefaults')
|
|
1
|
+
import regl from 'regl'
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
import { renderContext } from './renderContext.js'
|
|
4
|
+
import * as renderDefaults from './renderDefaults.js'
|
|
5
|
+
|
|
6
|
+
export const prepareRender = (params) => {
|
|
5
7
|
const defaults = {
|
|
6
8
|
// extensions:['oes_element_index_uint']
|
|
7
9
|
}
|
|
@@ -20,7 +22,7 @@ const prepareRender = (params) => {
|
|
|
20
22
|
}
|
|
21
23
|
)
|
|
22
24
|
// setup regl
|
|
23
|
-
const
|
|
25
|
+
const base = regl(options) // , (width, height))
|
|
24
26
|
// setup draw command cache
|
|
25
27
|
// const drawCache = {}
|
|
26
28
|
const drawCache2 = new Map()
|
|
@@ -30,8 +32,8 @@ const prepareRender = (params) => {
|
|
|
30
32
|
props.rendering = Object.assign({}, renderDefaults, props.rendering)
|
|
31
33
|
|
|
32
34
|
// props is the first parameter, the second one is a function, doing the actual rendering
|
|
33
|
-
renderContext(
|
|
34
|
-
|
|
35
|
+
renderContext(base)(props, (context) => {
|
|
36
|
+
base.clear({
|
|
35
37
|
color: props.rendering.background,
|
|
36
38
|
depth: 1
|
|
37
39
|
})
|
|
@@ -54,7 +56,7 @@ const prepareRender = (params) => {
|
|
|
54
56
|
drawCmd = drawCache2.get(visuals.cacheId)
|
|
55
57
|
} else {
|
|
56
58
|
visuals.cacheId = drawCache2.size
|
|
57
|
-
drawCmd = props.drawCommands[visuals.drawCmd](
|
|
59
|
+
drawCmd = props.drawCommands[visuals.drawCmd](base, entity)
|
|
58
60
|
drawCache2.set(visuals.cacheId, drawCmd)
|
|
59
61
|
}
|
|
60
62
|
const drawParams = { // FIXME: horrible, tidy up !!: what is needed/should be passed to render pass ?
|
|
@@ -71,10 +73,8 @@ const prepareRender = (params) => {
|
|
|
71
73
|
// actual render function
|
|
72
74
|
return function render (data) {
|
|
73
75
|
// important for stats, correct resizing etc
|
|
74
|
-
|
|
76
|
+
base.poll()
|
|
75
77
|
command(data)// meh ??
|
|
76
78
|
// tick += 0.01
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
|
|
80
|
-
module.exports = prepareRender
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import * as mat4 from 'gl-mat4'
|
|
2
2
|
|
|
3
3
|
/** function that injects most of the uniforms into the regl context:
|
|
4
4
|
* ie keeps track of all regl global state.
|
|
5
5
|
* @param {} regl
|
|
6
6
|
* @param {} params={}
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
8
|
+
export const renderContext = (regl, params = {}) => {
|
|
9
9
|
const { fbo } = params
|
|
10
10
|
|
|
11
11
|
const commandParams = {
|
|
@@ -44,5 +44,3 @@ const renderWrapper = (regl, params = {}) => {
|
|
|
44
44
|
// it returns a function
|
|
45
45
|
return regl(Object.assign({}, commandParams, params.extras))
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
module.exports = renderWrapper
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
materialShininess: 8.0
|
|
11
|
-
}
|
|
1
|
+
export const background = [1, 1, 1, 1]
|
|
2
|
+
export const meshColor = [0, 0.6, 1, 1] // default face color or line color
|
|
3
|
+
export const lightColor = [1, 1, 1, 1] // note: for now there is a single preset light, not an entity
|
|
4
|
+
export const lightDirection = [0.2, 0.2, 1]
|
|
5
|
+
export const lightPosition = [100, 200, 100]
|
|
6
|
+
export const ambientLightAmount = 0.3
|
|
7
|
+
export const diffuseLightAmount = 0.89
|
|
8
|
+
export const specularLightAmount = 0.16
|
|
9
|
+
export const materialShininess = 8.0
|
package/src/utils.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* kinda, sorta like a nested object.assign, so that nested object values
|
|
2
3
|
* do not get lost
|
|
3
4
|
* note : this is NOT actually making anything immutable !
|
|
4
5
|
* @param {} output={}
|
|
5
6
|
* @param {} currentState
|
|
6
7
|
* @param {} options
|
|
7
8
|
*/
|
|
8
|
-
const merge = (output = {}, currentState, options) => {
|
|
9
|
+
export const merge = (output = {}, currentState, options) => {
|
|
9
10
|
output = currentState // JSON.parse(JSON.stringify(currentState))
|
|
10
11
|
Object.keys(options).forEach((key) => {
|
|
11
12
|
const item = options[key]
|
|
@@ -28,7 +29,3 @@ const merge = (output = {}, currentState, options) => {
|
|
|
28
29
|
|
|
29
30
|
return output
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
module.exports = {
|
|
33
|
-
merge
|
|
34
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const cagToGeometries = (cags, options) => {
|
|
2
|
-
const defaults = {
|
|
3
|
-
color: [1, 0.4, 0, 1]// default color
|
|
4
|
-
}
|
|
5
|
-
const { color } = Object.assign({}, defaults, options)
|
|
6
|
-
// flag for transparency
|
|
7
|
-
let isTransparent = false
|
|
8
|
-
|
|
9
|
-
const points = cagToPointsArray(cags).map((x) => [x[0], x[1], 0])
|
|
10
|
-
const normals = points.map((x) => [0, 0, -1])
|
|
11
|
-
const colors = points.map((x) => color)
|
|
12
|
-
const indices = points.map((x, i) => i) // FIXME: temporary, not really needed, need to change drawMesh
|
|
13
|
-
|
|
14
|
-
if (color[3] !== 1) {
|
|
15
|
-
isTransparent = true // FIXME should be analyzed for each vertex
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return [
|
|
19
|
-
{
|
|
20
|
-
// indices,
|
|
21
|
-
positions: points,
|
|
22
|
-
normals: normals,
|
|
23
|
-
colors: colors,
|
|
24
|
-
indices,
|
|
25
|
-
isTransparent
|
|
26
|
-
}]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// FIXME same as in scad-api helpers...
|
|
30
|
-
const cagToPointsArray = (input) => {
|
|
31
|
-
let points
|
|
32
|
-
if ('sides' in input) { // this is a cag
|
|
33
|
-
points = []
|
|
34
|
-
input.sides.forEach((side) => {
|
|
35
|
-
points.push([side.vertex0.pos.x, side.vertex0.pos.y])
|
|
36
|
-
points.push([side.vertex1.pos.x, side.vertex1.pos.y])
|
|
37
|
-
})
|
|
38
|
-
// cag.sides.map(side => [side.vertex0.pos.x, side.vertex0.pos.y])
|
|
39
|
-
//, side.vertex1.pos.x, side.vertex1.pos.y])
|
|
40
|
-
// due to the logic of CAG.fromPoints()
|
|
41
|
-
// move the first point to the last
|
|
42
|
-
/* if (points.length > 0) {
|
|
43
|
-
points.push(points.shift())
|
|
44
|
-
} */
|
|
45
|
-
} else if ('points' in input) {
|
|
46
|
-
points = input.points.map((p) => ([p.x, p.y]))
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return points
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
module.exports = cagToGeometries
|