@jscad/x3d-serializer 2.4.10 → 3.0.1-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/package.json CHANGED
@@ -1,26 +1,31 @@
1
1
  {
2
2
  "name": "@jscad/x3d-serializer",
3
- "version": "2.4.10",
3
+ "version": "3.0.1-alpha.0",
4
4
  "description": "X3D Serializer for JSCAD",
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
+ "unpkg": "dist/jscad-x3d-serializer.min.js",
10
+ "module": "dist/jscad-x3d-serializer.es.js",
8
11
  "scripts": {
9
- "coverage": "nyc --all --reporter=html --reporter=text npm test",
10
- "test": "ava --verbose --timeout 2m './tests/*.test.js'"
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"
11
16
  },
12
17
  "contributors": [
13
18
  {
14
19
  "name": "Rene K. Mueller",
15
- "url": "http://renekmueller.com"
20
+ "url": "https://github.com/Spiritdude"
16
21
  },
17
22
  {
18
23
  "name": "z3dev",
19
- "url": "http://www.z3d.jp"
24
+ "url": "https://github.com/z3dev"
20
25
  },
21
26
  {
22
27
  "name": "Mark 'kaosat-dev' Moissette",
23
- "url": "http://kaosat.net"
28
+ "url": "https://github.com/kaosat-dev"
24
29
  }
25
30
  ],
26
31
  "keywords": [
@@ -32,13 +37,18 @@
32
37
  ],
33
38
  "license": "MIT",
34
39
  "dependencies": {
35
- "@jscad/array-utils": "2.1.4",
36
- "@jscad/modeling": "2.12.5",
37
- "onml": "1.3.0"
40
+ "@jscad/array-utils": "3.0.1-alpha.0",
41
+ "@jscad/io-utils": "^3.0.1-alpha.0",
42
+ "@jscad/modeling": "3.0.1-alpha.0",
43
+ "onml": "^1.3.0"
38
44
  },
39
45
  "devDependencies": {
40
- "ava": "3.15.0",
41
- "nyc": "15.1.0"
46
+ "@rollup/plugin-node-resolve": "^15.0.1",
47
+ "@rollup/plugin-terser": "^0.4.3",
48
+ "ava": "^4.3.3",
49
+ "c8": "^8.0.0",
50
+ "rollup": "^2.79.1",
51
+ "rollup-plugin-banner": "^0.2.1"
42
52
  },
43
- "gitHead": "d8010c4f1d70685404a510d604f8b6d5c362f93a"
53
+ "gitHead": "0660b5c1f1a5faf54d4cfae1cb85bb94182a8d32"
44
54
  }
@@ -0,0 +1,25 @@
1
+ import banner from 'rollup-plugin-banner'
2
+ import { nodeResolve } from '@rollup/plugin-node-resolve'
3
+ import terser from '@rollup/plugin-terser'
4
+
5
+ export default {
6
+ input: 'src/index.js',
7
+
8
+ output: [
9
+ {
10
+ file: 'dist/jscad-x3d-serializer.min.js',
11
+ format: 'umd',
12
+ name: 'jscadX3dSerializer'
13
+ },
14
+ {
15
+ file: 'dist/jscad-x3d-serializer.es.js',
16
+ format: 'es'
17
+ }
18
+ ],
19
+
20
+ plugins: [
21
+ nodeResolve(),
22
+ banner('<%= pkg.description %>\n@module <%= pkg.name %>\n@version <%= pkg.version %>\n@license <%= pkg.license %>'),
23
+ terser({ compress: { module: true }, mangle: false, format: { comments: 'some' } })
24
+ ]
25
+ }
package/src/index.js CHANGED
@@ -1,20 +1,8 @@
1
- /*
2
- JSCAD Object to X3D (XML) Format Serialization
3
-
4
- ## License
1
+ import { generalize, geom2, geom3, path2, poly2, poly3 } from '@jscad/modeling'
5
2
 
6
- Copyright (c) 2018-2022 JSCAD Organization https://github.com/jscad
3
+ import { flatten } from '@jscad/array-utils'
7
4
 
8
- All code released under MIT license
9
-
10
- Notes:
11
- 1) geom2 conversion to:
12
- Polyline2D with lineSegment and Color
13
- 2) geom3 conversion to:
14
- IndexedTriangleSet with Coordinates and Colors
15
- 3) path2 conversion to:
16
- Polyline2D with lineSegment and Color
17
- */
5
+ import { stringify } from '@jscad/io-utils'
18
6
 
