|
@@ -1,17 +1,17 @@
|
|
|
import * as React from "react";
|
|
|
-import { GlobalState } from '../globalState';
|
|
|
+import { GlobalState } from "../globalState";
|
|
|
|
|
|
-import { Engine } from 'babylonjs/Engines/engine';
|
|
|
-import { SceneLoader } from 'babylonjs/Loading/sceneLoader';
|
|
|
+import { Engine } from "babylonjs/Engines/engine";
|
|
|
+import { SceneLoader } from "babylonjs/Loading/sceneLoader";
|
|
|
import { GLTFFileLoader } from "babylonjs-loaders/glTF/glTFFileLoader";
|
|
|
-import { Scene } from 'babylonjs/scene';
|
|
|
-import { Vector3 } from 'babylonjs/Maths/math.vector';
|
|
|
-import { ArcRotateCamera } from 'babylonjs/Cameras/arcRotateCamera';
|
|
|
-import { FramingBehavior } from 'babylonjs/Behaviors/Cameras/framingBehavior';
|
|
|
-import { EnvironmentTools } from '../tools/environmentTools';
|
|
|
-import { Tools } from 'babylonjs/Misc/tools';
|
|
|
-import { FilesInput } from 'babylonjs/Misc/filesInput';
|
|
|
-import {Animation} from 'babylonjs/Animations/animation';
|
|
|
+import { Scene } from "babylonjs/scene";
|
|
|
+import { Vector3 } from "babylonjs/Maths/math.vector";
|
|
|
+import { ArcRotateCamera } from "babylonjs/Cameras/arcRotateCamera";
|
|
|
+import { FramingBehavior } from "babylonjs/Behaviors/Cameras/framingBehavior";
|
|
|
+import { EnvironmentTools } from "../tools/environmentTools";
|
|
|
+import { Tools } from "babylonjs/Misc/tools";
|
|
|
+import { FilesInput } from "babylonjs/Misc/filesInput";
|
|
|
+import { Animation } from "babylonjs/Animations/animation";
|
|
|
|
|
|
require("../scss/renderingZone.scss");
|
|
|
|
|
@@ -35,7 +35,7 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
initEngine() {
|
|
|
this._canvas = document.getElementById("renderCanvas") as HTMLCanvasElement;
|
|
|
this._engine = new Engine(this._canvas, true, { premultipliedAlpha: false, preserveDrawingBuffer: true });
|
|
|
-
|
|
|
+
|
|
|
this._engine.loadingUIBackgroundColor = "#2A2342";
|
|
|
|
|
|
// Resize
|
|
@@ -46,12 +46,16 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
this.loadAsset();
|
|
|
|
|
|
// File inputs
|
|
|
- let filesInput = new FilesInput(this._engine, null,
|
|
|
+ let filesInput = new FilesInput(
|
|
|
+ this._engine,
|
|
|
+ null,
|
|
|
(sceneFile: File, scene: Scene) => {
|
|
|
this._scene = scene;
|
|
|
this.onSceneLoaded(sceneFile.name);
|
|
|
},
|
|
|
- null, null, null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
() => {
|
|
|
Tools.ClearLogCache();
|
|
|
if (this._scene) {
|
|
@@ -61,15 +65,16 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
this._scene.debugLayer.hide();
|
|
|
}
|
|
|
}
|
|
|
- }, null, (file, scene, message) => {
|
|
|
- this.props.globalState.onError.notifyObservers({ message : message});
|
|
|
- });
|
|
|
+ },
|
|
|
+ null,
|
|
|
+ (file, scene, message) => {
|
|
|
+ this.props.globalState.onError.notifyObservers({ message: message });
|
|
|
+ }
|
|
|
+ );
|
|
|
|
|
|
filesInput.onProcessFileCallback = (file, name, extension) => {
|
|
|
if (filesInput.filesToLoad && filesInput.filesToLoad.length === 1 && extension) {
|
|
|
- if (extension.toLowerCase() === "dds" ||
|
|
|
- extension.toLowerCase() === "env" ||
|
|
|
- extension.toLowerCase() === "hdr") {
|
|
|
+ if (extension.toLowerCase() === "dds" || extension.toLowerCase() === "env" || extension.toLowerCase() === "hdr") {
|
|
|
FilesInput.FilesToLoad[name] = file;
|
|
|
EnvironmentTools.SkyboxPath = "file:" + (file as any).correctName;
|
|
|
return false;
|
|
@@ -86,8 +91,7 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
if (event.keyCode === 82 && event.target && (event.target as HTMLElement).nodeName !== "INPUT" && this._scene) {
|
|
|
if (this.props.assetUrl) {
|
|
|
this.loadAssetFromUrl();
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
filesInput.reload();
|
|
|
}
|
|
|
}
|
|
@@ -105,8 +109,7 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
|
|
|
if (this.props.cameraPosition) {
|
|
|
camera.setPosition(this.props.cameraPosition);
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
if (this._currentPluginName === "gltf") {
|
|
|
// glTF assets use a +Z forward convention while the default camera faces +Z. Rotate the camera to look at the front of the asset.
|
|
|
camera.alpha += Math.PI;
|
|
@@ -120,7 +123,7 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
framingBehavior.elevationReturnTime = -1;
|
|
|
|
|
|
if (this._scene.meshes.length) {
|
|
|
- camera.lowerRadiusLimit = null;
|
|
|
+ camera.lowerRadiusLimit = null;
|
|
|
|
|
|
var worldExtends = this._scene.getWorldExtends(function (mesh) {
|
|
|
return mesh.isVisible && mesh.isEnabled();
|
|
@@ -136,20 +139,19 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
camera.pinchDeltaPercentage = 0.01;
|
|
|
}
|
|
|
|
|
|
- this._scene.activeCamera!.attachControl(this._canvas);
|
|
|
+ this._scene.activeCamera!.attachControl();
|
|
|
}
|
|
|
|
|
|
handleErrors() {
|
|
|
// In case of error during loading, meshes will be empty and clearColor is set to red
|
|
|
if (this._scene.meshes.length === 0 && this._scene.clearColor.r === 1 && this._scene.clearColor.g === 0 && this._scene.clearColor.b === 0) {
|
|
|
this._canvas.style.opacity = "0";
|
|
|
- this.props.globalState.onError.notifyObservers({scene: this._scene, message: "No mesh found in your scene"});
|
|
|
- }
|
|
|
- else {
|
|
|
+ this.props.globalState.onError.notifyObservers({ scene: this._scene, message: "No mesh found in your scene" });
|
|
|
+ } else {
|
|
|
if (Tools.errorsCount > 0) {
|
|
|
- this.props.globalState.onError.notifyObservers({scene: this._scene, message: "Scene loaded but several errors were found"});
|
|
|
+ this.props.globalState.onError.notifyObservers({ scene: this._scene, message: "Scene loaded but several errors were found" });
|
|
|
}
|
|
|
- // this._canvas.style.opacity = "1";
|
|
|
+ // this._canvas.style.opacity = "1";
|
|
|
let camera = this._scene.activeCamera! as ArcRotateCamera;
|
|
|
if (camera.keysUp) {
|
|
|
camera.keysUp.push(90); // Z
|
|
@@ -160,7 +162,7 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
camera.keysRight.push(69); // E
|
|
|
camera.keysRight.push(68); // D
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
prepareLighting() {
|
|
@@ -172,8 +174,7 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
if (this._scene.environmentTexture) {
|
|
|
this._scene.createDefaultSkybox(this._scene.environmentTexture, true, (this._scene.activeCamera!.maxZ - this._scene.activeCamera!.minZ) / 2, 0.3, false);
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
var pbrPresent = false;
|
|
|
for (var i = 0; i < this._scene.materials.length; i++) {
|
|
|
if (this._scene.materials[i].transparencyMode !== undefined) {
|
|
@@ -186,8 +187,7 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
if (!this._scene.environmentTexture) {
|
|
|
this._scene.environmentTexture = EnvironmentTools.LoadSkyboxPathTexture(this._scene);
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
this._scene.createDefaultLight();
|
|
|
}
|
|
|
}
|
|
@@ -198,7 +198,7 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
|
|
|
this._scene.skipFrustumClipping = true;
|
|
|
|
|
|
- this.props.globalState.onSceneLoaded.notifyObservers({scene: this._scene, filename: filename});
|
|
|
+ this.props.globalState.onSceneLoaded.notifyObservers({ scene: this._scene, filename: filename });
|
|
|
|
|
|
this.prepareCamera();
|
|
|
this.prepareLighting();
|
|
@@ -213,24 +213,26 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
let assetUrl = this.props.assetUrl!;
|
|
|
let rootUrl = Tools.GetFolderPath(assetUrl);
|
|
|
let fileName = Tools.GetFilename(assetUrl);
|
|
|
- SceneLoader.LoadAsync(rootUrl, fileName, this._engine).then((scene) => {
|
|
|
- if (this._scene) {
|
|
|
- this._scene.dispose();
|
|
|
- }
|
|
|
+ SceneLoader.LoadAsync(rootUrl, fileName, this._engine)
|
|
|
+ .then((scene) => {
|
|
|
+ if (this._scene) {
|
|
|
+ this._scene.dispose();
|
|
|
+ }
|
|
|
|
|
|
- this._scene = scene;
|
|
|
+ this._scene = scene;
|
|
|
|
|
|
- this.onSceneLoaded(fileName);
|
|
|
+ this.onSceneLoaded(fileName);
|
|
|
|
|
|
- scene.whenReadyAsync().then(() => {
|
|
|
- this._engine.runRenderLoop(() => {
|
|
|
- scene.render();
|
|
|
+ scene.whenReadyAsync().then(() => {
|
|
|
+ this._engine.runRenderLoop(() => {
|
|
|
+ scene.render();
|
|
|
+ });
|
|
|
});
|
|
|
+ })
|
|
|
+ .catch((reason) => {
|
|
|
+ this.props.globalState.onError.notifyObservers({ message: reason.message });
|
|
|
+ //TODO sceneError({ name: fileName }, null, reason.message || reason);
|
|
|
});
|
|
|
- }).catch((reason) => {
|
|
|
- this.props.globalState.onError.notifyObservers({ message : reason.message});
|
|
|
- //TODO sceneError({ name: fileName }, null, reason.message || reason);
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
loadAsset() {
|
|
@@ -249,13 +251,13 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
|
|
|
// This is really important to tell Babylon.js to use decomposeLerp and matrix interpolation
|
|
|
Animation.AllowMatricesInterpolation = true;
|
|
|
-
|
|
|
+
|
|
|
// Setting up some GLTF values
|
|
|
GLTFFileLoader.IncrementalLoading = false;
|
|
|
- SceneLoader.OnPluginActivatedObservable.add((plugin) =>{
|
|
|
+ SceneLoader.OnPluginActivatedObservable.add((plugin) => {
|
|
|
this._currentPluginName = plugin.name;
|
|
|
if (this._currentPluginName === "gltf") {
|
|
|
- (plugin as GLTFFileLoader).onValidatedObservable.add((results) =>{
|
|
|
+ (plugin as GLTFFileLoader).onValidatedObservable.add((results) => {
|
|
|
if (results.issues.numErrors > 0) {
|
|
|
this.props.globalState.showDebugLayer();
|
|
|
}
|
|
@@ -277,9 +279,8 @@ export class RenderingZone extends React.Component<IRenderingZoneProps> {
|
|
|
public render() {
|
|
|
return (
|
|
|
<div id="canvasZone" className={this.props.expanded ? "expanded" : ""}>
|
|
|
- <canvas id="renderCanvas" touch-action="none"
|
|
|
- onContextMenu={evt => evt.preventDefault()}></canvas>
|
|
|
+ <canvas id="renderCanvas" touch-action="none" onContextMenu={(evt) => evt.preventDefault()}></canvas>
|
|
|
</div>
|
|
|
- )
|
|
|
+ );
|
|
|
}
|
|
|
-}
|
|
|
+}
|