@shopware-ag/dive 1.10.0 → 1.11.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopware-ag/dive",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "Shopware Spatial Framework",
5
5
  "type": "module",
6
6
  "main": "./build/dive.cjs",
package/src/com/types.ts CHANGED
@@ -26,7 +26,7 @@ export type COMModel = COMBaseEntity & {
26
26
  rotation: Vector3Like;
27
27
  scale: Vector3Like;
28
28
  loaded: boolean;
29
- material?: COMMaterial;
29
+ material?: Partial<COMMaterial>;
30
30
  };
31
31
 
32
32
  export type COMGeometry = {
@@ -38,10 +38,11 @@ export type COMGeometry = {
38
38
 
39
39
  export type COMMaterial = {
40
40
  color: string | number;
41
+ map: Texture | null;
41
42
  roughness: number;
42
- roughnessMap?: Texture;
43
+ roughnessMap: Texture | null;
43
44
  metalness: number;
44
- metalnessMap?: Texture;
45
+ metalnessMap: Texture | null;
45
46
  }
46
47
 
47
48
  export type COMPrimitive = COMBaseEntity & {
@@ -49,7 +50,7 @@ export type COMPrimitive = COMBaseEntity & {
49
50
  rotation: Vector3Like;
50
51
  scale: Vector3Like;
51
52
  geometry: COMGeometry;
52
- material: COMMaterial;
53
+ material?: Partial<COMMaterial>;
53
54
  };
54
55
 
55
56
  export type COMEntity = COMPov | COMLight | COMModel | COMPrimitive;
@@ -79,37 +79,44 @@ export default class DIVEModel extends Object3D implements DIVESelectable, DIVEM
79
79
  });
80
80
  }
81
81
 
