@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
package/package.json
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/regl-renderer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
4
|
"description": "Renderer for JSCAD Geometries",
|
|
5
5
|
"homepage": "https://openjscad.xyz/",
|
|
6
6
|
"repository": "https://github.com/jscad/OpenJSCAD.org",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"main": "src/index.js",
|
|
9
|
+
"types": "types",
|
|
8
10
|
"unpkg": "dist/jscad-regl-renderer.min.js",
|
|
11
|
+
"module": "dist/jscad-regl-renderer.es.js",
|
|
9
12
|
"scripts": {
|
|
10
|
-
"build": "
|
|
11
|
-
"
|
|
12
|
-
"dev": "
|
|
13
|
+
"build": "rollup --config",
|
|
14
|
+
"coverage": "c8 --all --reporter=html --reporter=text pnpm test",
|
|
15
|
+
"dev": "http-server",
|
|
13
16
|
"demo-cli": "node ./demo-cli.js",
|
|
14
|
-
"demo-web": "budo ./demo-web.js --title regl-renderer --live",
|
|
15
17
|
"test": "ava 'src/**/*.test.js' --verbose --timeout 2m",
|
|
16
|
-
"
|
|
18
|
+
"test:tsd": "tsd",
|
|
19
|
+
"version": "pnpm run build && git add dist"
|
|
17
20
|
},
|
|
18
|
-
"
|
|
21
|
+
"contributors": [
|
|
22
|
+
{
|
|
23
|
+
"name": "z3dev",
|
|
24
|
+
"url": "https://github.com/z3dev"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "Davor Hrg",
|
|
28
|
+
"url": "https://github.com/hrgdavor"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "Kenny",
|
|
32
|
+
"url": "https://github.com/platypil"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "Timothy Johnson"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "Mark 'kaosat-dev' Moissette",
|
|
39
|
+
"url": "https://github.com/kaosat-dev"
|
|
40
|
+
}
|
|
41
|
+
],
|
|
19
42
|
"keywords": [
|
|
20
43
|
"openjscad",
|
|
21
44
|
"jscad",
|
|
@@ -26,9 +49,8 @@
|
|
|
26
49
|
"publishConfig": {
|
|
27
50
|
"access": "public"
|
|
28
51
|
},
|
|
29
|
-
"types": "types",
|
|
30
52
|
"dependencies": {
|
|
31
|
-
"@jscad/array-utils": "
|
|
53
|
+
"@jscad/array-utils": "3.0.0-alpha.0",
|
|
32
54
|
"camera-unproject": "1.0.1",
|
|
33
55
|
"gl-mat4": "1.2.0",
|
|
34
56
|
"gl-vec3": "1.1.3",
|
|
@@ -36,12 +58,15 @@
|
|
|
36
58
|
},
|
|
37
59
|
"devDependencies": {
|
|
38
60
|
"@jscad/img-utils": "2.0.5",
|
|
39
|
-
"@jscad/modeling": "
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
61
|
+
"@jscad/modeling": "3.0.0-alpha.0",
|
|
62
|
+
"@rollup/plugin-commonjs": "^23.0.4",
|
|
63
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
64
|
+
"@rollup/plugin-terser": "^0.4.3",
|
|
65
|
+
"ava": "^4.3.3",
|
|
66
|
+
"c8": "^8.0.0",
|
|
67
|
+
"http-server": "^14.1.1",
|
|
68
|
+
"rollup": "^2.79.1",
|
|
69
|
+
"rollup-plugin-banner": "^0.2.1"
|
|
45
70
|
},
|
|
46
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "3656d36ed9cd738ab884e86aae5a2ce08d52adf7"
|
|
47
72
|
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import banner from 'rollup-plugin-banner'
|
|
2
|
+
import commonjs from '@rollup/plugin-commonjs'
|
|
3
|
+
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
|
4
|
+
import terser from '@rollup/plugin-terser'
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
input: 'src/index.js',
|
|
8
|
+
|
|
9
|
+
output: [
|
|
10
|
+
{
|
|
11
|
+
file: 'dist/jscad-regl-renderer.min.js',
|
|
12
|
+
format: 'umd',
|
|
13
|
+
name: 'jscadReglRenderer'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
file: 'dist/jscad-regl-renderer.es.js',
|
|
17
|
+
format: 'es'
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
|
|
21
|
+
plugins: [
|
|
22
|
+
nodeResolve(),
|
|
23
|
+
commonjs(),
|
|
24
|
+
banner('<%= pkg.description %>\n@module <%= pkg.name %>\n@version <%= pkg.version %>\n@license <%= pkg.license %>'),
|
|
25
|
+
terser({ compress: { module: true }, mangle: false, format: { comments: 'some'} })
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// modified version of https://github.com/thibauts/vertices-bounding-box that also works with non nested positions
|
|
2
|
-
const boundingBox = (positions) => {
|
|
2
|
+
export const boundingBox = (positions) => {
|
|
3
3
|
if (positions.length === 0) {
|
|
4
4
|
return [[0, 0, 0], [0, 0, 0]]
|
|
5
5
|
}
|
|
@@ -35,4 +35,3 @@ const boundingBox = (positions) => {
|
|
|
35
35
|
|
|
36
36
|
return [min, max]
|
|
37
37
|
}
|
|
38
|
-
module.exports = boundingBox
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { squaredDistance, vec3 } from 'gl-vec3'
|
|
2
|
+
|
|
3
|
+
import { boundingBox } from './boundingBox.js'
|
|
3
4
|
|
|
4
5
|
/*
|
|
5
6
|
* compute diameter of the bounding sphere for the given (geometry) positions
|
|
@@ -7,7 +8,7 @@ const boundingBox = require('./boundingBox')
|
|
|
7
8
|
* @param {array} positions - the array/typed array of positions.
|
|
8
9
|
* for now loosely based on three.js implementation
|
|
9
10
|
*/
|
|
10
|
-
const boundingSphere = (center, positions) => {
|
|
11
|
+
export const boundingSphere = (center, positions) => {
|
|
11
12
|
if (positions.length === 0) {
|
|
12
13
|
return null
|
|
13
14
|
}
|
|
@@ -33,5 +34,3 @@ const boundingSphere = (center, positions) => {
|
|
|
33
34
|
}
|
|
34
35
|
return Math.sqrt(maxRadiusSq)
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
module.exports = boundingSphere
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import vec3 from 'gl-vec3'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { flatten } from '@jscad/array-utils'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { boundingBox } from './boundingBox.js'
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
8
|
* Compute the bounds of the given geometries.
|
|
@@ -17,7 +17,7 @@ const boundingBox = require('./boundingBox')
|
|
|
17
17
|
* size: [6,20,4]
|
|
18
18
|
* }
|
|
19
19
|
*/
|
|
20
|
-
const computeBounds = (...geometries) => {
|
|
20
|
+
export const computeBounds = (...geometries) => {
|
|
21
21
|
geometries = flatten(geometries)
|
|
22
22
|
|
|
23
23
|
let bbox // min and max
|
|
@@ -50,5 +50,3 @@ const computeBounds = (...geometries) => {
|
|
|
50
50
|
}
|
|
51
51
|
return bounds
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
module.exports = computeBounds
|
package/src/cameras/camera.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as vec3 from 'gl-vec3'
|
|
2
|
+
import * as mat4 from 'gl-mat4'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import * as orthographicCamera from './orthographicCamera.js'
|
|
5
|
+
import * as perspectiveCamera from './perspectiveCamera.js'
|
|
6
|
+
|
|
7
|
+
export const fromOrthographicToPerspective = (orthographicCamera) => {
|
|
8
|
+
const { near, far, fov } = orthographicCamera
|
|
6
9
|
// recompute projection matrix to use perspective camera projection matrix
|
|
7
10
|
const { viewport } = orthographicCamera
|
|
8
|
-
const projection =
|
|
9
|
-
const { projectionType } =
|
|
11
|
+
const projection = perspectiveCamera.setProjection(orthographicCamera, { width: viewport[2], height: viewport[3] })
|
|
12
|
+
const { projectionType } = perspectiveCamera.cameraState
|
|
10
13
|
return Object.assign({}, orthographicCamera, projection, { projectionType }, { near, far, fov })
|
|
11
14
|
}
|
|
12
15
|
|
|
13
|
-
const fromPerspectiveToOrthographic = (perspectiveCamera) => {
|
|
16
|
+
export const fromPerspectiveToOrthographic = (perspectiveCamera) => {
|
|
14
17
|
const { fov, aspect } = perspectiveCamera
|
|
15
18
|
|
|
16
19
|
// set the orthographic view rectangle to 0,0,width,height
|
|
@@ -23,12 +26,12 @@ const fromPerspectiveToOrthographic = (perspectiveCamera) => {
|
|
|
23
26
|
// we re-use near, far, & projection matrix of orthographicCamera
|
|
24
27
|
const { near, far, viewport } = perspectiveCamera
|
|
25
28
|
const fCam = { zoom: 1, near, far }
|
|
26
|
-
const
|
|
27
|
-
const projection =
|
|
28
|
-
return Object.assign({}, orthographicCamera, perspectiveCamera, projection, { projectionType
|
|
29
|
+
const projectionType = orthographicCamera.cameraState.projectionType
|
|
30
|
+
const projection = orthographicCamera.setProjection(fCam, { width, height })
|
|
31
|
+
return Object.assign({}, orthographicCamera, perspectiveCamera, projection, { projectionType, viewport })
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
const toPerspectiveView = ({ camera }) => {
|
|
34
|
+
export const toPerspectiveView = ({ camera }) => {
|
|
32
35
|
const offsetToTarget = vec3.distance(camera.position, camera.target)
|
|
33
36
|
const distance = offsetToTarget
|
|
34
37
|
const position = [distance, distance, distance]
|
|
@@ -40,7 +43,7 @@ const toPerspectiveView = ({ camera }) => {
|
|
|
40
43
|
/**
|
|
41
44
|
* Calculate the camera view and position for acheiving the given preset view.
|
|
42
45
|
*/
|
|
43
|
-
const toPresetView = (viewName, { camera }) => {
|
|
46
|
+
export const toPresetView = (viewName, { camera }) => {
|
|
44
47
|
const presets = {
|
|
45
48
|
top: [0, -0.000001, 1],
|
|
46
49
|
bottom: [0, 0, -1],
|
|
@@ -57,10 +60,3 @@ const toPresetView = (viewName, { camera }) => {
|
|
|
57
60
|
|
|
58
61
|
return { view, position }
|
|
59
62
|
}
|
|
60
|
-
|
|
61
|
-
module.exports = {
|
|
62
|
-
toPerspectiveView,
|
|
63
|
-
toPresetView,
|
|
64
|
-
fromOrthographicToPerspective,
|
|
65
|
-
fromPerspectiveToOrthographic
|
|
66
|
-
}
|
package/src/cameras/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import * as camera from './camera.js'
|
|
2
|
+
import * as orthographic from './orthographicCamera.js'
|
|
3
|
+
import * as perspective from './perspectiveCamera.js'
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
camera,
|
|
7
|
+
orthographic,
|
|
8
|
+
perspective
|
|
5
9
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import * as mat4 from 'gl-mat4'
|
|
2
2
|
|
|
3
|
-
const cameraState = {
|
|
3
|
+
export const cameraState = {
|
|
4
4
|
view: mat4.identity(new Float32Array(16)),
|
|
5
5
|
projection: mat4.identity(new Float32Array(16)),
|
|
6
6
|
matrix: mat4.identity(new Float32Array(16)), // not sure if needed
|
|
@@ -18,9 +18,9 @@ const cameraState = {
|
|
|
18
18
|
projectionType: 'orthographic'
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const cameraProps = {}
|
|
21
|
+
export const cameraProps = {}
|
|
22
22
|
|
|
23
|
-
const setProjection = (camera, input) => {
|
|
23
|
+
export const setProjection = (camera, input) => {
|
|
24
24
|
const { width, height } = input
|
|
25
25
|
// context.viewportWidth / context.viewportHeight,
|
|
26
26
|
const aspect = width / height
|
|
@@ -35,5 +35,3 @@ const setProjection = (camera, input) => {
|
|
|
35
35
|
const projection = mat4.ortho([], left, right, bottom, top, camera.near, camera.far)
|
|
36
36
|
return { projection, aspect, viewport }
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
module.exports = { cameraState, cameraProps, setProjection }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as mat4 from 'gl-mat4'
|
|
2
|
+
import * as vec3 from 'gl-vec3'
|
|
3
3
|
|
|
4
|
-
const cameraState = {
|
|
4
|
+
export const cameraState = {
|
|
5
5
|
view: mat4.identity(new Float32Array(16)),
|
|
6
6
|
projection: mat4.identity(new Float32Array(16)),
|
|
7
7
|
matrix: mat4.identity(new Float32Array(16)), // not sure if needed
|
|
@@ -18,10 +18,10 @@ const cameraState = {
|
|
|
18
18
|
projectionType: 'perspective'
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const cameraProps = {}
|
|
22
|
-
const defaults = Object.assign({}, cameraState, cameraProps)
|
|
21
|
+
export const cameraProps = {}
|
|
22
|
+
export const defaults = Object.assign({}, cameraState, cameraProps)
|
|
23
23
|
|
|
24
|
-
const setProjection = (output, camera, input) => {
|
|
24
|
+
export const setProjection = (output, camera, input) => {
|
|
25
25
|
// context.viewportWidth / context.viewportHeight,
|
|
26
26
|
const aspect = input.width / input.height
|
|
27
27
|
|
|
@@ -39,7 +39,7 @@ const setProjection = (output, camera, input) => {
|
|
|
39
39
|
return out
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
const update = (output, camera) => {
|
|
42
|
+
export const update = (output, camera) => {
|
|
43
43
|
if (!camera) {
|
|
44
44
|
camera = output
|
|
45
45
|
}
|
|
@@ -54,5 +54,3 @@ const update = (output, camera) => {
|
|
|
54
54
|
out.view = newView
|
|
55
55
|
return out
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
module.exports = { cameraState, cameraProps, defaults, setProjection, update }
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as vec3 from 'gl-vec3'
|
|
2
|
+
import * as mat4 from 'gl-mat4'
|
|
3
|
+
|
|
4
|
+
import { unproject } from 'camera-unproject'
|
|
5
|
+
|
|
6
|
+
import { computeBounds } from '../bound-utils/computeBounds.js'
|
|
7
|
+
import { setProjection } from '../cameras/orthographicCamera.js'
|
|
4
8
|
|
|
5
|
-
const
|
|
9
|
+
const { max, min, sqrt, PI, sin, cos, atan2 } = Math
|
|
6
10
|
|
|
7
11
|
// TODO: make it more data driven ?
|
|
8
12
|
/*
|
|
@@ -29,7 +33,7 @@ rotate => modify the angle input
|
|
|
29
33
|
|
|
30
34
|
*/
|
|
31
35
|
|
|
32
|
-
const controlsProps = {
|
|
36
|
+
export const controlsProps = {
|
|
33
37
|
limits: {
|
|
34
38
|
minDistance: 0.01,
|
|
35
39
|
maxDistance: 10000
|
|
@@ -57,16 +61,16 @@ const controlsProps = {
|
|
|
57
61
|
autoAdjustPlanes: true // adjust near & far planes when zooming in &out
|
|
58
62
|
}
|
|
59
63
|
|
|
60
|
-
const controlsState = {
|
|
64
|
+
export const controlsState = {
|
|
61
65
|
// orbit controls state
|
|
62
66
|
thetaDelta: 0,
|
|
63
67
|
phiDelta: 0,
|
|
64
68
|
scale: 1
|
|
65
69
|
}
|
|
66
70
|
|
|
67
|
-
const defaults = Object.assign({}, controlsState, controlsProps)
|
|
71
|
+
export const defaults = Object.assign({}, controlsState, controlsProps)
|
|
68
72
|
|
|
69
|
-
const update = ({ controls, camera }, output) => {
|
|
73
|
+
export const update = ({ controls, camera }, output) => {
|
|
70
74
|
// custom z up is settable, with inverted Y and Z (since we use camera[2] => up)
|
|
71
75
|
const { EPS, drag } = controls
|
|
72
76
|
const { position, target } = camera
|
|
@@ -158,7 +162,7 @@ const update = ({ controls, camera }, output) => {
|
|
|
158
162
|
* @param {Float} angle value of the angle to rotate
|
|
159
163
|
* @return {Object} the updated camera data/state
|
|
160
164
|
*/
|
|
161
|
-
const rotate = ({ controls, camera, speed = 1 }, angle) => {
|
|
165
|
+
export const rotate = ({ controls, camera, speed = 1 }, angle) => {
|
|
162
166
|
let {
|
|
163
167
|
thetaDelta,
|
|
164
168
|
phiDelta
|
|
@@ -185,7 +189,7 @@ const rotate = ({ controls, camera, speed = 1 }, angle) => {
|
|
|
185
189
|
* @param {Float} zoomDelta value of the zoom
|
|
186
190
|
* @return {Object} the updated camera data/state
|
|
187
191
|
*/
|
|
188
|
-
const zoom = ({ controls, camera, speed = 1 }, zoomDelta = 0) => {
|
|
192
|
+
export const zoom = ({ controls, camera, speed = 1 }, zoomDelta = 0) => {
|
|
189
193
|
let { scale } = controls
|
|
190
194
|
|
|
191
195
|
if (controls.userControl.zoom && camera && zoomDelta !== undefined && zoomDelta !== 0 && !isNaN(zoomDelta)) {
|
|
@@ -207,7 +211,7 @@ const zoom = ({ controls, camera, speed = 1 }, zoomDelta = 0) => {
|
|
|
207
211
|
const width = Math.tan(camera.fov) * distance * camera.aspect
|
|
208
212
|
const height = Math.tan(camera.fov) * distance
|
|
209
213
|
|
|
210
|
-
const projection =
|
|
214
|
+
const projection = setProjection(camera, { width, height })
|
|
211
215
|
camera = projection
|
|
212
216
|
}
|
|
213
217
|
|
|
@@ -227,8 +231,7 @@ const zoom = ({ controls, camera, speed = 1 }, zoomDelta = 0) => {
|
|
|
227
231
|
* @param {Float} delta value of the raw pan delta
|
|
228
232
|
* @return {Object} the updated camera data/state
|
|
229
233
|
*/
|
|
230
|
-
const pan = ({ controls, camera, speed = 1 }, delta) => {
|
|
231
|
-
const unproject = require('camera-unproject')
|
|
234
|
+
export const pan = ({ controls, camera, speed = 1 }, delta) => {
|
|
232
235
|
const { projection, view, viewport } = camera
|
|
233
236
|
const combinedProjView = mat4.multiply([], projection, view)
|
|
234
237
|
const invProjView = mat4.invert([], combinedProjView)
|
|
@@ -266,7 +269,7 @@ const pan = ({ controls, camera, speed = 1 }, delta) => {
|
|
|
266
269
|
* @param {Array} entities - an array of entities (see entitiesFromSolids)
|
|
267
270
|
* @return {Object} the updated camera data/state
|
|
268
271
|
*/
|
|
269
|
-
const zoomToFit = ({ controls, camera, entities }) => {
|
|
272
|
+
export const zoomToFit = ({ controls, camera, entities }) => {
|
|
270
273
|
// our camera.fov is already in radian, no need to convert
|
|
271
274
|
const { zoomToFit } = controls
|
|
272
275
|
if (zoomToFit.targets !== 'all') {
|
|
@@ -307,7 +310,7 @@ const zoomToFit = ({ controls, camera, entities }) => {
|
|
|
307
310
|
* @param {Object} desiredState the state to reset the camera to: defaults to default values
|
|
308
311
|
* @return {Object} the updated camera data/state
|
|
309
312
|
*/
|
|
310
|
-
const reset = ({ controls, camera }, desiredState) => {
|
|
313
|
+
export const reset = ({ controls, camera }, desiredState) => {
|
|
311
314
|
const options = {
|
|
312
315
|
camera: {
|
|
313
316
|
position: desiredState.camera.position,
|
|
@@ -323,15 +326,3 @@ const reset = ({ controls, camera }, desiredState) => {
|
|
|
323
326
|
}
|
|
324
327
|
return options
|
|
325
328
|
}
|
|
326
|
-
|
|
327
|
-
module.exports = {
|
|
328
|
-
controlsProps,
|
|
329
|
-
controlsState,
|
|
330
|
-
defaults,
|
|
331
|
-
update,
|
|
332
|
-
rotate,
|
|
333
|
-
zoom,
|
|
334
|
-
pan,
|
|
335
|
-
zoomToFit,
|
|
336
|
-
reset
|
|
337
|
-
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { flatten, toArray } from '@jscad/array-utils'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { meshColor } from '../rendering/renderDefaults.js'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { geom2ToGeometries } from './geom2ToGeometries.js'
|
|
6
|
+
import { geom3ToGeometries } from './geom3ToGeometries.js'
|
|
7
|
+
import { path2ToGeometries } from './path2ToGeometries.js'
|
|
8
8
|
|
|
9
9
|
/*
|
|
10
10
|
* Assemble a set of renderable entities from the given geometries.
|
|
@@ -35,7 +35,7 @@ const assembleEntities = (geometries) => {
|
|
|
35
35
|
* @param {Boolean} [options.smoothNormals=true] - smooth the normals of 3d solids, rendering a smooth surface
|
|
36
36
|
* @returns {Array} an array of renderable entities
|
|
37
37
|
*/
|
|
38
|
-
const entitiesFromSolids = (options, ...solids) => {
|
|
38
|
+
export const entitiesFromSolids = (options, ...solids) => {
|
|
39
39
|
const defaults = {
|
|
40
40
|
color: meshColor,
|
|
41
41
|
smoothNormals: true
|
|
@@ -48,7 +48,7 @@ const entitiesFromSolids = (options, ...solids) => {
|
|
|
48
48
|
const entities = []
|
|
49
49
|
solids.forEach((solid) => {
|
|
50
50
|
let geometries = []
|
|
51
|
-
if ('
|
|
51
|
+
if ('outlines' in solid) {
|
|
52
52
|
geometries = geom2ToGeometries({ color }, solid)
|
|
53
53
|
} else if ('points' in solid) {
|
|
54
54
|
geometries = path2ToGeometries({ color }, solid)
|
|
@@ -63,5 +63,3 @@ const entitiesFromSolids = (options, ...solids) => {
|
|
|
63
63
|
})
|
|
64
64
|
return entities
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
module.exports = entitiesFromSolids
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import test from 'ava'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { entitiesFromSolids } from './entitiesFromSolids.js'
|
|
4
4
|
|
|
5
5
|
test('entitiesFromSolids (various solids)', (t) => {
|
|
6
6
|
const solids = [
|
|
7
7
|
null,
|
|
8
|
-
{
|
|
8
|
+
{ outlines: [[[0, 0], [1, 0], [1, 1]]], color: [1, 0, 0, 0.5] },
|
|
9
9
|
{ points: [[0, 0], [1, 0], [1, 1]], transforms: [5, 0, 0, 0, 0, 4, 0, 0, 0, 0, 3, 0, 0, 0, 0, 2] },
|
|
10
10
|
{
|
|
11
11
|
polygons: [
|
|
@@ -18,7 +18,7 @@ test('entitiesFromSolids (various solids)', (t) => {
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
'hi',
|
|
21
|
-
{
|
|
21
|
+
{ outlines: [] },
|
|
22
22
|
{ points: [] },
|
|
23
23
|
{ polygons: [] }
|
|
24
24
|
]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import mat4 from 'gl-mat4'
|
|
2
|
+
|
|
3
|
+
const maxIndex = Math.floor(65535 / 2) // two vertices per segment
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Convert the given solid into one or more geometries for rendering.
|
|
7
|
+
* @param {Object} options - options for conversion
|
|
8
|
+
* @param {Array} options.color - RGBA of solid
|
|
9
|
+
* @param {geom2} solid - the V3 geom3 object to convert
|
|
10
|
+
* @return {Array} list of new geometries
|
|
11
|
+
*/
|
|
12
|
+
export const geom2ToGeometries = (options, solid) => {
|
|
13
|
+
let { color } = options
|
|
14
|
+
|
|
15
|
+
const outlines = solid.outlines
|
|
16
|
+
if (outlines.length === 0) return []
|
|
17
|
+
|
|
18
|
+
if ('color' in solid) color = solid.color
|
|
19
|
+
const isTransparent = (color[3] < 1.0)
|
|
20
|
+
|
|
21
|
+
const geometries = []
|
|
22
|
+
for (let i = 0; i < outlines.length; i++) {
|
|
23
|
+
const points = outlines[i]
|
|
24
|
+
const numgeometries = Math.floor(points.length / (maxIndex)) + 1
|
|
25
|
+
|
|
26
|
+
for (let g = 0; g < numgeometries; g++) {
|
|
27
|
+
const offset = g * maxIndex
|
|
28
|
+
const endset = Math.min(offset + maxIndex, points.length)
|
|
29
|
+
const positions = []
|
|
30
|
+
let prevvertice
|
|
31
|
+
for (let j = offset; j < endset; j++) {
|
|
32
|
+
const point = points[j]
|
|
33
|
+
if (prevvertice) {
|
|
34
|
+
positions.push([prevvertice[0], prevvertice[1], 0])
|
|
35
|
+
positions.push([point[0], point[1], 0])
|
|
36
|
+
}
|
|
37
|
+
prevvertice = point
|
|
38
|
+
}
|
|
39
|
+
// add the last segment if necessary
|
|
40
|
+
if ((g + 1) === numgeometries && prevvertice) {
|
|
41
|
+
const point = points[0]
|
|
42
|
+
positions.push([prevvertice[0], prevvertice[1], 0])
|
|
43
|
+
positions.push([point[0], point[1], 0])
|
|
44
|
+
}
|
|
45
|
+
// assemble the geometry
|
|
46
|
+
const normal = [0, 0, -1]
|
|
47
|
+
const normals = positions.map((x) => normal)
|
|
48
|
+
const indices = positions.map((x, i) => i) // FIXME: temporary, not really needed, need to change drawLines
|
|
49
|
+
const transforms = solid.transforms ? mat4.clone(solid.transforms) : mat4.create()
|
|
50
|
+
// FIXME positions should be Float32Array buffers to eliminate another conversion
|
|
51
|
+
// FIXME normals should be Float32Array buffers to eliminate another conversion
|
|
52
|
+
// FIXME indices should be Uint16Array buffers to eliminate another conversion
|
|
53
|
+
geometries.push({ type: '2d', positions, normals, indices, transforms, color, isTransparent })
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return geometries
|
|
57
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import test from 'ava'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { geom2ToGeometries } from './geom2ToGeometries.js'
|
|
4
4
|
|
|
5
5
|
const defaultTransforms = Float32Array.from([
|
|
6
6
|
1, 0, 0, 0,
|
|
@@ -11,7 +11,8 @@ const defaultTransforms = Float32Array.from([
|
|
|
11
11
|
|
|
12
12
|
test('geom2ToGeometries (empty solid)', (t) => {
|
|
13
13
|
const solid = {
|
|
14
|
-
|
|
14
|
+
outlines: [],
|
|
15
|
+
transforms: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
|
|
15
16
|
}
|
|
16
17
|
const expected = []
|
|
17
18
|
let geometries = geom2ToGeometries({ color: [1, 2, 3, 4] }, solid)
|
|
@@ -33,13 +34,15 @@ test('geom2ToGeometries (empty solid)', (t) => {
|
|
|
33
34
|
t.deepEqual(geometries, expected)
|
|
34
35
|
})
|
|
35
36
|
|
|
36
|
-
test('geom2ToGeometries (solid with
|
|
37
|
+
test('geom2ToGeometries (solid with outlines)', (t) => {
|
|
37
38
|
const solid = {
|
|
38
|
-
|
|
39
|
+
outlines: [
|
|
40
|
+
[[0, 0], [1, 0], [1, 1]]
|
|
41
|
+
],
|
|
42
|
+
transforms: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
|
|
39
43
|
}
|
|
40
44
|
const expected = [{
|
|
41
45
|
color: [1, 2, 3, 0.8],
|
|
42
|
-
colors: [],
|
|
43
46
|
indices: [0, 1, 2, 3, 4, 5],
|
|
44
47
|
normals: [[0, 0, -1], [0, 0, -1], [0, 0, -1], [0, 0, -1], [0, 0, -1], [0, 0, -1]],
|
|
45
48
|
positions: [[0, 0, 0], [1, 0, 0], [1, 0, 0], [1, 1, 0], [1, 1, 0], [0, 0, 0]],
|
|
@@ -51,14 +54,15 @@ test('geom2ToGeometries (solid with sides)', (t) => {
|
|
|
51
54
|
t.deepEqual(geometries, expected)
|
|
52
55
|
})
|
|
53
56
|
|
|
54
|
-
test('geom2ToGeometries (solid with > 65000
|
|
55
|
-
const
|
|
57
|
+
test('geom2ToGeometries (solid with > 65000 outlines)', (t) => {
|
|
58
|
+
const outline = []
|
|
56
59
|
for (let i = 0; i < 70000; i++) {
|
|
57
|
-
|
|
60
|
+
outline.push([i, i])
|
|
61
|
+
}
|
|
62
|
+
const solid = {
|
|
63
|
+
outlines: [outline],
|
|
64
|
+
transforms: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
|
|
58
65
|
}
|
|
59
|
-
const start = solid.sides[0]
|
|
60
|
-
const end = solid.sides[solid.sides.length - 1]
|
|
61
|
-
solid.sides.push([end[1], start[0]])
|
|
62
66
|
|
|
63
67
|
const geometries = geom2ToGeometries({ color: [1, 2, 3, 0.8] }, solid)
|
|
64
68
|
t.is(geometries.length, 3)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import vec3 from 'gl-vec3'
|
|
2
|
+
import mat4 from 'gl-mat4'
|
|
3
3
|
|
|
4
4
|
const maxIndex = 65535
|
|
5
5
|
|
|
@@ -12,7 +12,7 @@ const maxIndex = 65535
|
|
|
12
12
|
* @param {geom3} solid - the solid to convert
|
|
13
13
|
* @return {Array} list of new geometries
|
|
14
14
|
*/
|
|
15
|
-
const geom3ToGeometries = (options, solid) => {
|
|
15
|
+
export const geom3ToGeometries = (options, solid) => {
|
|
16
16
|
let { color, smoothLighting } = options
|
|
17
17
|
|
|
18
18
|
if ('color' in solid) color = solid.color
|
|
@@ -213,5 +213,3 @@ const fuzyNormalAndPositionLookup = (normalPositionLookup, toCompare, normalThre
|
|
|
213
213
|
}
|
|
214
214
|
return undefined
|
|
215
215
|
}
|
|
216
|
-
|
|
217
|
-
module.exports = geom3ToGeometries
|