|
@@ -0,0 +1,71 @@
|
|
|
|
+import { PropertyChangedEvent } from './propertyChangedEvent';
|
|
|
|
+import { Tools } from 'babylonjs/Misc/tools';
|
|
|
|
+
|
|
|
|
+export class ReplayRecorder {
|
|
|
|
+ private _recordedCodeLines: string[];
|
|
|
|
+ private _previousObject: any;
|
|
|
|
+ private _previousProperty: string;
|
|
|
|
+
|
|
|
|
+ public reset() {
|
|
|
|
+ this._recordedCodeLines = [];
|
|
|
|
+ this._previousObject = null;
|
|
|
|
+ this._previousProperty = "";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public record(event: PropertyChangedEvent) {
|
|
|
|
+ if (!this._recordedCodeLines) {
|
|
|
|
+ this._recordedCodeLines = [];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this._previousObject === event.object && this._previousProperty === event.property) {
|
|
|
|
+ this._recordedCodeLines.pop();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let value = event.value;
|
|
|
|
+
|
|
|
|
+ if (value.w) { // Quaternion
|
|
|
|
+ value = `new BABYLON.Quaternion(${value.x}, ${value.y}, ${value.z}, ${value.w})`;
|
|
|
|
+ } else if (value.z) { // Vector3
|
|
|
|
+ value = `new BABYLON.Vector3(${value.x}, ${value.y}, ${value.z})`;
|
|
|
|
+ } else if (value.y) { // Vector2
|
|
|
|
+ value = `new BABYLON.Vector2(${value.x}, ${value.y})`;
|
|
|
|
+ } else if (value.a) { // Color4
|
|
|
|
+ value = `new BABYLON.Color4(${value.r}, ${value.g}, ${value.b}, ${value.a})`;
|
|
|
|
+ } else if (value.b) { // Color3
|
|
|
|
+ value = `new BABYLON.Color3(${value.r}, ${value.g}, ${value.b})`;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let target = event.object.getClassName().toLowerCase();
|
|
|
|
+
|
|
|
|
+ if (event.object.uniqueId) {
|
|
|
|
+ if (target.indexOf("camera")) {
|
|
|
|
+ target = `scene.getCameraByUniqueID(${event.object.uniqueId})`;
|
|
|
|
+ } else if (target.indexOf("mesh")) {
|
|
|
|
+ target = `scene.getMeshByUniqueID(${event.object.uniqueId})`;
|
|
|
|
+ } else if (target.indexOf("light")) {
|
|
|
|
+ target = `scene.getLightByUniqueID(${event.object.uniqueId})`;
|
|
|
|
+ } else if (target === "transformnode") {
|
|
|
|
+ target = `scene.getTransformNodeByUniqueID(${event.object.uniqueId})`;
|
|
|
|
+ } else if (target === "skeleton") {
|
|
|
|
+ target = `scene.getSkeletonByUniqueId(${event.object.uniqueId})`;
|
|
|
|
+ } else if (target.indexOf("material")) {
|
|
|
|
+ target = `scene.getMaterialByUniqueID(${event.object.uniqueId})`;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this._recordedCodeLines.push(`${target}.${event.property} = ${value};`);
|
|
|
|
+
|
|
|
|
+ this._previousObject = event.object;
|
|
|
|
+ this._previousProperty = event.property;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public export() {
|
|
|
|
+ let content = "// Code generated by babylon.js Inspector\r\n// Please keep in mind to define the 'scene' variable before using that code\r\n\r\n";
|
|
|
|
+
|
|
|
|
+ if (this._recordedCodeLines) {
|
|
|
|
+ content += this._recordedCodeLines.join("\r\n");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Tools.Download(new Blob([content]), "pseudo-code.txt");
|
|
|
|
+ }
|
|
|
|
+}
|