@shopware-ag/dive 1.12.0 → 1.12.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware-ag/dive",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "description": "Shopware Spatial Framework",
5
5
  "type": "module",
6
6
  "main": "./build/dive.cjs",
package/src/dive.ts CHANGED
@@ -9,7 +9,7 @@ import DIVEAxisCamera from "./axiscamera/AxisCamera.ts";
9
9
  import { getObjectDelta } from "./helper/getObjectDelta/getObjectDelta.ts";
10
10
 
11
11
  import type { Actions } from './com/actions/index.ts';
12
- import type { COMPov, COMLight, COMModel, COMEntity } from './com/types.ts';
12
+ import type { COMPov, COMLight, COMModel, COMEntity, COMPrimitive } from './com/types.ts';
13
13
  import { DIVEMath } from './math/index.ts';
14
14
  import { generateUUID } from "three/src/math/MathUtils";
15
15
  import { DIVEInfo } from "./info/Info.ts";
@@ -278,6 +278,7 @@ export type {
278
278
  COMPov,
279
279
  COMLight,
280
280
  COMModel,
281
+ COMPrimitive,
281
282
  COMEntity,
282
283
  };
283
284
 
@@ -1,4 +1,4 @@
1
- import { Box3, BoxGeometry, BufferGeometry, Color, CylinderGeometry, Float32BufferAttribute, Mesh, MeshStandardMaterial, Object3D, Raycaster, SphereGeometry, Uint32BufferAttribute, Vector3, Vector3Like } from 'three';
1
+ import { Box3, BoxGeometry, BufferGeometry, Color, ConeGeometry, CylinderGeometry, Mesh, MeshStandardMaterial, Object3D, Raycaster, SphereGeometry, Vector3, Vector3Like } from 'three';
2
2
  import DIVECommunication from '../com/Communication';
3
3
  import { PRODUCT_LAYER_MASK } from '../constant/VisibilityLayerMask';
4
4
  import { findSceneRecursive } from '../helper/findSceneRecursive/findSceneRecursive';
@@ -35,14 +35,13 @@ export class DIVEPrimitive extends Object3D implements DIVESelectable, DIVEMovea
35
35
  this._mesh.layers.mask = PRODUCT_LAYER_MASK;
36
36
  this._mesh.castShadow = true;
37
37
  this._mesh.receiveShadow = true;
38
+ this._mesh.material = new MeshStandardMaterial();
38
39
  this.add(this._mesh);
39
40
 
40
41
  this._boundingBox = new Box3();
41
42
  }
42
43
 
43
44
  public SetGeometry(geometry: COMGeometry): void {
44
- this.clear();
45
-
46
45
  this._mesh.geometry = this.assembleGeometry(geometry);
47
46
  this._boundingBox.setFromObject(this._mesh);
48
47
  }
