@configura/babylon-view 2.0.0-alpha.9 → 2.0.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/.eslintrc.json +5 -18
- package/LICENSE +201 -201
- package/README.md +1 -1
- package/dist/animation/AnimatableObject.d.ts +8 -8
- package/dist/animation/AnimatableObject.js +3 -3
- package/dist/animation/animator/Animator.d.ts +33 -33
- package/dist/animation/animator/Animator.js +58 -58
- package/dist/animation/animator/AnimatorEasing.d.ts +16 -16
- package/dist/animation/animator/AnimatorEasing.js +31 -31
- package/dist/animation/animator/AnimatorEasingMatrix.d.ts +14 -14
- package/dist/animation/animator/AnimatorEasingMatrix.js +16 -16
- package/dist/animation/animator/AnimatorHighlight.d.ts +16 -16
- package/dist/animation/animator/AnimatorHighlight.js +32 -32
- package/dist/animation/animator/AnimatorPointToPoint.d.ts +8 -8
- package/dist/animation/animator/AnimatorPointToPoint.js +14 -14
- package/dist/animation/animator/AnimatorQueue.d.ts +13 -13
- package/dist/animation/animator/AnimatorQueue.js +57 -57
- package/dist/animation/animator/AnimatorScale.d.ts +8 -8
- package/dist/animation/animator/AnimatorScale.js +13 -13
- package/dist/animation/animator/AnimatorSpin.d.ts +10 -10
- package/dist/animation/animator/AnimatorSpin.js +13 -13
- package/dist/animation/animator/EasingFunctions.d.ts +35 -35
- package/dist/animation/animator/EasingFunctions.js +137 -137
- package/dist/animation/coordinator/Coordinator.d.ts +28 -28
- package/dist/animation/coordinator/Coordinator.js +53 -53
- package/dist/animation/coordinator/CoordinatorDropAndSpin.d.ts +22 -22
- package/dist/animation/coordinator/CoordinatorDropAndSpin.js +138 -138
- package/dist/animation/coordinator/CoordinatorIdentity.d.ts +11 -11
- package/dist/animation/coordinator/CoordinatorIdentity.js +14 -14
- package/dist/animation/coordinator/CoordinatorNodeQueues.d.ts +18 -18
- package/dist/animation/coordinator/CoordinatorNodeQueues.js +50 -50
- package/dist/animation/coordinator/CoordinatorPulse.d.ts +21 -21
- package/dist/animation/coordinator/CoordinatorPulse.js +47 -47
- package/dist/animation/coordinator/CoordinatorPulseBounce.d.ts +14 -14
- package/dist/animation/coordinator/CoordinatorPulseBounce.js +35 -35
- package/dist/animation/coordinator/CoordinatorPulseHighlight.d.ts +13 -13
- package/dist/animation/coordinator/CoordinatorPulseHighlight.js +29 -29
- package/dist/animation/coordinator/CoordinatorPulseInflate.d.ts +14 -14
- package/dist/animation/coordinator/CoordinatorPulseInflate.js +23 -23
- package/dist/camera/CameraCreator.d.ts +5 -5
- package/dist/camera/CameraCreator.js +4 -4
- package/dist/camera/CfgArcRotateCameraPointersInput.d.ts +26 -26
- package/dist/camera/CfgArcRotateCameraPointersInput.js +266 -266
- package/dist/camera/CfgOrbitalCamera.d.ts +76 -73
- package/dist/camera/CfgOrbitalCamera.js +281 -260
- package/dist/camera/CfgOrbitalCameraControlProps.d.ts +14 -11
- package/dist/camera/CfgOrbitalCameraControlProps.js +7 -6
- package/dist/camera/GradingApplier.d.ts +3 -3
- package/dist/camera/GradingApplier.js +48 -48
- package/dist/engine/EngineCreator.d.ts +3 -3
- package/dist/engine/EngineCreator.js +10 -10
- package/dist/geometry/CfgGeometry.d.ts +29 -29
- package/dist/geometry/CfgGeometry.js +146 -146
- package/dist/geometry/CfgMesh.d.ts +10 -10
- package/dist/geometry/CfgMesh.js +38 -38
- package/dist/geometry/geoSplitter.d.ts +8 -8
- package/dist/geometry/geoSplitter.js +192 -192
- package/dist/geometry/stretch/CfgMorphTarget.d.ts +15 -15
- package/dist/geometry/stretch/CfgMorphTarget.js +65 -65
- package/dist/geometry/stretch/CfgStretchData.d.ts +116 -116
- package/dist/geometry/stretch/CfgStretchData.js +350 -350
- package/dist/geometry/stretch/CfgStretchMorphGeometry.d.ts +16 -16
- package/dist/geometry/stretch/CfgStretchMorphGeometry.js +95 -95
- package/dist/index.d.ts +16 -16
- package/dist/index.js +16 -16
- package/dist/io/CfgHistoryToCameraConfConnector.d.ts +31 -29
- package/dist/io/CfgHistoryToCameraConfConnector.js +90 -80
- package/dist/io/CfgIOCameraConfConnector.d.ts +35 -35
- package/dist/io/CfgIOCameraConfConnector.js +81 -80
- package/dist/io/CfgObservableStateToCameraConfConnector.d.ts +10 -10
- package/dist/io/CfgObservableStateToCameraConfConnector.js +11 -11
- package/dist/io/CfgWindowMessageToCameraConfConnector.d.ts +10 -10
- package/dist/io/CfgWindowMessageToCameraConfConnector.js +11 -11
- package/dist/light/CfgDirectionalLight.d.ts +8 -8
- package/dist/light/CfgDirectionalLight.js +18 -18
- package/dist/light/CfgHemisphericLight.d.ts +7 -7
- package/dist/light/CfgHemisphericLight.js +17 -17
- package/dist/light/CfgPointLight.d.ts +8 -8
- package/dist/light/CfgPointLight.js +18 -18
- package/dist/light/DefaultLightRig.d.ts +19 -19
- package/dist/light/DefaultLightRig.js +77 -77
- package/dist/light/LightRigCreator.d.ts +9 -9
- package/dist/light/LightRigCreator.js +3 -3
- package/dist/material/CfgMaterial.d.ts +68 -68
- package/dist/material/CfgMaterial.js +482 -482
- package/dist/material/DummyMaterialCreator.d.ts +4 -4
- package/dist/material/DummyMaterialCreator.js +15 -15
- package/dist/material/material.d.ts +18 -18
- package/dist/material/material.js +128 -128
- package/dist/material/texture.d.ts +14 -14
- package/dist/material/texture.js +306 -306
- package/dist/nodes/CfgContentRootNode.d.ts +19 -19
- package/dist/nodes/CfgContentRootNode.js +75 -75
- package/dist/nodes/CfgDeferredMeshNode.d.ts +55 -55
- package/dist/nodes/CfgDeferredMeshNode.js +378 -378
- package/dist/nodes/CfgProductNode.d.ts +127 -127
- package/dist/nodes/CfgProductNode.js +598 -598
- package/dist/nodes/CfgSymNode.d.ts +50 -50
- package/dist/nodes/CfgSymNode.js +249 -249
- package/dist/nodes/CfgSymRootNode.d.ts +45 -45
- package/dist/nodes/CfgSymRootNode.js +229 -229
- package/dist/nodes/CfgTransformNode.d.ts +33 -33
- package/dist/nodes/CfgTransformNode.js +83 -83
- package/dist/scene/SceneCreator.d.ts +6 -6
- package/dist/scene/SceneCreator.js +22 -22
- package/dist/utilities/CfgBoundingBox.d.ts +21 -21
- package/dist/utilities/CfgBoundingBox.js +81 -81
- package/dist/utilities/anchor/anchor.d.ts +50 -50
- package/dist/utilities/anchor/anchor.js +133 -133
- package/dist/utilities/anchor/anchorMap.d.ts +20 -20
- package/dist/utilities/anchor/anchorMap.js +111 -111
- package/dist/utilities/utilities3D.d.ts +70 -70
- package/dist/utilities/utilities3D.js +265 -265
- package/dist/utilities/utilitiesColor.d.ts +18 -18
- package/dist/utilities/utilitiesColor.js +50 -50
- package/dist/utilities/utilitiesImage.d.ts +6 -6
- package/dist/utilities/utilitiesImage.js +107 -107
- package/dist/utilities/utilitiesSymRootIdentifier.d.ts +7 -7
- package/dist/utilities/utilitiesSymRootIdentifier.js +26 -26
- package/dist/view/BaseView.d.ts +78 -78
- package/dist/view/BaseView.js +303 -303
- package/dist/view/BaseViewConfiguration.d.ts +32 -32
- package/dist/view/BaseViewConfiguration.js +10 -10
- package/dist/view/RenderEnv.d.ts +43 -43
- package/dist/view/RenderEnv.js +7 -7
- package/dist/view/SingleProductDefaultCameraView.d.ts +38 -37
- package/dist/view/SingleProductDefaultCameraView.js +149 -145
- package/dist/view/SingleProductDefaultCameraViewConfiguration.d.ts +44 -42
- package/dist/view/SingleProductDefaultCameraViewConfiguration.js +11 -11
- package/dist/view/SingleProductView.d.ts +44 -44
- package/dist/view/SingleProductView.js +212 -212
- package/dist/view/SingleProductViewConfiguration.d.ts +32 -32
- package/dist/view/SingleProductViewConfiguration.js +19 -19
- package/package.json +5 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Scene } from "@babylonjs/core/scene.js";
|
|
2
|
-
import { CfgMaterial } from "./CfgMaterial.js";
|
|
3
|
-
export declare type DummyMaterialCreator = (scene: Scene, maxSimultaneousLights: number, color?: number) => CfgMaterial;
|
|
4
|
-
export declare function defaultDummyMaterialCreator(scene: Scene, maxSimultaneousLights: number, color?: number): CfgMaterial;
|
|
1
|
+
import { Scene } from "@babylonjs/core/scene.js";
|
|
2
|
+
import { CfgMaterial } from "./CfgMaterial.js";
|
|
3
|
+
export declare type DummyMaterialCreator = (scene: Scene, maxSimultaneousLights: number, color?: number) => CfgMaterial;
|
|
4
|
+
export declare function defaultDummyMaterialCreator(scene: Scene, maxSimultaneousLights: number, color?: number): CfgMaterial;
|
|
5
5
|
//# sourceMappingURL=DummyMaterialCreator.d.ts.map
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
|
2
|
-
import { toColor3 } from "../utilities/utilitiesColor.js";
|
|
3
|
-
import { CfgMaterial, makeMaterialDoubleSided } from "./CfgMaterial.js";
|
|
4
|
-
export function defaultDummyMaterialCreator(scene, maxSimultaneousLights, color) {
|
|
5
|
-
const material = new PBRMaterial("Dummy Material", scene);
|
|
6
|
-
material.albedoColor = toColor3(color === undefined ? 0xb5b5b5 : color).toLinearSpace();
|
|
7
|
-
material.roughness = 1;
|
|
8
|
-
// For a rather nice x-ray version during loading, enable the settings below
|
|
9
|
-
// material.alpha = 0.2;
|
|
10
|
-
// material.transparencyMode = PBRMaterial.PBRMATERIAL_ALPHABLEND;
|
|
11
|
-
// material.disableDepthWrite = true;
|
|
12
|
-
// material.separateCullingPass = true;
|
|
13
|
-
makeMaterialDoubleSided(material, true); // Double sided improved mesh compatibility
|
|
14
|
-
return new CfgMaterial(material, maxSimultaneousLights);
|
|
15
|
-
}
|
|
1
|
+
import { PBRMaterial } from "@babylonjs/core/Materials/PBR/pbrMaterial.js";
|
|
2
|
+
import { toColor3 } from "../utilities/utilitiesColor.js";
|
|
3
|
+
import { CfgMaterial, makeMaterialDoubleSided } from "./CfgMaterial.js";
|
|
4
|
+
export function defaultDummyMaterialCreator(scene, maxSimultaneousLights, color) {
|
|
5
|
+
const material = new PBRMaterial("Dummy Material", scene);
|
|
6
|
+
material.albedoColor = toColor3(color === undefined ? 0xb5b5b5 : color).toLinearSpace();
|
|
7
|
+
material.roughness = 1;
|
|
8
|
+
// For a rather nice x-ray version during loading, enable the settings below
|
|
9
|
+
// material.alpha = 0.2;
|
|
10
|
+
// material.transparencyMode = PBRMaterial.PBRMATERIAL_ALPHABLEND;
|
|
11
|
+
// material.disableDepthWrite = true;
|
|
12
|
+
// material.separateCullingPass = true;
|
|
13
|
+
makeMaterialDoubleSided(material, true); // Double sided improved mesh compatibility
|
|
14
|
+
return new CfgMaterial(material, maxSimultaneousLights);
|
|
15
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { CfgMtrlSourceWithMetaData } from "@configura/web-api";
|
|
2
|
-
import { GMaterial3D } from "@configura/web-core/dist/cm/core3D/GMaterial3D.js";
|
|
3
|
-
import { MultiGMaterial3D } from "@configura/web-core/dist/cm/core3D/MultiGMaterial3D.js";
|
|
4
|
-
import { LogObservable } from "@configura/web-utilities";
|
|
5
|
-
import { RenderEnv } from "../view/RenderEnv.js";
|
|
6
|
-
import { CfgMaterial } from "./CfgMaterial.js";
|
|
7
|
-
export declare type MaterialMetaData = {
|
|
8
|
-
sourcePath: string[];
|
|
9
|
-
logger: LogObservable;
|
|
10
|
-
multiGMaterial?: MultiGMaterial3D;
|
|
11
|
-
gMaterial?: GMaterial3D;
|
|
12
|
-
};
|
|
13
|
-
export declare type MaterialWithMetaData = {
|
|
14
|
-
material: CfgMaterial | undefined;
|
|
15
|
-
meta: MaterialMetaData;
|
|
16
|
-
};
|
|
17
|
-
export declare function mtrlSourceToCfgMaterial(meta: MaterialMetaData, mtrlSourceWithMetaData: CfgMtrlSourceWithMetaData, renderEnvironment: RenderEnv): Promise<CfgMaterial | undefined>;
|
|
18
|
-
export declare function gMaterialToCfgMaterial(meta: MaterialMetaData, renderEnvironment: RenderEnv, gMaterial: GMaterial3D): Promise<CfgMaterial | undefined>;
|
|
1
|
+
import { CfgMtrlSourceWithMetaData } from "@configura/web-api";
|
|
2
|
+
import { GMaterial3D } from "@configura/web-core/dist/cm/core3D/GMaterial3D.js";
|
|
3
|
+
import { MultiGMaterial3D } from "@configura/web-core/dist/cm/core3D/MultiGMaterial3D.js";
|
|
4
|
+
import { LogObservable } from "@configura/web-utilities";
|
|
5
|
+
import { RenderEnv } from "../view/RenderEnv.js";
|
|
6
|
+
import { CfgMaterial } from "./CfgMaterial.js";
|
|
7
|
+
export declare type MaterialMetaData = {
|
|
8
|
+
sourcePath: string[];
|
|
9
|
+
logger: LogObservable;
|
|
10
|
+
multiGMaterial?: MultiGMaterial3D;
|
|
11
|
+
gMaterial?: GMaterial3D;
|
|
12
|
+
};
|
|
13
|
+
export declare type MaterialWithMetaData = {
|
|
14
|
+
material: CfgMaterial | undefined;
|
|
15
|
+
meta: MaterialMetaData;
|
|
16
|
+
};
|
|
17
|
+
export declare function mtrlSourceToCfgMaterial(meta: MaterialMetaData, mtrlSourceWithMetaData: CfgMtrlSourceWithMetaData, renderEnvironment: RenderEnv): Promise<CfgMaterial | undefined>;
|
|
18
|
+
export declare function gMaterialToCfgMaterial(meta: MaterialMetaData, renderEnvironment: RenderEnv, gMaterial: GMaterial3D): Promise<CfgMaterial | undefined>;
|
|
19
19
|
//# sourceMappingURL=material.d.ts.map
|
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { CfgMtrlSourceBuffer, CfgMtrlSourceUrl, } from "@configura/web-api";
|
|
11
|
-
import { loadMaterialFromUrl, makeMaterialFromBuffer, } from "@configura/web-core/dist/cm/format/cmsym/components/SymGMaterial.js";
|
|
12
|
-
import { getFileExtension, LogObservable } from "@configura/web-utilities";
|
|
13
|
-
import { CfgMaterial } from "./CfgMaterial.js";
|
|
14
|
-
import { getTextures, loadTextureFromURL } from "./texture.js";
|
|
15
|
-
function copyMetaData(source, target) {
|
|
16
|
-
const { logger: sourceLogger, sourcePath: sourceSourcePath, multiGMaterial: sourceMultiGMaterial, gMaterial: sourceGMaterial, } = source;
|
|
17
|
-
const { logger: targetLogger, sourcePath: targetSourcePath } = target;
|
|
18
|
-
sourceLogger.accumulated.forEach((p) => targetLogger.addPrebaked(p));
|
|
19
|
-
targetSourcePath.push(...sourceSourcePath);
|
|
20
|
-
if (sourceMultiGMaterial !== undefined) {
|
|
21
|
-
target.multiGMaterial = sourceMultiGMaterial;
|
|
22
|
-
}
|
|
23
|
-
if (sourceGMaterial !== undefined) {
|
|
24
|
-
target.gMaterial = sourceGMaterial;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export function mtrlSourceToCfgMaterial(meta, mtrlSourceWithMetaData, renderEnvironment) {
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const mtrlSource = mtrlSourceWithMetaData.mtrl;
|
|
30
|
-
meta.sourcePath.push("mtrlSourceToCfgMaterial");
|
|
31
|
-
if (mtrlSource instanceof CfgMtrlSourceBuffer) {
|
|
32
|
-
return bufferToCfgMaterial(renderEnvironment, meta, mtrlSource);
|
|
33
|
-
}
|
|
34
|
-
if (mtrlSource instanceof CfgMtrlSourceUrl) {
|
|
35
|
-
return mtrlSourceUrlToCachedCfgMaterial(meta, renderEnvironment, mtrlSource);
|
|
36
|
-
}
|
|
37
|
-
throw meta.logger.errorAsObject("Unsupported mtrlSource");
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
function mtrlSourceUrlToCachedCfgMaterial(meta, renderEnvironment, mtrl) {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const url = mtrl.url;
|
|
43
|
-
meta.sourcePath.push("mtrlSourceUrlToCachedCfgMaterial");
|
|
44
|
-
const materialWithMetaData = yield renderEnvironment.materialCache.get(url, () => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const innerMeta = {
|
|
46
|
-
logger: new LogObservable(),
|
|
47
|
-
sourcePath: [],
|
|
48
|
-
};
|
|
49
|
-
const result = {
|
|
50
|
-
material: undefined,
|
|
51
|
-
meta: innerMeta,
|
|
52
|
-
};
|
|
53
|
-
innerMeta.sourcePath.push("cache_url");
|
|
54
|
-
if (!url.startsWith("http")) {
|
|
55
|
-
innerMeta.logger.warn("BAD MTRL URL: ", url);
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
if (getFileExtension(url) !== "gm") {
|
|
59
|
-
const texture = yield loadTextureFromURL(url, renderEnvironment);
|
|
60
|
-
innerMeta.sourcePath.push("image");
|
|
61
|
-
result.material = CfgMaterial.makeFromTexture(renderEnvironment, texture, innerMeta.sourcePath);
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
const multiGMaterial = yield loadMaterialFromUrl(innerMeta.logger, url, renderEnvironment.dexManager);
|
|
65
|
-
innerMeta.sourcePath.push("gm");
|
|
66
|
-
result.material = yield multiGToCfgMaterial(innerMeta, renderEnvironment, multiGMaterial);
|
|
67
|
-
return result;
|
|
68
|
-
}));
|
|
69
|
-
copyMetaData(materialWithMetaData.meta, meta);
|
|
70
|
-
return materialWithMetaData.material;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
function bufferToCfgMaterial(renderEnvironment, meta, mtrl) {
|
|
74
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
meta.sourcePath.push("bufferToCfgMaterial");
|
|
76
|
-
const fileName = mtrl.fileName;
|
|
77
|
-
const buffer = mtrl.buffer;
|
|
78
|
-
const fileExtension = getFileExtension(fileName);
|
|
79
|
-
if (fileExtension !== "gm") {
|
|
80
|
-
if (fileExtension !== "jpg" && fileExtension !== "jpeg" && fileExtension !== "png") {
|
|
81
|
-
throw meta.logger.errorAsObject("Unsupported file type");
|
|
82
|
-
}
|
|
83
|
-
meta.sourcePath.push("image");
|
|
84
|
-
const texture = yield loadTextureFromURL(`data:image/${fileExtension};base64,${btoa(String.fromCharCode(...new Uint8Array(buffer)))}`, renderEnvironment);
|
|
85
|
-
return CfgMaterial.makeFromTexture(renderEnvironment, texture, meta.sourcePath);
|
|
86
|
-
}
|
|
87
|
-
const multiGMaterial = makeMaterialFromBuffer(meta.logger, mtrl.buffer, renderEnvironment.dexManager);
|
|
88
|
-
meta.sourcePath.push("gm");
|
|
89
|
-
return multiGToCfgMaterial(meta, renderEnvironment, multiGMaterial);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
export function gMaterialToCfgMaterial(meta, renderEnvironment, gMaterial) {
|
|
93
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
meta.sourcePath.push("gMaterialToCfgMaterial");
|
|
95
|
-
const withMetaData = yield renderEnvironment.materialCache.get(gMaterial, () => __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
const innerMeta = {
|
|
97
|
-
logger: new LogObservable(),
|
|
98
|
-
sourcePath: [],
|
|
99
|
-
};
|
|
100
|
-
innerMeta.sourcePath.push("cache_gMaterial");
|
|
101
|
-
innerMeta.gMaterial = gMaterial;
|
|
102
|
-
const textures = yield getTextures(innerMeta.logger, renderEnvironment, gMaterial);
|
|
103
|
-
const material = CfgMaterial.makeFromGm(renderEnvironment, innerMeta, gMaterial, textures);
|
|
104
|
-
return {
|
|
105
|
-
material: material,
|
|
106
|
-
meta: innerMeta,
|
|
107
|
-
};
|
|
108
|
-
}));
|
|
109
|
-
copyMetaData(withMetaData.meta, meta);
|
|
110
|
-
return withMetaData.material;
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
function multiGToCfgMaterial(meta, renderEnvironment, multiGMaterial) {
|
|
114
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
meta.sourcePath.push("multiGToCfgMaterial");
|
|
116
|
-
if (multiGMaterial instanceof Error) {
|
|
117
|
-
meta.logger.error("error while loading materials", multiGMaterial.message);
|
|
118
|
-
meta.logger.warn(multiGMaterial);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
meta.multiGMaterial = multiGMaterial;
|
|
122
|
-
const gMaterial = multiGMaterial.renderMaterial();
|
|
123
|
-
if (gMaterial === undefined) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
return gMaterialToCfgMaterial(meta, renderEnvironment, gMaterial);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { CfgMtrlSourceBuffer, CfgMtrlSourceUrl, } from "@configura/web-api";
|
|
11
|
+
import { loadMaterialFromUrl, makeMaterialFromBuffer, } from "@configura/web-core/dist/cm/format/cmsym/components/SymGMaterial.js";
|
|
12
|
+
import { getFileExtension, LogObservable } from "@configura/web-utilities";
|
|
13
|
+
import { CfgMaterial } from "./CfgMaterial.js";
|
|
14
|
+
import { getTextures, loadTextureFromURL } from "./texture.js";
|
|
15
|
+
function copyMetaData(source, target) {
|
|
16
|
+
const { logger: sourceLogger, sourcePath: sourceSourcePath, multiGMaterial: sourceMultiGMaterial, gMaterial: sourceGMaterial, } = source;
|
|
17
|
+
const { logger: targetLogger, sourcePath: targetSourcePath } = target;
|
|
18
|
+
sourceLogger.accumulated.forEach((p) => targetLogger.addPrebaked(p));
|
|
19
|
+
targetSourcePath.push(...sourceSourcePath);
|
|
20
|
+
if (sourceMultiGMaterial !== undefined) {
|
|
21
|
+
target.multiGMaterial = sourceMultiGMaterial;
|
|
22
|
+
}
|
|
23
|
+
if (sourceGMaterial !== undefined) {
|
|
24
|
+
target.gMaterial = sourceGMaterial;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function mtrlSourceToCfgMaterial(meta, mtrlSourceWithMetaData, renderEnvironment) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const mtrlSource = mtrlSourceWithMetaData.mtrl;
|
|
30
|
+
meta.sourcePath.push("mtrlSourceToCfgMaterial");
|
|
31
|
+
if (mtrlSource instanceof CfgMtrlSourceBuffer) {
|
|
32
|
+
return bufferToCfgMaterial(renderEnvironment, meta, mtrlSource);
|
|
33
|
+
}
|
|
34
|
+
if (mtrlSource instanceof CfgMtrlSourceUrl) {
|
|
35
|
+
return mtrlSourceUrlToCachedCfgMaterial(meta, renderEnvironment, mtrlSource);
|
|
36
|
+
}
|
|
37
|
+
throw meta.logger.errorAsObject("Unsupported mtrlSource");
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function mtrlSourceUrlToCachedCfgMaterial(meta, renderEnvironment, mtrl) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const url = mtrl.url;
|
|
43
|
+
meta.sourcePath.push("mtrlSourceUrlToCachedCfgMaterial");
|
|
44
|
+
const materialWithMetaData = yield renderEnvironment.materialCache.get(url, () => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const innerMeta = {
|
|
46
|
+
logger: new LogObservable(),
|
|
47
|
+
sourcePath: [],
|
|
48
|
+
};
|
|
49
|
+
const result = {
|
|
50
|
+
material: undefined,
|
|
51
|
+
meta: innerMeta,
|
|
52
|
+
};
|
|
53
|
+
innerMeta.sourcePath.push("cache_url");
|
|
54
|
+
if (!url.startsWith("http")) {
|
|
55
|
+
innerMeta.logger.warn("BAD MTRL URL: ", url);
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
if (getFileExtension(url) !== "gm") {
|
|
59
|
+
const texture = yield loadTextureFromURL(url, renderEnvironment);
|
|
60
|
+
innerMeta.sourcePath.push("image");
|
|
61
|
+
result.material = CfgMaterial.makeFromTexture(renderEnvironment, texture, innerMeta.sourcePath);
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
const multiGMaterial = yield loadMaterialFromUrl(innerMeta.logger, url, renderEnvironment.dexManager);
|
|
65
|
+
innerMeta.sourcePath.push("gm");
|
|
66
|
+
result.material = yield multiGToCfgMaterial(innerMeta, renderEnvironment, multiGMaterial);
|
|
67
|
+
return result;
|
|
68
|
+
}));
|
|
69
|
+
copyMetaData(materialWithMetaData.meta, meta);
|
|
70
|
+
return materialWithMetaData.material;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function bufferToCfgMaterial(renderEnvironment, meta, mtrl) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
meta.sourcePath.push("bufferToCfgMaterial");
|
|
76
|
+
const fileName = mtrl.fileName;
|
|
77
|
+
const buffer = mtrl.buffer;
|
|
78
|
+
const fileExtension = getFileExtension(fileName);
|
|
79
|
+
if (fileExtension !== "gm") {
|
|
80
|
+
if (fileExtension !== "jpg" && fileExtension !== "jpeg" && fileExtension !== "png") {
|
|
81
|
+
throw meta.logger.errorAsObject("Unsupported file type");
|
|
82
|
+
}
|
|
83
|
+
meta.sourcePath.push("image");
|
|
84
|
+
const texture = yield loadTextureFromURL(`data:image/${fileExtension};base64,${btoa(String.fromCharCode(...new Uint8Array(buffer)))}`, renderEnvironment);
|
|
85
|
+
return CfgMaterial.makeFromTexture(renderEnvironment, texture, meta.sourcePath);
|
|
86
|
+
}
|
|
87
|
+
const multiGMaterial = makeMaterialFromBuffer(meta.logger, mtrl.buffer, renderEnvironment.dexManager);
|
|
88
|
+
meta.sourcePath.push("gm");
|
|
89
|
+
return multiGToCfgMaterial(meta, renderEnvironment, multiGMaterial);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
export function gMaterialToCfgMaterial(meta, renderEnvironment, gMaterial) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
meta.sourcePath.push("gMaterialToCfgMaterial");
|
|
95
|
+
const withMetaData = yield renderEnvironment.materialCache.get(gMaterial, () => __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const innerMeta = {
|
|
97
|
+
logger: new LogObservable(),
|
|
98
|
+
sourcePath: [],
|
|
99
|
+
};
|
|
100
|
+
innerMeta.sourcePath.push("cache_gMaterial");
|
|
101
|
+
innerMeta.gMaterial = gMaterial;
|
|
102
|
+
const textures = yield getTextures(innerMeta.logger, renderEnvironment, gMaterial);
|
|
103
|
+
const material = CfgMaterial.makeFromGm(renderEnvironment, innerMeta, gMaterial, textures);
|
|
104
|
+
return {
|
|
105
|
+
material: material,
|
|
106
|
+
meta: innerMeta,
|
|
107
|
+
};
|
|
108
|
+
}));
|
|
109
|
+
copyMetaData(withMetaData.meta, meta);
|
|
110
|
+
return withMetaData.material;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function multiGToCfgMaterial(meta, renderEnvironment, multiGMaterial) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
meta.sourcePath.push("multiGToCfgMaterial");
|
|
116
|
+
if (multiGMaterial instanceof Error) {
|
|
117
|
+
meta.logger.error("error while loading materials", multiGMaterial.message);
|
|
118
|
+
meta.logger.warn(multiGMaterial);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
meta.multiGMaterial = multiGMaterial;
|
|
122
|
+
const gMaterial = multiGMaterial.renderMaterial();
|
|
123
|
+
if (gMaterial === undefined) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
return gMaterialToCfgMaterial(meta, renderEnvironment, gMaterial);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
|
2
|
-
import { GMaterial3D, GMaterial3DTexture } from "@configura/web-core/dist/cm/core3D/GMaterial3D.js";
|
|
3
|
-
import { Logger, LogObservable } from "@configura/web-utilities";
|
|
4
|
-
import { RenderEnv } from "../view/RenderEnv.js";
|
|
5
|
-
export declare type TextureImageWithMetaData = {
|
|
6
|
-
image: HTMLImageElement | undefined;
|
|
7
|
-
logger: LogObservable;
|
|
8
|
-
};
|
|
9
|
-
export declare function loadTextureFromURL(url: string, renderEnvironment: RenderEnv): Promise<Texture>;
|
|
10
|
-
export interface GMAndTexture {
|
|
11
|
-
gm: GMaterial3DTexture;
|
|
12
|
-
tx?: Texture;
|
|
13
|
-
}
|
|
14
|
-
export declare function getTextures(logger: Logger, renderEnvironment: RenderEnv, gm: GMaterial3D): Promise<GMAndTexture[]>;
|
|
1
|
+
import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
|
2
|
+
import { GMaterial3D, GMaterial3DTexture } from "@configura/web-core/dist/cm/core3D/GMaterial3D.js";
|
|
3
|
+
import { Logger, LogObservable } from "@configura/web-utilities";
|
|
4
|
+
import { RenderEnv } from "../view/RenderEnv.js";
|
|
5
|
+
export declare type TextureImageWithMetaData = {
|
|
6
|
+
image: HTMLImageElement | undefined;
|
|
7
|
+
logger: LogObservable;
|
|
8
|
+
};
|
|
9
|
+
export declare function loadTextureFromURL(url: string, renderEnvironment: RenderEnv): Promise<Texture>;
|
|
10
|
+
export interface GMAndTexture {
|
|
11
|
+
gm: GMaterial3DTexture;
|
|
12
|
+
tx?: Texture;
|
|
13
|
+
}
|
|
14
|
+
export declare function getTextures(logger: Logger, renderEnvironment: RenderEnv, gm: GMaterial3D): Promise<GMAndTexture[]>;
|
|
15
15
|
//# sourceMappingURL=texture.d.ts.map
|