@xort/cga 0.0.88 → 0.0.89

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.
@@ -140,7 +140,7 @@ exports.linkSide = linkSide;
140
140
  *
141
141
  */
142
142
  function linkSides(options) {
143
- options = __assign({ sealEnd: true, sealStart: true, shapeClosed: true, pathClosed: false, generateUV: true, autoIndex: true, axisPlane: trianglution_1.AxisPlane.XY }, options);
143
+ options = __assign({ sealEnd: false, sealStart: false, shapeClosed: true, pathClosed: false, generateUV: true, autoIndex: true, axisPlane: 'xyz' }, options);
144
144
  if (options.autoIndex)
145
145
  options.index = options.index || { index: 0 };
146
146
  var shapes = options.shapes;
@@ -169,7 +169,7 @@ function linkSides(options) {
169
169
  var startHoles = (0, common_1.clone)(holess[0]);
170
170
  allVertics.push(startHoles);
171
171
  }
172
- var startTris = (0, trianglution_1.triangulation)(orgShape, orgHoles, { feature: trianglution_1.AxisPlane.XYZ });
172
+ var startTris = (0, trianglution_1.triangulation)(orgShape, orgHoles, { feature: 'xy' });
173
173
  if (index) {
174
174
  startTris.forEach(function (v, i) {
175
175
  startTris[i] = v + (index === null || index === void 0 ? void 0 : index.index);
@@ -189,7 +189,7 @@ function linkSides(options) {
189
189
  var endHoles = (0, common_1.clone)((0, common_1.clone)(holess[holess.length - 1]));
190
190
  allVertics.push(endHoles);
191
191
  }
192
- var endTris = (0, trianglution_1.triangulation)(orgShape, orgHoles, { feature: trianglution_1.AxisPlane.XYZ });
192
+ var endTris = (0, trianglution_1.triangulation)(orgShape, orgHoles, { feature: 'xy' });
193
193
  if (index) {
194
194
  endTris.forEach(function (v, i) {
195
195
  endTris[i] = v + (index === null || index === void 0 ? void 0 : index.index);
@@ -252,7 +252,7 @@ function linkSides(options) {
252
252
  //前后纹理
253
253
  var sealUvs = [];
254
254
  switch (options.axisPlane) {
255
- case trianglution_1.AxisPlane.XY:
255
+ case 'xy':
256
256
  orgShape.map(function (e) {
257
257
  sealUvs.push(e.x, e.y);
258
258
  });
@@ -263,7 +263,7 @@ function linkSides(options) {
263
263
  });
264
264
  });
265
265
  break;
266
- case trianglution_1.AxisPlane.XZ:
266
+ case 'xz':
267
267
  orgShape.map(function (e) {
268
268
  sealUvs.push(e.x, e.z);
269
269
  });
@@ -274,7 +274,7 @@ function linkSides(options) {
274
274
  });
275
275
  });
276
276
  break;
277
- case trianglution_1.AxisPlane.YZ:
277
+ case 'yz':
278
278
  orgShape.map(function (e) {
279
279
  sealUvs.push(e.y, e.z);
280
280
  });
@@ -345,7 +345,7 @@ var _vec2 = (0, Vec3_1.v3)();
345
345
  *
346
346
  */
347
347
  function extrude(options) {
348
- options = __assign({ sealEnd: true, sealStart: true, shapeClosed: true, pathClosed: false, generateUV: true, autoIndex: true, axisPlane: trianglution_1.AxisPlane.XY, up: Vec3_1.Vec3.Up, smoothAngle: 30 * Math_1.RADIANS_PER_DEGREE, enableSmooth: false }, options);
348
+ options = __assign({ sealEnd: true, sealStart: true, shapeClosed: true, pathClosed: false, generateUV: true, autoIndex: true, axisPlane: 'xy', up: Vec3_1.Vec3.Up, smoothAngle: 30 * Math_1.RADIANS_PER_DEGREE, enableSmooth: false }, options);
349
349
  if (!vecs_1.vecs.isCCW(options.shape))
350
350
  options.shape.reverse();
351
351
  if (options.holes)
@@ -565,7 +565,7 @@ var EndType;
565
565
  * @param options
566
566
  */
567
567
  function extrudeNext(options) {
568
- options = __assign({ sealEnd: true, sealStart: true, shapeClosed: true, pathClosed: false, generateUV: true, autoIndex: true, axisPlane: trianglution_1.AxisPlane.XY, smoothAngle: 30 * Math_1.RADIANS_PER_DEGREE, enableSmooth: false }, options);
568
+ options = __assign({ sealEnd: true, sealStart: true, shapeClosed: true, pathClosed: false, generateUV: true, autoIndex: true, axisPlane: 'xy', smoothAngle: 30 * Math_1.RADIANS_PER_DEGREE, enableSmooth: false }, options);
569
569
  var path = options.shapeCenter ? (0, pointset_1.translate)(options.path, options.shapeCenter, false) : options.path;
570
570
  var shape = options.shape;
571
571
  (0, array_1.unique)(path, function (a, b) { return a.equals(b); });
@@ -1,10 +1,5 @@
1
1
  import { Vec3 } from '../math/Vec3';
2
- export declare enum AxisPlane {
3
- XY = "xy",
4
- XZ = "xz",
5
- YZ = "yz",
6
- XYZ = "xyz"
7
- }
2
+ export type AxisPlane = 'xy' | 'xz' | 'yz' | 'xyz';
8
3
  export interface ITriangulationOption {
9
4
  feature?: AxisPlane;
10
5
  dim?: number;
@@ -23,20 +23,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.triangulation = exports.AxisPlane = void 0;
26
+ exports.triangulation = void 0;
27
27
  var earcut_1 = __importDefault(require("earcut"));
28
28
  var Vec3_1 = require("../math/Vec3");
29
29
  var array_1 = require("../utils/array");
30
30
  var common_1 = require("./common");
31
31
  var Math_1 = require("../math/Math");
32
32
  var vecs_1 = require("../math/vecs");
33
- var AxisPlane;
34
- (function (AxisPlane) {
35
- AxisPlane["XY"] = "xy";
36
- AxisPlane["XZ"] = "xz";
37
- AxisPlane["YZ"] = "yz";
38
- AxisPlane["XYZ"] = "xyz";
39
- })(AxisPlane = exports.AxisPlane || (exports.AxisPlane = {}));
40
33
  /**
41
34
  * 三角剖分 earcut.js
42
35
  * @param {Array} boundary 边界
@@ -47,8 +40,8 @@ var AxisPlane;
47
40
  function triangulation(inboundary, holes, options) {
48
41
  if (holes === void 0) { holes = []; }
49
42
  if (options === void 0) { options = { normal: Vec3_1.Vec3.UnitZ }; }
50
- options = __assign({ feature: AxisPlane.XYZ, dim: 3 }, options);
51
- if (options.feature !== AxisPlane.XYZ)
43
+ options = __assign({ feature: 'xyz', dim: 3 }, options);
44
+ if (options.feature !== 'xyz')
52
45
  options.dim = 2;
53
46
  var boundary = null;
54
47
  var feature = options.feature;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.linksToGeometry = exports.linkToGeometry = exports.extrudeToGeometryBuffer = exports.toGeometryBuffer = void 0;
4
4
  var extrude_1 = require("../alg/extrude");
5
- var trianglution_1 = require("../alg/trianglution");
6
5
  var array_1 = require("../utils/array");
7
6
  var mesh_1 = require("../render/mesh");
8
7
  function toGeometryBuffer(geo) {
@@ -29,7 +28,7 @@ exports.extrudeToGeometryBuffer = extrudeToGeometryBuffer;
29
28
  * @param {*} material
30
29
  */
31
30
  function linkToGeometry(shape, shape1, axisPlane, shapeClose) {
32
- if (axisPlane === void 0) { axisPlane = trianglution_1.AxisPlane.XY; }
31
+ if (axisPlane === void 0) { axisPlane = 'xy'; }
33
32
  if (shapeClose === void 0) { shapeClose = false; }
34
33
  var geo = (0, extrude_1.linkSides)({ shapes: [shape, shape1], shapeClosed: shapeClose, orgShape: shape, axisPlane: axisPlane });
35
34
  var geometry = toGeometryBuffer(geo);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xort/cga",
3
- "version": "0.0.88",
3
+ "version": "0.0.89",
4
4
  "description": "Xtor Compute Geometry Algorithm Libary 计算几何算法库",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -166,10 +166,10 @@ export interface ILinkSideOptions {
166
166
  */
167
167
  export function linkSides(options: ILinkSideOptions): IGeometry {
168
168
  options = {
169
- sealEnd: true, sealStart: true, shapeClosed: true, pathClosed: false,
169
+ sealEnd: false, sealStart: false, shapeClosed: true, pathClosed: false,
170
170
  generateUV: true,
171
171
  autoIndex: true,
172
- axisPlane: AxisPlane.XY,
172
+ axisPlane: 'xyz',
173
173
  ...options
174
174
  }
175
175
 
@@ -211,7 +211,7 @@ export function linkSides(options: ILinkSideOptions): IGeometry {
211
211
  allVertics.push(startHoles)
212
212
  }
213
213
 
214
- var startTris = triangulation(orgShape, orgHoles, { feature: AxisPlane.XYZ });
214
+ var startTris = triangulation(orgShape, orgHoles, { feature: 'xy' });
215
215
  if (index) {
216
216
  startTris.forEach((v: number, i: number) => {
217
217
  startTris[i] = v + index?.index;
@@ -234,7 +234,7 @@ export function linkSides(options: ILinkSideOptions): IGeometry {
234
234
  var endHoles = clone(clone(holess[holess.length - 1]));
235
235
  allVertics.push(endHoles)
236
236
  }
237
- var endTris = triangulation(orgShape, orgHoles, { feature: AxisPlane.XYZ });
237
+ var endTris = triangulation(orgShape, orgHoles, { feature: 'xy' });
238
238
  if (index) {
239
239
  endTris.forEach((v: number, i: number) => {
240
240
  endTris[i] = v + index?.index;
@@ -307,7 +307,7 @@ export function linkSides(options: ILinkSideOptions): IGeometry {
307
307
  //前后纹理
308
308
  var sealUvs: any = []
309
309
  switch (options.axisPlane) {
310
- case AxisPlane.XY:
310
+ case 'xy':
311
311
  orgShape.map(e => {
312
312
  sealUvs.push(e.x, e.y)
313
313
  })
@@ -318,7 +318,7 @@ export function linkSides(options: ILinkSideOptions): IGeometry {
318
318
  })
319
319
  })
320
320
  break;
321
- case AxisPlane.XZ:
321
+ case 'xz':
322
322
  orgShape.map(e => {
323
323
  sealUvs.push(e.x, e.z)
324
324
  })
@@ -329,7 +329,7 @@ export function linkSides(options: ILinkSideOptions): IGeometry {
329
329
  })
330
330
  })
331
331
  break;
332
- case AxisPlane.YZ:
332
+ case 'yz':
333
333
  orgShape.map(e => {
334
334
  sealUvs.push(e.y, e.z)
335
335
  })
@@ -444,7 +444,7 @@ export function extrude(options: IExtrudeOptionsEx): IGeometry {
444
444
  sealEnd: true, sealStart: true, shapeClosed: true, pathClosed: false,
445
445
  generateUV: true,
446
446
  autoIndex: true,
447
- axisPlane: AxisPlane.XY,
447
+ axisPlane: 'xy',
448
448
  up: Vec3.Up,
449
449
  smoothAngle: 30 * RADIANS_PER_DEGREE,
450
450
  enableSmooth: false,
@@ -733,7 +733,7 @@ export function extrudeNext(options: IExtrudeOptionsNext) {
733
733
  sealEnd: true, sealStart: true, shapeClosed: true, pathClosed: false,
734
734
  generateUV: true,
735
735
  autoIndex: true,
736
- axisPlane: AxisPlane.XY,
736
+ axisPlane: 'xy',
737
737
  smoothAngle: 30 * RADIANS_PER_DEGREE,
738
738
  enableSmooth: false,
739
739
  ...options
@@ -5,12 +5,7 @@ import { clone, rotateByUnitVectors } from './common';
5
5
  import { delta4 } from '../math/Math';
6
6
  import { vecs } from '../math/vecs';
7
7
 
8
- export enum AxisPlane {
9
- XY = 'xy',
10
- XZ = 'xz',
11
- YZ = 'yz',
12
- XYZ = 'xyz',
13
- }
8
+ export type AxisPlane = 'xy' | 'xz' | 'yz' | 'xyz';
14
9
 
15
10
  export interface ITriangulationOption {
16
11
  feature?: AxisPlane;
@@ -26,8 +21,8 @@ export interface ITriangulationOption {
26
21
  * @returns {Array<Number>} 三角形索引数组
27
22
  */
28
23
  export function triangulation(inboundary: any, holes: any[] = [], options: ITriangulationOption = { normal: Vec3.UnitZ }) {
29
- options = { feature: AxisPlane.XYZ, dim: 3, ...options }
30
- if (options.feature !== AxisPlane.XYZ)
24
+ options = { feature: 'xyz', dim: 3, ...options }
25
+ if (options.feature !== 'xyz')
31
26
  options.dim = 2;
32
27
  let boundary = null;
33
28
  let feature = options.feature;
@@ -40,7 +40,7 @@ export function extrudeToGeometryBuffer(shape: ArrayList<Vec3>, arg_path: Array<
40
40
  * @param {*} options
41
41
  * @param {*} material
42
42
  */
43
- export function linkToGeometry(shape: Array<Vec3>, shape1: | Array<Vec3>, axisPlane: AxisPlane = AxisPlane.XY, shapeClose: boolean = false) {
43
+ export function linkToGeometry(shape: Array<Vec3>, shape1: | Array<Vec3>, axisPlane: AxisPlane = 'xy', shapeClose: boolean = false) {
44
44
  const geo: IGeometry = linkSides({ shapes: [shape, shape1], shapeClosed: shapeClose, orgShape: shape, axisPlane: axisPlane })
45
45
 
46
46
  const geometry = toGeometryBuffer(geo);