@@ -68,16 +67,32 @@ export class DIVEPrimitive extends Object3D implements DIVESelectable, DIVEMovea
68
67
  public SetMaterial(material: Partial<COMMaterial>): void {
69
68
  const primitiveMaterial = this._mesh.material as MeshStandardMaterial;
70
69
 
70
+ if (material.vertexColors !== undefined) {
71
+ primitiveMaterial.vertexColors = material.vertexColors;
72
+ }
73
+
71
74
  // apply color if supplied
72
- if (material.color !== undefined) primitiveMaterial.color = new Color(material.color);
75
+ if (material.color !== undefined) {
76
+ primitiveMaterial.color = new Color(material.color);
77
+ }
73
78
 
74
79
  // apply albedo map if supplied
75
- if (material.map !== undefined) primitiveMaterial.map = material.map;
80
+ if (material.map !== undefined) {
81
+ primitiveMaterial.map = material.map;
82
+ }
83
+
84
+ // apply normal map
85
+ if (material.normalMap !== undefined) {
86
+ primitiveMaterial.normalMap = material.normalMap;
87
+ }
76
88
 
77
89
  // set roughness value
78
90
  // if supplied, apply roughness map
79
91
  // if we applied a roughness map, set roughness to 1.0
80
- if (material.roughness !== undefined) primitiveMaterial.roughness = material.roughness;
92
+ if (material.roughness !== undefined) {
93
+ primitiveMaterial.roughness = material.roughness;
94
+ }
95
+
81
96
  if (material.roughnessMap !== undefined) {
82
97
  primitiveMaterial.roughnessMap = material.roughnessMap;
83
98
 
@@ -89,12 +104,15 @@ export class DIVEPrimitive extends Object3D implements DIVESelectable, DIVEMovea
89
104
  // set metalness value
90
105
  // if supplied, apply metalness map
91
106
  // if we applied a metalness map, set metalness to 1.0
92
- if (material.metalness !== undefined) primitiveMaterial.metalness = material.metalness;
107
+ if (material.metalness !== undefined) {
108
+ primitiveMaterial.metalness = material.metalness;
109
+ }
110
+
93
111
  if (material.metalnessMap !== undefined) {
94
112
  primitiveMaterial.metalnessMap = material.metalnessMap;
95
113
 
96
114
  if (primitiveMaterial.metalnessMap) {
97
- primitiveMaterial.metalness = 1.0;
115
+ primitiveMaterial.metalness = 0.0;
98
116
  }
99
117
  }
100
118
 
@@ -179,47 +197,44 @@ export class DIVEPrimitive extends Object3D implements DIVESelectable, DIVEMovea
179
197
  }
180
198
 
181
199
  private createCylinderGeometry(geometry: COMGeometry): BufferGeometry {
182
- return new CylinderGeometry(geometry.width * 2, geometry.width * 2, geometry.height, 64);
200
+ const geo = new CylinderGeometry(geometry.width / 2, geometry.width / 2, geometry.height, 64);
201
+ geo.translate(0, geometry.height / 2, 0);
202
+ return geo;
183
203
  }
184
204
 
185
205
  private createSphereGeometry(geometry: COMGeometry): BufferGeometry {
186
- return new SphereGeometry(geometry.width * 2, 64);
206
+ const geo = new SphereGeometry(geometry.width / 2, 256, 256);
207
+ return geo;
187
208
  }
188
209
 
189
210
  private createPyramidGeometry(geometry: COMGeometry): BufferGeometry {
190
- const geo = new BufferGeometry();
191
- const { width, height, depth } = geometry;
192
- geo.setAttribute('position', new Float32BufferAttribute([
193
- width / 2, 0, depth / 2, // right back
194
- width / 2, 0, -depth / 2, // right front
195
- -width / 2, 0, -depth / 2, // left front
196
- -width / 2, 0, depth / 2, // left back
197
- 0, height, 0, // top
198
- ], 3));
199
- geo.setIndex(new Uint32BufferAttribute([
200
- 1, 0, 4,
201
- 2, 1, 4,
202
- 3, 2, 4,
203
- 3, 0, 4,
204
- 0, 1, 2,
205
- 0, 2, 3,
206
- ], 1));
211
+ const geo = new ConeGeometry(geometry.width / 2, geometry.height, 4, 1, true);
212
+ geo.rotateY(Math.PI / 4);
213
+ geo.translate(0, geometry.height / 2, 0);
207
214
  return geo;
208
215
  }
209
216
 
210
217
  private createBoxGeometry(geometry: COMGeometry): BufferGeometry {
211
- return new BoxGeometry(geometry.width, geometry.height, geometry.depth);
218
+ const geo = new BoxGeometry(geometry.width, geometry.height, geometry.depth);
219
+ geo.translate(0, geometry.height / 2, 0);
220
+ return geo;
212
221
  }
213
222
 
214
223
  private createConeGeometry(geometry: COMGeometry): BufferGeometry {
215
- return new CylinderGeometry(0, geometry.width * 2, geometry.height, 64);
224
+ const geo = new ConeGeometry(geometry.width / 2, geometry.height, 256);
225
+ geo.translate(0, geometry.height / 2, 0);
226
+ return geo;
216
227
  }
217
228
 
218
229
  private createWallGeometry(geometry: COMGeometry): BufferGeometry {
219
- return new BoxGeometry(geometry.width, geometry.height, geometry.depth, 16);
230
+ const geo = new BoxGeometry(geometry.width, geometry.height, geometry.depth || 0.05, 16);
231
+ geo.translate(0, geometry.height / 2, 0);
232
+ return geo;
220
233
  }
221
234
 
222
235
  private createPlaneGeometry(geometry: COMGeometry): BufferGeometry {
223
- return new BoxGeometry(geometry.width, geometry.height, geometry.depth);
236
+ const geo = new BoxGeometry(geometry.width, geometry.height, geometry.depth);
237
+ geo.translate(0, geometry.height / 2, 0);
238
+ return geo;
224
239
  }
225
240
  }