82
- public SetMaterial(material: COMMaterial): void {
83
- console.error('HERE', this._mesh);
84
-
82
+ public SetMaterial(material: Partial<COMMaterial>): void {
85
83
  // if there is no material, create a new one
86
84
  if (!this._material) {
87
85
  this._material = new MeshStandardMaterial();
88
86
  }
89
87
 
90
- this._material.color = new Color(material.color);
88
+ // apply color if supplied
89
+ if (material.color !== undefined) this._material.color = new Color(material.color);
90
+
91
+ // apply albedo map if supplied
92
+ if (material.map !== undefined) this._material.map = material.map;
91
93
 
92
- // if there is a roughness map, use it, otherwise use the roughness value
93
- if (material.roughnessMap) {
94
+ // set roughness value
95
+ // if supplied, apply roughness map
96
+ // if we applied a roughness map, set roughness to 1.0
97
+ if (material.roughness !== undefined) this._material.roughness = material.roughness;
98
+ if (material.roughnessMap !== undefined) {
94
99
  this._material.roughnessMap = material.roughnessMap;
95
- this._material.roughness = 1.0;
96
- } else {
97
- this._material.roughness = material.roughness;
100
+
101
+ if (this._material.roughnessMap) {
102
+ this._material.roughness = 1.0;
103
+ }
98
104
  }
99
105
 
100
- // if there is a metalness map, use it, otherwise use the metalness value
101
- if (material.metalnessMap) {
106
+ // set metalness value
107
+ // if supplied, apply metalness map
108
+ // if we applied a metalness map, set metalness to 1.0
109
+ if (material.metalness !== undefined) this._material.metalness = material.metalness;
110
+ if (material.metalnessMap !== undefined) {
102
111
  this._material.metalnessMap = material.metalnessMap;
103
- this._material.metalness = 0.0;
104
- } else {
105
- this._material.metalness = material.metalness;
112
+
113
+ if (this._material.metalnessMap) {
114
+ this._material.metalness = 1.0;
115
+ }
106
116
  }
107
117
 
108
118
  // if the mesh is already set, update the material
109
-
110
- if (this._mesh) {
111
- this._mesh.material = this._material;
112
- }
119
+ if (this._mesh) this._mesh.material = this._material;
113
120
  }
114
121
 
115
122
  public SetToWorldOrigin(): void {
@@ -356,14 +356,15 @@ describe('dive/model/DIVEModel', () => {
356
356
 
357
357
  expect(() => model.SetMaterial({
358
358
  color: 0xff00ff,
359
+ map: 'This_Is_A_Texture' as unknown as Texture,
359
360
  roughness: 0,
360
- roughnessMap: 'this is a Texture' as unknown as Texture,
361
+ roughnessMap: 'This_Is_A_Texture' as unknown as Texture,
361
362
  metalness: 1,
362
- metalnessMap: 'this is a Texture' as unknown as Texture,
363
+ metalnessMap: 'This_Is_A_Texture' as unknown as Texture,
363
364
  } as COMMaterial)).not.toThrow();
364
365
  expect((model['_material'] as MeshStandardMaterial).roughness).toBe(1);
365
366
  expect((model['_material'] as MeshStandardMaterial).roughnessMap).toBeDefined();
366
- expect((model['_material'] as MeshStandardMaterial).metalness).toBe(0);
367
+ expect((model['_material'] as MeshStandardMaterial).metalness).toBe(1);
367
368
  expect((model['_material'] as MeshStandardMaterial).metalnessMap).toBeDefined();
368
369
  });
369
370
 
@@ -65,26 +65,41 @@ export class DIVEPrimitive extends Object3D implements DIVESelectable, DIVEMovea
65
65
  });
66
66
  }
67
67
 
68
- public SetMaterial(material: COMMaterial): void {
68
+ public SetMaterial(material: Partial<COMMaterial>): void {
69
69
  const primitiveMaterial = this._mesh.material as MeshStandardMaterial;
70
70
 
71
- primitiveMaterial.color = new Color(material.color);
71
+ // apply color if supplied
72
+ if (material.color !== undefined) primitiveMaterial.color = new Color(material.color);
72
73
 
73
- // if there is a roughness map, use it, otherwise use the roughness value
74
- if (material.roughnessMap) {
74
+ // apply albedo map if supplied
75
+ if (material.map !== undefined) primitiveMaterial.map = material.map;
76
+
77
+ // set roughness value
78
+ // if supplied, apply roughness map
79
+ // if we applied a roughness map, set roughness to 1.0
80
+ if (material.roughness !== undefined) primitiveMaterial.roughness = material.roughness;
81
+ if (material.roughnessMap !== undefined) {
75
82
  primitiveMaterial.roughnessMap = material.roughnessMap;
76
- primitiveMaterial.roughness = 1.0;
77
- } else {
78
- primitiveMaterial.roughness = material.roughness;
83
+
84
+ if (primitiveMaterial.roughnessMap) {
85
+ primitiveMaterial.roughness = 1.0;
86
+ }
79
87
  }
80
88
 
81
- // if there is a metalness map, use it, otherwise use the metalness value
82
- if (material.metalnessMap) {
89
+ // set metalness value
90
+ // if supplied, apply metalness map
91
+ // if we applied a metalness map, set metalness to 1.0
92
+ if (material.metalness !== undefined) primitiveMaterial.metalness = material.metalness;
93
+ if (material.metalnessMap !== undefined) {
83
94
  primitiveMaterial.metalnessMap = material.metalnessMap;
84
- primitiveMaterial.metalness = 0.0;
85
- } else {
86
- primitiveMaterial.metalness = material.metalness;
95
+
96
+ if (primitiveMaterial.metalnessMap) {
97
+ primitiveMaterial.metalness = 1.0;
98
+ }
87
99
  }
100
+
101
+ // if the mesh is already set, update the material
102
+ if (this._mesh) this._mesh.material = primitiveMaterial;
88
103
  }
89
104
 
90
105
  public SetToWorldOrigin(): void {
@@ -419,14 +419,15 @@ describe('dive/primitive/DIVEPrimitive', () => {
419
419
 
420
420
  expect(() => primitive.SetMaterial({
421
421
  color: 0xff00ff,
422
+ map: 'This_Is_A_Texture' as unknown as Texture,
422
423
  roughness: 0,
423
- roughnessMap: 'this is a Texture' as unknown as Texture,
424
+ roughnessMap: 'This_Is_A_Texture' as unknown as Texture,
424
425
  metalness: 1,
425
- metalnessMap: 'this is a Texture' as unknown as Texture,
426
+ metalnessMap: 'This_Is_A_Texture' as unknown as Texture,
426
427
  } as COMMaterial)).not.toThrow();
427
428
  expect(material.roughness).toBe(1);
428
429
  expect(material.roughnessMap).toBeDefined();
429
- expect(material.metalness).toBe(0);
430
+ expect(material.metalness).toBe(1);
430
431
  expect(material.metalnessMap).toBeDefined();
431
432
  });
432
433
  });