@jscad/x3d-deserializer 2.2.5 → 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 +9 -45
- package/README.md +3 -1
- package/dist/jscad-x3d-deserializer.es.js +37 -0
- package/dist/jscad-x3d-deserializer.min.js +38 -0
- package/package.json +21 -9
- package/rollup.config.js +29 -0
- package/src/constants.js +1 -5
- package/src/createTransform.js +11 -13
- package/src/extrudeX3D.js +5 -14
- package/src/index.js +7 -15
- package/src/instantiate.js +6 -10
- package/src/instantiateDefinitions.js +10 -12
- package/src/instantiateLine.js +11 -16
- package/src/instantiateMesh.js +6 -11
- package/src/instantiatePrimitive.js +37 -26
- package/src/objects.js +38 -83
- package/src/parse.js +7 -9
- package/src/translate.js +8 -27
- package/src/translateDefinitions.js +5 -7
- package/src/translateHelpers.js +6 -16
- package/src/translateLine.js +3 -5
- package/src/translateMesh.js +4 -6
- package/src/translateShape.js +23 -27
- package/tests/createTransform.test.js +2 -2
- package/tests/instantiate.test.js +62 -63
- package/tests/translate.test.js +37 -31
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jscad/x3d-deserializer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
4
|
"description": "X3D Deserializer for JSCAD",
|
|
5
|
+
"homepage": "https://openjscad.xyz/",
|
|
5
6
|
"repository": "https://github.com/jscad/OpenJSCAD.org/",
|
|
7
|
+
"type": "module",
|
|
6
8
|
"main": "src/index.js",
|
|
9
|
+
"unpkg": "dist/jscad-x3d-deserializer.min.js",
|
|
10
|
+
"module": "dist/jscad-x3d-deserializer.es.js",
|
|
7
11
|
"scripts": {
|
|
8
|
-
"
|
|
9
|
-
"
|
|
12
|
+
"build": "rollup --config",
|
|
13
|
+
"coverage": "c8 --all --reporter=html --reporter=text pnpm test",
|
|
14
|
+
"test": "ava --verbose --timeout 2m 'tests/**/*.test.js'",
|
|
15
|
+
"version": "pnpm run build && git add dist"
|
|
10
16
|
},
|
|
11
17
|
"contributors": [
|
|
12
18
|
{
|
|
@@ -26,13 +32,19 @@
|
|
|
26
32
|
"access": "public"
|
|
27
33
|
},
|
|
28
34
|
"dependencies": {
|
|
29
|
-
"@jscad/array-utils": "
|
|
30
|
-
"@jscad/modeling": "
|
|
31
|
-
"saxes": "
|
|
35
|
+
"@jscad/array-utils": "3.0.0-alpha.0",
|
|
36
|
+
"@jscad/modeling": "3.0.0-alpha.0",
|
|
37
|
+
"saxes": "^6.0.0"
|
|
32
38
|
},
|
|
33
39
|
"devDependencies": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
40
|
+
"@rollup/plugin-commonjs": "^23.0.4",
|
|
41
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
42
|
+
"@rollup/plugin-terser": "^0.4.3",
|
|
43
|
+
"ava": "^4.3.3",
|
|
44
|
+
"c8": "^8.0.0",
|
|
45
|
+
"rollup": "^2.79.1",
|
|
46
|
+
"rollup-plugin-banner": "^0.2.1",
|
|
47
|
+
"rollup-plugin-version-injector": "^1.3.3"
|
|
36
48
|
},
|
|
37
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "3656d36ed9cd738ab884e86aae5a2ce08d52adf7"
|
|
38
50
|
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import banner from 'rollup-plugin-banner'
|
|
2
|
+
import commonjs from '@rollup/plugin-commonjs'
|
|
3
|
+
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
|
4
|
+
import versionInjector from 'rollup-plugin-version-injector'
|
|
5
|
+
import terser from '@rollup/plugin-terser'
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
input: 'src/index.js',
|
|
9
|
+
|
|
10
|
+
output: [
|
|
11
|
+
{
|
|
12
|
+
file: 'dist/jscad-x3d-deserializer.min.js',
|
|
13
|
+
format: 'umd',
|
|
14
|
+
name: 'jscadX3dDeserializer'
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
file: 'dist/jscad-x3d-deserializer.es.js',
|
|
18
|
+
format: 'es'
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
|
|
22
|
+
plugins: [
|
|
23
|
+
commonjs(),
|
|
24
|
+
nodeResolve(),
|
|
25
|
+
banner('<%= pkg.description %>\n@module <%= pkg.name %>\n@version <%= pkg.version %>\n@license <%= pkg.license %>'),
|
|
26
|
+
versionInjector({ injectInComments: { fileRegexp: /\.(html)$/ }, logLevel: 'warn' }),
|
|
27
|
+
terser({ compress: { module: true }, mangle: false, format: { comments: 'some'} })
|
|
28
|
+
]
|
|
29
|
+
}
|
package/src/constants.js
CHANGED
package/src/createTransform.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { mat4, vec3 } from '@jscad/modeling'
|
|
2
2
|
|
|
3
|
-
const createTransform = (center, rotation, scale, scaleOrientation, translation) => {
|
|
4
|
-
const matrix =
|
|
5
|
-
const temp =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
export const createTransform = (center, rotation, scale, scaleOrientation, translation) => {
|
|
4
|
+
const matrix = mat4.create()
|
|
5
|
+
const temp = mat4.create()
|
|
6
|
+
mat4.multiply(matrix, matrix, mat4.fromTranslation(temp, translation))
|
|
7
|
+
mat4.multiply(matrix, matrix, mat4.fromTranslation(temp, center))
|
|
8
|
+
mat4.multiply(matrix, matrix, mat4.fromRotation(temp, rotation[3], rotation))
|
|
9
|
+
mat4.multiply(matrix, matrix, mat4.fromRotation(temp, scaleOrientation[3], scaleOrientation))
|
|
10
|
+
mat4.multiply(matrix, matrix, mat4.fromScaling(temp, scale))
|
|
11
|
+
mat4.multiply(matrix, matrix, mat4.fromRotation(temp, scaleOrientation[3], vec3.negate(vec3.create(), scaleOrientation)))
|
|
12
|
+
mat4.multiply(matrix, matrix, mat4.fromTranslation(temp, vec3.negate(vec3.create(), center)))
|
|
13
13
|
|
|
14
14
|
return matrix
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
module.exports = createTransform
|
package/src/extrudeX3D.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { mat4, vec3, utils } = maths
|
|
4
|
-
const { extrudeFromSlices, slice } = extrusions
|
|
1
|
+
import { extrudeFromSlices, geom2, mat4, poly2, slice, vec3 } from '@jscad/modeling'
|
|
5
2
|
|
|
6
3
|
const calculateYaxes = (spine) => {
|
|
7
4
|
const slength = spine.length
|
|
@@ -128,12 +125,11 @@ const rotationMatrixFromSCP = (out, xaxis, yaxis, zaxis) => {
|
|
|
128
125
|
return out
|
|
129
126
|
}
|
|
130
127
|
|
|
131
|
-
const extrudeX3D = (x3dshape) => {
|
|
132
|
-
// console.log(x3dshape)
|
|
128
|
+
export const extrudeX3D = (x3dshape) => {
|
|
133
129
|
let { beginCap, endCap, crossSection, orientations, scales, spine } = Object.assign({}, x3dshape)
|
|
134
130
|
|
|
135
131
|
// orientate the crossection for extruding
|
|
136
|
-
if (
|
|
132
|
+
if (poly2.measureArea(poly2.create(crossSection)) < 0) crossSection.reverse()
|
|
137
133
|
|
|
138
134
|
// complete scales if necessary
|
|
139
135
|
if (scales.length === 1) {
|
|
@@ -151,16 +147,13 @@ const extrudeX3D = (x3dshape) => {
|
|
|
151
147
|
}
|
|
152
148
|
|
|
153
149
|
// Create the initial slice
|
|
154
|
-
const initialShape =
|
|
155
|
-
const initialSlice = slice.
|
|
150
|
+
const initialShape = geom2.create([crossSection])
|
|
151
|
+
const initialSlice = slice.fromGeom2(initialShape)
|
|
156
152
|
|
|
157
153
|
// Calculate SCP values
|
|
158
154
|
let yaxes = calculateYaxes(spine)
|
|
159
|
-
// console.log(yaxes)
|
|
160
155
|
let zaxes = calculateZaxes(spine)
|
|
161
|
-
// console.log(zaxes)
|
|
162
156
|
let xaxes = calculateXaxes(yaxes, zaxes)
|
|
163
|
-
// console.log(xaxes)
|
|
164
157
|
|
|
165
158
|
// initial Y=0 matrix
|
|
166
159
|
const y0direction = [0, 1, 0]
|
|
@@ -212,5 +205,3 @@ const extrudeX3D = (x3dshape) => {
|
|
|
212
205
|
}
|
|
213
206
|
}, initialSlice)
|
|
214
207
|
}
|
|
215
|
-
|
|
216
|
-
module.exports = extrudeX3D
|
package/src/index.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/*
|
|
2
|
-
## License
|
|
3
|
-
|
|
4
|
-
Copyright (c) 2021 Z3 Development https://github.com/z3dev
|
|
5
|
-
|
|
6
|
-
All code released under MIT license
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
1
|
// //////////////////////////////////////////
|
|
10
2
|
//
|
|
11
3
|
// Extensible 3D (X3D) Graphics is the open standard for publishing, viewing, printing and archiving interactive 3D models
|
|
@@ -21,10 +13,10 @@ All code released under MIT license
|
|
|
21
13
|
* const { deserializer, extension } = require('@jscad/x3d-deserializer')
|
|
22
14
|
*/
|
|
23
15
|
|
|
24
|
-
|
|
16
|
+
import { translate } from './translate.js'
|
|
17
|
+
import { instantiate } from './instantiate.js'
|
|
25
18
|
|
|
26
|
-
const
|
|
27
|
-
const instantiate = require('./instantiate')
|
|
19
|
+
const version = '[VI]{version}[/VI]' // version is injected by rollup
|
|
28
20
|
|
|
29
21
|
/**
|
|
30
22
|
* Deserialize the given X3D source (XML Encoding) into either a script or an array of geometry
|
|
@@ -52,9 +44,9 @@ const deserialize = (options, input) => {
|
|
|
52
44
|
return options.output === 'script' ? translate(options, input) : instantiate(options, input)
|
|
53
45
|
}
|
|
54
46
|
|
|
55
|
-
const
|
|
47
|
+
const mimeType = 'model/x3d+xml'
|
|
56
48
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
export {
|
|
50
|
+
mimeType,
|
|
51
|
+
deserialize
|
|
60
52
|
}
|
package/src/instantiate.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { flatten } from '@jscad/array-utils'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import { parse } from './parse.js'
|
|
4
|
+
import { instantiateDefinitions } from './instantiateDefinitions.js'
|
|
5
|
+
import { x3dTypes } from './objects.js'
|
|
6
6
|
|
|
7
|
-
const instantiate = (options, src) => {
|
|
7
|
+
export const instantiate = (options, src) => {
|
|
8
8
|
const defaults = {
|
|
9
|
-
pxPmm: require('./constants').pxPmm
|
|
10
9
|
}
|
|
11
10
|
options = Object.assign({}, defaults, options)
|
|
12
|
-
const { pxPmm } = options
|
|
13
11
|
|
|
14
12
|
options && options.statusCallback && options.statusCallback({ progress: 0 })
|
|
15
13
|
|
|
16
14
|
// parse the X3D source
|
|
17
|
-
const { x3dObj } = parse(src
|
|
15
|
+
const { x3dObj } = parse(src)
|
|
18
16
|
|
|
19
17
|
if (x3dObj.definition !== x3dTypes.X3D || (!x3dObj.objects)) throw new Error('X3D malformed')
|
|
20
18
|
if (x3dObj.objects.length < 1 || x3dObj.objects[0].definition !== x3dTypes.SCENE) throw new Error('X3D did not define a SCENE')
|
|
@@ -32,5 +30,3 @@ const instantiate = (options, src) => {
|
|
|
32
30
|
|
|
33
31
|
return geometries
|
|
34
32
|
}
|
|
35
|
-
|
|
36
|
-
module.exports = instantiate
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { colorize, transform } from '@jscad/modeling'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { createTransform } from './createTransform.js'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { x3dTypes } from './objects.js'
|
|
6
|
+
import { findColor } from './translateHelpers.js'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import { instantiatePrimitive } from './instantiatePrimitive.js'
|
|
9
|
+
import { instantiateLine } from './instantiateLine.js'
|
|
10
|
+
import { instantiateMesh } from './instantiateMesh.js'
|
|
11
11
|
|
|
12
12
|
const instantiatedList = new Map()
|
|
13
13
|
|
|
@@ -21,7 +21,7 @@ const instantiateTransform = (options, object) => {
|
|
|
21
21
|
|
|
22
22
|
return geometries.map((geometry) => {
|
|
23
23
|
const color = geometry.color
|
|
24
|
-
geometry =
|
|
24
|
+
geometry = transform(matrix, geometry)
|
|
25
25
|
if (color) geometry.color = color
|
|
26
26
|
return geometry
|
|
27
27
|
})
|
|
@@ -38,7 +38,7 @@ const instantiateShape = (options, object) => {
|
|
|
38
38
|
if (!geometry) geometry = null
|
|
39
39
|
|
|
40
40
|
if (geometry && color) {
|
|
41
|
-
geometry =
|
|
41
|
+
geometry = colorize(color, geometry)
|
|
42
42
|
}
|
|
43
43
|
return geometry
|
|
44
44
|
}
|
|
@@ -69,12 +69,10 @@ const instantiateDefinition = (options, object) => {
|
|
|
69
69
|
return geometry
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
const instantiateDefinitions = (options, objects) => {
|
|
72
|
+
export const instantiateDefinitions = (options, objects) => {
|
|
73
73
|
const geometries = objects.map((object) => instantiateDefinition(options, object)).filter((g) => g != null)
|
|
74
74
|
|
|
75
75
|
instantiatedList.clear()
|
|
76
76
|
|
|
77
77
|
return geometries
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
module.exports = instantiateDefinitions
|
package/src/instantiateLine.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { colorize, line } from '@jscad/modeling'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { createColors, findNode } from './translateHelpers.js'
|
|
4
|
+
import { x3dTypes } from './objects.js'
|
|
5
5
|
|
|
6
|
-
const convertLine = (options, objects) => {
|
|
6
|
+
export const convertLine = (options, objects) => {
|
|
7
7
|
let shape = findNode(x3dTypes.INDEXEDLINESET, objects)
|
|
8
8
|
if (shape) {
|
|
9
9
|
const coordinate = findNode(x3dTypes.COORDINATE, shape.objects)
|
|
@@ -71,27 +71,22 @@ const convertLine = (options, objects) => {
|
|
|
71
71
|
return null
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
const instantiateLine = (options, objects) => {
|
|
74
|
+
export const instantiateLine = (options, objects) => {
|
|
75
75
|
let geometry
|
|
76
76
|
|
|
77
77
|
const components = convertLine(options, objects)
|
|
78
78
|
if (components) {
|
|
79
|
-
const { pointsSet,
|
|
79
|
+
const { pointsSet, segColors } = components
|
|
80
80
|
geometry = pointsSet.map((points, i) => {
|
|
81
|
-
let
|
|
82
|
-
if (
|
|
83
|
-
|
|
81
|
+
let l
|
|
82
|
+
if (segColors) {
|
|
83
|
+
l = colorize(segColors[i], line(points))
|
|
84
84
|
} else {
|
|
85
|
-
|
|
85
|
+
l = line(points)
|
|
86
86
|
}
|
|
87
|
-
return
|
|
87
|
+
return l
|
|
88
88
|
})
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
return geometry
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
module.exports = {
|
|
95
|
-
convertLine,
|
|
96
|
-
instantiateLine
|
|
97
|
-
}
|
package/src/instantiateMesh.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { polyhedron } from '@jscad/modeling'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { x3dTypes } from './objects.js'
|
|
4
|
+
import { findNode, createColors } from './translateHelpers.js'
|
|
5
5
|
|
|
6
|
-
const convertMesh = (options, objects) => {
|
|
6
|
+
export const convertMesh = (options, objects) => {
|
|
7
7
|
let shape = findNode(x3dTypes.TRIANGLESET, objects)
|
|
8
8
|
if (shape) {
|
|
9
9
|
const coordinate = findNode(x3dTypes.COORDINATE, shape.objects)
|
|
@@ -277,17 +277,12 @@ const convertMesh = (options, objects) => {
|
|
|
277
277
|
return null
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
const instantiateMesh = (options, objects) => {
|
|
280
|
+
export const instantiateMesh = (options, objects) => {
|
|
281
281
|
let geometry
|
|
282
282
|
|
|
283
283
|
const components = convertMesh(options, objects)
|
|
284
284
|
if (components) {
|
|
285
|
-
geometry =
|
|
285
|
+
geometry = polyhedron(components)
|
|
286
286
|
}
|
|
287
287
|
return geometry
|
|
288
288
|
}
|
|
289
|
-
|
|
290
|
-
module.exports = {
|
|
291
|
-
convertMesh,
|
|
292
|
-
instantiateMesh
|
|
293
|
-
}
|
|
@@ -1,24 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import {
|
|
2
|
+
arc,
|
|
3
|
+
circle,
|
|
4
|
+
cuboid,
|
|
5
|
+
cylinder,
|
|
6
|
+
cylinderElliptic,
|
|
7
|
+
geom2,
|
|
8
|
+
line,
|
|
9
|
+
path2,
|
|
10
|
+
rectangle,
|
|
11
|
+
rotateX,
|
|
12
|
+
sphere,
|
|
13
|
+
subtract
|
|
14
|
+
} from '@jscad/modeling'
|
|
15
|
+
|
|
16
|
+
import { x3dTypes } from './objects.js'
|
|
17
|
+
import { findNode } from './translateHelpers.js'
|
|
18
|
+
|
|
19
|
+
import { extrudeX3D } from './extrudeX3D.js'
|
|
20
|
+
|
|
21
|
+
export const instantiatePrimitive = (options, objects) => {
|
|
9
22
|
let geometry
|
|
10
23
|
|
|
11
24
|
// 3D primitives
|
|
12
25
|
|
|
13
26
|
let object = findNode(x3dTypes.BOX, objects)
|
|
14
27
|
if (object) {
|
|
15
|
-
geometry =
|
|
28
|
+
geometry = cuboid({ size: object.size })
|
|
16
29
|
return geometry
|
|
17
30
|
}
|
|
18
31
|
|
|
19
32
|
object = findNode(x3dTypes.CONE, objects)
|
|
20
33
|
if (object) {
|
|
21
|
-
geometry =
|
|
34
|
+
geometry = rotateX(-Math.PI / 2, cylinderElliptic({
|
|
22
35
|
startRadius: [object.bottomRadius, object.bottomRadius],
|
|
23
36
|
height: object.height,
|
|
24
37
|
segments: object.subdivision,
|
|
@@ -29,7 +42,7 @@ const instantiatePrimitive = (options, objects) => {
|
|
|
29
42
|
|
|
30
43
|
object = findNode(x3dTypes.CYLINDER, objects)
|
|
31
44
|
if (object) {
|
|
32
|
-
geometry =
|
|
45
|
+
geometry = rotateX(-Math.PI / 2, cylinder({
|
|
33
46
|
radius: object.radius,
|
|
34
47
|
height: object.height,
|
|
35
48
|
segments: object.subdivision
|
|
@@ -39,7 +52,7 @@ const instantiatePrimitive = (options, objects) => {
|
|
|
39
52
|
|
|
40
53
|
object = findNode(x3dTypes.SPHERE, objects)
|
|
41
54
|
if (object) {
|
|
42
|
-
geometry =
|
|
55
|
+
geometry = sphere({ radius: object.radius, segments: object.subdivision })
|
|
43
56
|
return geometry
|
|
44
57
|
}
|
|
45
58
|
|
|
@@ -53,18 +66,18 @@ const instantiatePrimitive = (options, objects) => {
|
|
|
53
66
|
|
|
54
67
|
object = findNode(x3dTypes.ARC2D, objects)
|
|
55
68
|
if (object) {
|
|
56
|
-
geometry =
|
|
69
|
+
geometry = arc({ radius: object.radius, startAngle: object.startAngle, endAngle: object.endAngle, segments: object.subdivision })
|
|
57
70
|
return geometry
|
|
58
71
|
}
|
|
59
72
|
|
|
60
73
|
object = findNode(x3dTypes.ARCCLOSE2D, objects)
|
|
61
74
|
if (object) {
|
|
62
75
|
if (object.closureType === 'PIE') {
|
|
63
|
-
geometry =
|
|
76
|
+
geometry = circle({ radius: object.radius, startAngle: object.startAngle, endAngle: object.endAngle, segments: object.subdivision })
|
|
64
77
|
} else {
|
|
65
|
-
geometry =
|
|
66
|
-
|
|
67
|
-
)))
|
|
78
|
+
geometry = geom2.create([path2.toPoints(path2.close(
|
|
79
|
+
arc({ radius: object.radius, startAngle: object.startAngle, endAngle: object.endAngle, segments: object.subdivision })
|
|
80
|
+
))])
|
|
68
81
|
}
|
|
69
82
|
return geometry
|
|
70
83
|
}
|
|
@@ -72,19 +85,19 @@ const instantiatePrimitive = (options, objects) => {
|
|
|
72
85
|
object = findNode(x3dTypes.CIRCLE2D, objects)
|
|
73
86
|
if (object) {
|
|
74
87
|
// NOTE: X3D circles are really closed arcs (lines)
|
|
75
|
-
geometry =
|
|
88
|
+
geometry = arc({ radius: object.radius, segments: object.subdivision })
|
|
76
89
|
return geometry
|
|
77
90
|
}
|
|
78
91
|
|
|
79
92
|
object = findNode(x3dTypes.DISK2D, objects)
|
|
80
93
|
if (object) {
|
|
81
94
|
if (object.innerRadius === object.outerRadius) {
|
|
82
|
-
geometry =
|
|
95
|
+
geometry = arc({ radius: object.outerRadius, segments: object.subdivision })
|
|
83
96
|
} else {
|
|
84
97
|
if (object.innerRadius === 0) {
|
|
85
|
-
geometry =
|
|
98
|
+
geometry = circle({ radius: object.outerRadius, segments: object.subdivision })
|
|
86
99
|
} else {
|
|
87
|
-
geometry =
|
|
100
|
+
geometry = subtract(circle({ radius: object.outerRadius, segments: object.subdivision }), circle({ radius: object.innerRadius, segments: object.subdivision }))
|
|
88
101
|
}
|
|
89
102
|
}
|
|
90
103
|
return geometry
|
|
@@ -92,13 +105,13 @@ const instantiatePrimitive = (options, objects) => {
|
|
|
92
105
|
|
|
93
106
|
object = findNode(x3dTypes.POLYLINE2D, objects)
|
|
94
107
|
if (object) {
|
|
95
|
-
geometry =
|
|
108
|
+
geometry = line([object.lineSegments])
|
|
96
109
|
return geometry
|
|
97
110
|
}
|
|
98
111
|
|
|
99
112
|
object = findNode(x3dTypes.RECTANGLE2D, objects)
|
|
100
113
|
if (object) {
|
|
101
|
-
geometry =
|
|
114
|
+
geometry = rectangle({ size: object.size })
|
|
102
115
|
return geometry
|
|
103
116
|
}
|
|
104
117
|
|
|
@@ -109,12 +122,10 @@ const instantiatePrimitive = (options, objects) => {
|
|
|
109
122
|
const numfaces = Math.trunc(numpoints / 3)
|
|
110
123
|
geometry = []
|
|
111
124
|
for (let i = 0; i < numfaces; i = i + 3) {
|
|
112
|
-
geometry.push(
|
|
125
|
+
geometry.push(geom2.create([[vertices[i], vertices[i + 1], vertices[i + 2]]]))
|
|
113
126
|
}
|
|
114
127
|
return geometry
|
|
115
128
|
}
|
|
116
129
|
|
|
117
130
|
return geometry
|
|
118
131
|
}
|
|
119
|
-
|
|
120
|
-
module.exports = instantiatePrimitive
|