@@ -139,25 +139,31 @@ jest.mock('three', () => {
139
139
  BufferGeometry: jest.fn(function () {
140
140
  this.setAttribute = jest.fn();
141
141
  this.setIndex = jest.fn();
142
+ this.translate = jest.fn();
142
143
  return this;
143
144
  }),
144
145
  CylinderGeometry: jest.fn(function () {
145
- return {};
146
+ this.translate = jest.fn();
147
+ return this;
146
148
  }),
147
149
  SphereGeometry: jest.fn(function () {
148
- return {};
150
+ this.translate = jest.fn();
151
+ return this;
149
152
  }),
150
153
  BoxGeometry: jest.fn(function () {
151
- return {};
154
+ this.translate = jest.fn();
155
+ return this;
152
156
  }),
153
157
  ConeGeometry: jest.fn(function () {
154
- return {};
158
+ this.rotateY = jest.fn();
159
+ this.translate = jest.fn();
160
+ return this;
155
161
  }),
156
162
  Float32BufferAttribute: jest.fn(function () {
157
- return {};
163
+ return this;
158
164
  }),
159
165
  Uint32BufferAttribute: jest.fn(function () {
160
- return {};
166
+ return this;
161
167
  }),
162
168
  MeshStandardMaterial: jest.fn(function () {
163
169
  this.color = {};
@@ -390,6 +396,13 @@ describe('dive/primitive/DIVEPrimitive', () => {
390
396
  } as COMGeometry;
391
397
  expect(() => primitive.SetGeometry(wall)).not.toThrow();
392
398
 
399
+ const wallWithoutDepth = {
400
+ name: 'wall',
401
+ width: 1,
402
+ height: 1.5,
403
+ } as COMGeometry;
404
+ expect(() => primitive.SetGeometry(wallWithoutDepth)).not.toThrow();
405
+
393
406
  // plane
394
407
  const plane = {
395
408
  name: 'plane',
@@ -407,27 +420,30 @@ describe('dive/primitive/DIVEPrimitive', () => {
407
420
  expect(() => primitive.SetMaterial({} as COMMaterial)).not.toThrow();
408
421
  expect(material).toBeDefined();
409
422
 
423
+
410
424
  expect(() => primitive.SetMaterial({
411
425
  color: 0xffffff,
412
426
  roughness: 0,
413
427
  metalness: 1,
414
428
  } as COMMaterial)).not.toThrow();
415
- expect(material.roughness).toBe(0);
416
- expect(material.roughnessMap).toBeUndefined();
417
- expect(material.metalness).toBe(1);
418
- expect(material.metalnessMap).toBeUndefined();
429
+ expect((material as MeshStandardMaterial).roughness).toBe(0);
430
+ expect((material as MeshStandardMaterial).roughnessMap).toBeUndefined();
431
+ expect((material as MeshStandardMaterial).metalness).toBe(1);
432
+ expect((material as MeshStandardMaterial).metalnessMap).toBeUndefined();
419
433
 
420
434
  expect(() => primitive.SetMaterial({
421
435
  color: 0xff00ff,
436
+ vertexColors: true,
422
437
  map: 'This_Is_A_Texture' as unknown as Texture,
438
+ normalMap: 'This_Is_A_Texture' as unknown as Texture,
423
439
  roughness: 0,
424
440
  roughnessMap: 'This_Is_A_Texture' as unknown as Texture,
425
441
  metalness: 1,
426
442
  metalnessMap: 'This_Is_A_Texture' as unknown as Texture,
427
443
  } as COMMaterial)).not.toThrow();
428
- expect(material.roughness).toBe(1);
429
- expect(material.roughnessMap).toBeDefined();
430
- expect(material.metalness).toBe(1);
431
- expect(material.metalnessMap).toBeDefined();
444
+ expect((material as MeshStandardMaterial).roughness).toBe(1);
445
+ expect((material as MeshStandardMaterial).roughnessMap).toBeDefined();
446
+ expect((material as MeshStandardMaterial).metalness).toBe(0);
447
+ expect((material as MeshStandardMaterial).metalnessMap).toBeDefined();
432
448
  });
433
449
  });