|
@@ -279,44 +279,6 @@ export class ViewerModel implements IDisposable {
|
|
|
updateMeshesWithNoParent(variable, configValues.w, 'w');
|
|
|
}
|
|
|
}
|
|
|
- // position?
|
|
|
- if (this._modelConfiguration.position) {
|
|
|
- updateXYZ('position', this._modelConfiguration.position);
|
|
|
- }
|
|
|
- if (this._modelConfiguration.rotation) {
|
|
|
- //quaternion?
|
|
|
- if (this._modelConfiguration.rotation.w) {
|
|
|
- meshesWithNoParent.forEach(mesh => {
|
|
|
- if (!mesh.rotationQuaternion) {
|
|
|
- mesh.rotationQuaternion = new Quaternion();
|
|
|
- }
|
|
|
- })
|
|
|
- updateXYZ('rotationQuaternion', this._modelConfiguration.rotation);
|
|
|
- } else {
|
|
|
- updateXYZ('rotation', this._modelConfiguration.rotation);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (this._modelConfiguration.rotationOffsetAxis) {
|
|
|
- let rotationAxis = new Vector3(0, 0, 0).copyFrom(this._modelConfiguration.rotationOffsetAxis as Vector3);
|
|
|
-
|
|
|
- meshesWithNoParent.forEach(m => {
|
|
|
- if (this._modelConfiguration.rotationOffsetAngle) {
|
|
|
- m.rotate(rotationAxis, this._modelConfiguration.rotationOffsetAngle);
|
|
|
- }
|
|
|
- })
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if (this._modelConfiguration.scaling) {
|
|
|
- updateXYZ('scaling', this._modelConfiguration.scaling);
|
|
|
- }
|
|
|
-
|
|
|
- if (this._modelConfiguration.castShadow) {
|
|
|
- this._meshes.forEach(mesh => {
|
|
|
- Tags.AddTagsTo(mesh, 'castShadow');
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
if (this._modelConfiguration.normalize) {
|
|
|
let center = false;
|
|
@@ -352,13 +314,61 @@ export class ViewerModel implements IDisposable {
|
|
|
const center = boundingInfo.min.add(halfSizeVec);
|
|
|
mesh.position = center.scale(-1);
|
|
|
|
|
|
- // Set on ground.
|
|
|
- //mesh.position.y = 0;
|
|
|
-
|
|
|
// Recompute Info.
|
|
|
mesh.computeWorldMatrix(true);
|
|
|
});
|
|
|
}
|
|
|
+ } else {
|
|
|
+ //center automatically
|
|
|
+ meshesWithNoParent.forEach(mesh => {
|
|
|
+ const boundingInfo = mesh.getHierarchyBoundingVectors(true);
|
|
|
+ const sizeVec = boundingInfo.max.subtract(boundingInfo.min);
|
|
|
+ const halfSizeVec = sizeVec.scale(0.5);
|
|
|
+ const center = boundingInfo.min.add(halfSizeVec);
|
|
|
+ mesh.position = center.scale(-1);
|
|
|
+
|
|
|
+ // Recompute Info.
|
|
|
+ mesh.computeWorldMatrix(true);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // position?
|
|
|
+ if (this._modelConfiguration.position) {
|
|
|
+ updateXYZ('position', this._modelConfiguration.position);
|
|
|
+ }
|
|
|
+ if (this._modelConfiguration.rotation) {
|
|
|
+ //quaternion?
|
|
|
+ if (this._modelConfiguration.rotation.w) {
|
|
|
+ meshesWithNoParent.forEach(mesh => {
|
|
|
+ if (!mesh.rotationQuaternion) {
|
|
|
+ mesh.rotationQuaternion = new Quaternion();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ updateXYZ('rotationQuaternion', this._modelConfiguration.rotation);
|
|
|
+ } else {
|
|
|
+ updateXYZ('rotation', this._modelConfiguration.rotation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this._modelConfiguration.rotationOffsetAxis) {
|
|
|
+ let rotationAxis = new Vector3(0, 0, 0).copyFrom(this._modelConfiguration.rotationOffsetAxis as Vector3);
|
|
|
+
|
|
|
+ meshesWithNoParent.forEach(m => {
|
|
|
+ if (this._modelConfiguration.rotationOffsetAngle) {
|
|
|
+ m.rotate(rotationAxis, this._modelConfiguration.rotationOffsetAngle);
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this._modelConfiguration.scaling) {
|
|
|
+ updateXYZ('scaling', this._modelConfiguration.scaling);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this._modelConfiguration.castShadow) {
|
|
|
+ this._meshes.forEach(mesh => {
|
|
|
+ Tags.AddTagsTo(mesh, 'castShadow');
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
let meshes = this.rootMesh.getChildMeshes(false);
|
|
@@ -394,8 +404,9 @@ export class ViewerModel implements IDisposable {
|
|
|
if (this._modelConfiguration.material.directEnabled !== undefined) {
|
|
|
material.disableLighting = !this._modelConfiguration.material.directEnabled;
|
|
|
}
|
|
|
-
|
|
|
- material.reflectionColor = this._viewer.sceneManager.mainColor;
|
|
|
+ if (this._viewer.sceneManager.mainColor) {
|
|
|
+ material.reflectionColor = this._viewer.sceneManager.mainColor;
|
|
|
+ }
|
|
|
}
|
|
|
else if (material instanceof BABYLON.MultiMaterial) {
|
|
|
for (let i = 0; i < material.subMaterials.length; i++) {
|