|
@@ -3,9 +3,9 @@ import { GLTFFileLoader, GLTF2 } from "babylonjs-loaders";
|
|
|
import { IModelConfiguration, IModelAnimationConfiguration } from "../configuration/interfaces";
|
|
|
import { IModelAnimation, GroupModelAnimation, AnimationPlayMode, ModelAnimationConfiguration, EasingFunction, AnimationState } from "./modelAnimation";
|
|
|
|
|
|
-import { deepmerge } from '../helper/';
|
|
|
-import { AbstractViewer } from "..";
|
|
|
-import { extendClassWithConfig } from "../helper/";
|
|
|
+import { deepmerge, extendClassWithConfig } from '../helper/';
|
|
|
+import { ObservablesManager } from "managers/observablesManager";
|
|
|
+import { ConfigurationContainer } from "configuration/configurationContainer";
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -104,7 +104,7 @@ export class ViewerModel implements IDisposable {
|
|
|
|
|
|
private _shadowsRenderedAfterLoad: boolean = false;
|
|
|
|
|
|
- constructor(protected _viewer: AbstractViewer, modelConfiguration: IModelConfiguration) {
|
|
|
+ constructor(private _observablesManager: ObservablesManager, modelConfiguration: IModelConfiguration, private _configurationContainer?: ConfigurationContainer) {
|
|
|
this.onLoadedObservable = new Observable();
|
|
|
this.onLoadErrorObservable = new Observable();
|
|
|
this.onLoadProgressObservable = new Observable();
|
|
@@ -113,8 +113,8 @@ export class ViewerModel implements IDisposable {
|
|
|
|
|
|
this.state = ModelState.INIT;
|
|
|
|
|
|
- this.rootMesh = new AbstractMesh("modelRootMesh", this._viewer.sceneManager.scene);
|
|
|
- this._pivotMesh = new AbstractMesh("pivotMesh", this._viewer.sceneManager.scene);
|
|
|
+ this.rootMesh = new AbstractMesh("modelRootMesh");
|
|
|
+ this._pivotMesh = new AbstractMesh("pivotMesh");
|
|
|
this._pivotMesh.parent = this.rootMesh;
|
|
|
// rotate 180, gltf fun
|
|
|
this._pivotMesh.rotation.y += Math.PI;
|
|
@@ -123,10 +123,9 @@ export class ViewerModel implements IDisposable {
|
|
|
|
|
|
this._animations = [];
|
|
|
//create a copy of the configuration to make sure it doesn't change even after it is changed in the viewer
|
|
|
- this._modelConfiguration = deepmerge(this._viewer.configuration.model || {}, modelConfiguration);
|
|
|
+ this._modelConfiguration = deepmerge((this._configurationContainer && this._configurationContainer.configuration.model) || {}, modelConfiguration);
|
|
|
|
|
|
- this._viewer.sceneManager.models.push(this);
|
|
|
- this._viewer.onModelAddedObservable.notifyObservers(this);
|
|
|
+ if (this._observablesManager) { this._observablesManager.onModelAddedObservable.notifyObservers(this); }
|
|
|
|
|
|
if (this._modelConfiguration.entryAnimation) {
|
|
|
this.rootMesh.setEnabled(false);
|
|
@@ -134,7 +133,7 @@ export class ViewerModel implements IDisposable {
|
|
|
|
|
|
this.onLoadedObservable.add(() => {
|
|
|
this.updateConfiguration(this._modelConfiguration);
|
|
|
- this._viewer.onModelLoadedObservable.notifyObservers(this);
|
|
|
+ if (this._observablesManager) { this._observablesManager.onModelLoadedObservable.notifyObservers(this); }
|
|
|
this._initAnimations();
|
|
|
});
|
|
|
|
|
@@ -155,6 +154,10 @@ export class ViewerModel implements IDisposable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public getViewerId() {
|
|
|
+ return this._configurationContainer && this._configurationContainer.viewerId;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Is this model enabled?
|
|
|
*/
|
|
@@ -181,13 +184,6 @@ export class ViewerModel implements IDisposable {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get the viewer showing this model
|
|
|
- */
|
|
|
- public getViewer() {
|
|
|
- return this._viewer;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
* Add a mesh to this model.
|
|
|
* Any mesh that has no parent will be provided with the root mesh as its new parent.
|
|
|
*
|
|
@@ -244,7 +240,7 @@ export class ViewerModel implements IDisposable {
|
|
|
// check if this is not a gltf loader and init the animations
|
|
|
if (this.skeletons.length) {
|
|
|
this.skeletons.forEach((skeleton, idx) => {
|
|
|
- let ag = new AnimationGroup("animation-" + idx, this._viewer.sceneManager.scene);
|
|
|
+ let ag = new AnimationGroup("animation-" + idx);
|
|
|
skeleton.getAnimatables().forEach(a => {
|
|
|
if (a.animations[0]) {
|
|
|
ag.addTargetedAnimation(a.animations[0], a);
|
|
@@ -282,9 +278,10 @@ export class ViewerModel implements IDisposable {
|
|
|
* @param completeCallback A function to call when the animation has completed
|
|
|
*/
|
|
|
private _enterScene(completeCallback?: () => void): void {
|
|
|
+ const scene = this.rootMesh.getScene();
|
|
|
let callback = () => {
|
|
|
this.state = ModelState.ENTRYDONE;
|
|
|
- this._viewer.sceneManager.animationBlendingEnabled = true;
|
|
|
+ scene.animationPropertiesOverride!.enableBlending = true;
|
|
|
this._checkCompleteState();
|
|
|
if (completeCallback) completeCallback();
|
|
|
}
|
|
@@ -294,7 +291,7 @@ export class ViewerModel implements IDisposable {
|
|
|
}
|
|
|
this.rootMesh.setEnabled(true);
|
|
|
// disable blending for the sake of the entry animation;
|
|
|
- this._viewer.sceneManager.animationBlendingEnabled = false;
|
|
|
+ scene.animationPropertiesOverride!.enableBlending = false;
|
|
|
this._applyAnimation(this._entryAnimation, true, callback);
|
|
|
}
|
|
|
|
|
@@ -553,8 +550,8 @@ export class ViewerModel implements IDisposable {
|
|
|
if (this._modelConfiguration.material.directEnabled !== undefined) {
|
|
|
material.disableLighting = !this._modelConfiguration.material.directEnabled;
|
|
|
}
|
|
|
- if (this._viewer.sceneManager.reflectionColor) {
|
|
|
- material.reflectionColor = this._viewer.sceneManager.reflectionColor;
|
|
|
+ if (this._configurationContainer && this._configurationContainer.reflectionColor) {
|
|
|
+ material.reflectionColor = this._configurationContainer.reflectionColor;
|
|
|
}
|
|
|
}
|
|
|
else if (material instanceof MultiMaterial) {
|
|
@@ -631,8 +628,8 @@ export class ViewerModel implements IDisposable {
|
|
|
|
|
|
this.rootMesh.animations = animations;
|
|
|
|
|
|
- if (this._viewer.sceneManager.scene.beginAnimation) {
|
|
|
- let animatable: Animatable = this._viewer.sceneManager.scene.beginAnimation(this.rootMesh, 0, this._frameRate * duration, false, 1, () => {
|
|
|
+ if (this.rootMesh.getScene().beginAnimation) {
|
|
|
+ let animatable: Animatable = this.rootMesh.getScene().beginAnimation(this.rootMesh, 0, this._frameRate * duration, false, 1, () => {
|
|
|
if (onAnimationEnd) {
|
|
|
onAnimationEnd();
|
|
|
}
|
|
@@ -733,10 +730,10 @@ export class ViewerModel implements IDisposable {
|
|
|
*/
|
|
|
public remove() {
|
|
|
this.stopAllAnimations();
|
|
|
- this._viewer.sceneManager.models.splice(this._viewer.sceneManager.models.indexOf(this), 1);
|
|
|
+
|
|
|
// hide it
|
|
|
this.rootMesh.isVisible = false;
|
|
|
- this._viewer.onModelRemovedObservable.notifyObservers(this);
|
|
|
+ if (this._observablesManager) { this._observablesManager.onModelRemovedObservable.notifyObservers(this); }
|
|
|
}
|
|
|
|
|
|
/**
|