19
7
  /**
20
8
  * Serializer of JSCAD geometries to X3D source data (XML).
@@ -31,17 +19,6 @@ Notes:
31
19
  * const { serializer, mimeType } = require('@jscad/x3d-serializer')
32
20
  */
33
21
 
34
- const { geometries, modifiers } = require('@jscad/modeling')
35
- const { geom2, geom3, path2, poly2, poly3 } = geometries
36
-
37
- const { flatten } = require('@jscad/array-utils')
38
-
39
- const stringify = require('onml/lib/stringify')
40
-
41
- // http://www.web3d.org/x3d/content/X3dTooltips.html
42
- // http://www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html#Meshes
43
- // https://x3dgraphics.com/examples/X3dForWebAuthors/Chapter13GeometryTrianglesQuadrilaterals/
44
-
45
22
  const mimeType = 'model/x3d+xml'
46
23
  const defNames = new Map()
47
24
 
@@ -120,7 +97,7 @@ const convertObjects = (objects, options) => {
120
97
 
121
98
  if (geom3.isA(object)) {
122
99
  // convert to triangles
123
- object = modifiers.generalize({ snap: true, triangulate: true }, object)
100
+ object = generalize({ snap: true, triangulate: true }, object)
124
101
  const polygons = geom3.toPolygons(object)
125
102
  if (polygons.length > 0) {
126
103
  shapes.push(convertGeom3(object, options))
@@ -190,7 +167,7 @@ const checkDefName = (defName) => {
190
167
  * Convert the given object (poly2) to X3D source
191
168
  */
192
169
  const convertPolyline2D = (object, options) => {
193
- const lineSegments = object.vertices.map((p) => `${p[0]} ${p[1]}`).join(' ')
170
+ const lineSegments = object.points.map((p) => `${p[0]} ${p[1]}`).join(' ')
194
171
  return ['Polyline2D', { lineSegments }]
195
172
  }
196
173
 
@@ -248,7 +225,7 @@ const convertToTriangles = (object, options) => {
248
225
  polygons.forEach((poly) => {
249
226
  const firstVertex = poly.vertices[0]
250
227
  for (let i = poly.vertices.length - 3; i >= 0; i--) {
251
- const triangle = poly3.fromPoints([
228
+ const triangle = poly3.create([
252
229
  firstVertex,
253
230
  poly.vertices[i + 1],
254
231
  poly.vertices[i + 2]
@@ -312,7 +289,7 @@ const polygons2coordinates = (polygons, options) => {
312
289
  return [indexList, pointList, colorList]
313
290
  }
314
291
 
315
- module.exports = {
316
- serialize,
317
- mimeType
292
+ export {
293
+ mimeType,
294
+ serialize
318
295
  }
@@ -1,13 +1,13 @@
1
- const test = require('ava')
1
+ import test from 'ava'
2
2
 
3
- const countOf = require('../../test/helpers/countOf')
3
+ import { countOf } from '../../test/helpers/countOf.js'
4
4
 
5
- const { colors, geometries, primitives } = require('@jscad/modeling')
5
+ import { colorize, geom2, rectangle } from '@jscad/modeling'
6
6
 
7
- const { serialize } = require('../src/index.js')
7
+ import { serialize } from '../src/index.js'
8
8
 
9
9
  test('serialize 2D geometry to X3D Polyline2D', (t) => {
10
- const shape1 = geometries.geom2.create()
10
+ const shape1 = geom2.create()
11
11
 
12
12
  let results = serialize({}, shape1)
13
13
  t.is(results.length, 1)
@@ -22,7 +22,7 @@ test('serialize 2D geometry to X3D Polyline2D', (t) => {
22
22
  t.is(countOf('Scene', obs), 2)
23
23
  t.is(countOf('Group', obs), 1)
24
24
 
25
- const shape2 = primitives.rectangle()
25
+ const shape2 = rectangle()
26
26
 
27
27
  results = serialize({ metadata: false }, shape2)
28
28
  t.is(results.length, 1)
@@ -39,7 +39,7 @@ test('serialize 2D geometry to X3D Polyline2D', (t) => {
39
39
  t.is(countOf('Shape', obs), 2)
40
40
  t.is(countOf('Polyline2D', obs), 1)
41
41
 
42
- const shape3 = colors.colorize([0, 0, 0], shape2)
42
+ const shape3 = colorize([0, 0, 0], shape2)
43
43
 
44
44
  results = serialize({ metadata: false }, shape3)
45
45
  t.is(results.length, 1)
@@ -1,15 +1,15 @@
1
- const test = require('ava')
1
+ import test from 'ava'
2
2
 
3
- const countOf = require('../../test/helpers/countOf')
3
+ import { countOf } from '../../test/helpers/countOf.js'
4
4
 
5
- const { colors, geometries, primitives, transforms } = require('@jscad/modeling')
5
+ import { center, colorize, cube, geom3 } from '@jscad/modeling'
6
6
 
7
- const serializer = require('../src/index.js')
7
+ import { serialize } from '../src/index.js'
8
8
 
9
9
  test('serialize 3D geometry to X3D IndexedTriangleSet', (t) => {
10
- const geom1 = geometries.geom3.create()
10
+ const g1 = geom3.create()
11
11
 
12
- let results = serializer.serialize({}, geom1)
12
+ let results = serialize({}, g1)
13
13
  t.is(results.length, 1)
14
14
 
15
15
  let obs = results[0]
@@ -21,9 +21,9 @@ test('serialize 3D geometry to X3D IndexedTriangleSet', (t) => {
21
21
  t.is(countOf('Created by JSCAD', obs), 1)
22
22
  t.is(countOf('Scene', obs), 2)
23
23
 
24
- const geom2 = primitives.cube()
24
+ const g2 = cube()
25
25
 
26
- results = serializer.serialize({ metadata: false }, geom2)
26
+ results = serialize({ metadata: false }, g2)
27
27
  t.is(results.length, 1)
28
28
 
29
29
  obs = results[0]
@@ -41,10 +41,10 @@ test('serialize 3D geometry to X3D IndexedTriangleSet', (t) => {
41
41
  t.is(countOf('Coordinate', obs), 1)
42
42
  t.is(countOf('Color', obs), 1)
43
43
 
44
- const geom3 = colors.colorize([0.5, 1, 0.5, 1.0], transforms.center({ relativeTo: [5, 5, 5] }, primitives.cube()))
45
- geom2.id = geom3.id = 'g23'
44
+ const g3 = colorize([0.5, 1, 0.5, 1.0], center({ relativeTo: [5, 5, 5] }, cube()))
45
+ g2.id = g3.id = 'g23'
46
46
 
47
- results = serializer.serialize({ metadata: false }, geom2, geom3)
47
+ results = serialize({ metadata: false }, g2, g3)
48
48
  t.is(results.length, 1)
49
49
 
50
50
  obs = results[0]
@@ -1,15 +1,15 @@
1
- const test = require('ava')
1
+ import test from 'ava'
2
2
 
3
- const countOf = require('../../test/helpers/countOf')
3
+ import { countOf } from '../../test/helpers/countOf.js'
4
4
 
5
- const { colors, geometries, primitives } = require('@jscad/modeling')
5
+ import { arc, colorize, path2 } from '@jscad/modeling'
6
6
 
7
- const { serialize } = require('../src/index.js')
7
+ import { serialize } from '../src/index.js'
8
8
 
9
9
  test('serialize 2D path to X3D Polyline2D', (t) => {
10
- const path1 = geometries.path2.create()
10
+ const p1 = path2.create()
11
11
 
12
- let results = serialize({}, path1)
12
+ let results = serialize({}, p1)
13
13
  t.is(results.length, 1)
14
14
 
15
15
  let obs = results[0]
@@ -20,9 +20,9 @@ test('serialize 2D path to X3D Polyline2D', (t) => {
20
20
  t.is(countOf('content', obs), 3)
21
21
  t.is(countOf('Created by JSCAD', obs), 1)
22
22
 
23
- const path2 = primitives.arc({ center: [5, 5], endAngle: 45, segments: 16 })
23
+ const p2 = arc({ center: [5, 5], endAngle: 45, segments: 16 })
24
24
 
25
- results = serialize({ metadata: false }, path2)
25
+ results = serialize({ metadata: false }, p2)
26
26
  t.is(results.length, 1)
27
27
 
28
28
  obs = results[0]
@@ -33,9 +33,9 @@ test('serialize 2D path to X3D Polyline2D', (t) => {
33
33
  t.is(countOf('Polyline2D', obs), 1)
34
34
  t.is(countOf('lineSegments', obs), 1)
35
35
 
36
- const path3 = colors.colorize([0, 0, 0], path2)
36
+ const p3 = colorize([0, 0, 0], p2)
37
37
 
38
- results = serialize({ metadata: false }, path2, path3)
38
+ results = serialize({ metadata: false }, p2, p3)
39
39
  t.is(results.length, 1)
40
40
 
41
41
  obs = results[0]