@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/build/dive.cjs +26 -22
- package/build/dive.cjs.map +1 -1
- package/build/dive.d.cts +5 -4
- package/build/dive.d.ts +5 -4
- package/build/dive.js +26 -22
- package/build/dive.js.map +1 -1
- package/package.json +1 -1
- package/src/com/types.ts +5 -4
- package/src/model/Model.ts +25 -18
- package/src/model/__test__/Model.test.ts +4 -3
- package/src/primitive/Primitive.ts +27 -12
- package/src/primitive/__test__/Primitive.test.ts +4 -3
package/package.json
CHANGED
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
|
|
43
|
+
roughnessMap: Texture | null;
|
|
43
44
|
metalness: number;
|
|
44
|
-
metalnessMap
|
|
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
|
|
53
|
+
material?: Partial<COMMaterial>;
|
|
53
54
|
};
|
|
54
55
|
|
|
55
56
|
export type COMEntity = COMPov | COMLight | COMModel | COMPrimitive;
|
package/src/model/Model.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
//
|
|
93
|
-
if
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
|
|
101
|
+
if (this._material.roughnessMap) {
|
|
102
|
+
this._material.roughness = 1.0;
|
|
103
|
+
}
|
|
98
104
|
}
|
|
99
105
|
|
|
100
|
-
//
|
|
101
|
-
if
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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: '
|
|
361
|
+
roughnessMap: 'This_Is_A_Texture' as unknown as Texture,
|
|
361
362
|
metalness: 1,
|
|
362
|
-
metalnessMap: '
|
|
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(
|
|
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
|
-
|
|
71
|
+
// apply color if supplied
|
|
72
|
+
if (material.color !== undefined) primitiveMaterial.color = new Color(material.color);
|
|
72
73
|
|
|
73
|
-
//
|
|
74
|
-
if (material.
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
|
|
84
|
+
if (primitiveMaterial.roughnessMap) {
|
|
85
|
+
primitiveMaterial.roughness = 1.0;
|
|
86
|
+
}
|
|
79
87
|
}
|
|
80
88
|
|
|
81
|
-
//
|
|
82
|
-
if
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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: '
|
|
424
|
+
roughnessMap: 'This_Is_A_Texture' as unknown as Texture,
|
|
424
425
|
metalness: 1,
|
|
425
|
-
metalnessMap: '
|
|
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(
|
|
430
|
+
expect(material.metalness).toBe(1);
|
|
430
431
|
expect(material.metalnessMap).toBeDefined();
|
|
431
432
|
});
|
|
432
433
|
});
|