|
@@ -1,27 +1,27 @@
|
|
|
module BABYLON {
|
|
|
|
|
|
var serializeLight = (light: Light): any => {
|
|
|
- var serializationObject:any = {};
|
|
|
+ var serializationObject: any = {};
|
|
|
serializationObject.name = light.name;
|
|
|
serializationObject.id = light.id;
|
|
|
serializationObject.tags = Tags.GetTags(light);
|
|
|
|
|
|
- if (light instanceof BABYLON.PointLight) {
|
|
|
+ if (light instanceof PointLight) {
|
|
|
serializationObject.type = 0;
|
|
|
serializationObject.position = (<PointLight>light).position.asArray();
|
|
|
- } else if (light instanceof BABYLON.DirectionalLight) {
|
|
|
+ } else if (light instanceof DirectionalLight) {
|
|
|
serializationObject.type = 1;
|
|
|
var directionalLight = <DirectionalLight>light;
|
|
|
serializationObject.position = directionalLight.position.asArray();
|
|
|
serializationObject.direction = directionalLight.direction.asArray();
|
|
|
- } else if (light instanceof BABYLON.SpotLight) {
|
|
|
+ } else if (light instanceof SpotLight) {
|
|
|
serializationObject.type = 2;
|
|
|
var spotLight = <SpotLight>light;
|
|
|
serializationObject.position = spotLight.position.asArray();
|
|
|
serializationObject.direction = spotLight.position.asArray();
|
|
|
serializationObject.angle = spotLight.angle;
|
|
|
serializationObject.exponent = spotLight.exponent;
|
|
|
- } else if (light instanceof BABYLON.HemisphericLight) {
|
|
|
+ } else if (light instanceof HemisphericLight) {
|
|
|
serializationObject.type = 3;
|
|
|
var hemisphericLight = <HemisphericLight>light;
|
|
|
serializationObject.direction = hemisphericLight.direction.asArray();
|
|
@@ -52,8 +52,8 @@
|
|
|
return serializationObject;
|
|
|
}
|
|
|
|
|
|
- var serializeCamera = (camera: FreeCamera): any => {
|
|
|
- var serializationObject:any = {};
|
|
|
+ var serializeCamera = (camera: Camera): any => {
|
|
|
+ var serializationObject: any = {};
|
|
|
serializationObject.name = camera.name;
|
|
|
serializationObject.tags = Tags.GetTags(camera);
|
|
|
serializationObject.id = camera.id;
|
|
@@ -64,26 +64,83 @@
|
|
|
serializationObject.parentId = camera.parent.id;
|
|
|
}
|
|
|
|
|
|
- // Target
|
|
|
- serializationObject.rotation = camera.rotation.asArray();
|
|
|
-
|
|
|
- // Locked target
|
|
|
- if (camera.lockedTarget && camera.lockedTarget.id) {
|
|
|
- serializationObject.lockedTargetId = camera.lockedTarget.id;
|
|
|
- }
|
|
|
-
|
|
|
serializationObject.fov = camera.fov;
|
|
|
serializationObject.minZ = camera.minZ;
|
|
|
serializationObject.maxZ = camera.maxZ;
|
|
|
|
|
|
- serializationObject.speed = camera.speed;
|
|
|
serializationObject.inertia = camera.inertia;
|
|
|
|
|
|
- serializationObject.checkCollisions = camera.checkCollisions;
|
|
|
- serializationObject.applyGravity = camera.applyGravity;
|
|
|
+ //setting the type
|
|
|
+ if (camera instanceof FreeCamera) {
|
|
|
+ serializationObject.type = "FreeCamera";
|
|
|
+ } else if (camera instanceof ArcRotateCamera) {
|
|
|
+ serializationObject.type = "ArcRotateCamera";
|
|
|
+ } else if (camera instanceof AnaglyphArcRotateCamera) {
|
|
|
+ serializationObject.type = "AnaglyphArcRotateCamera";
|
|
|
+ } else if (camera instanceof GamepadCamera) {
|
|
|
+ serializationObject.type = "GamepadCamera";
|
|
|
+ } else if (camera instanceof AnaglyphFreeCamera) {
|
|
|
+ serializationObject.type = "AnaglyphFreeCamera";
|
|
|
+ } else if (camera instanceof DeviceOrientationCamera) {
|
|
|
+ serializationObject.type = "DeviceOrientationCamera";
|
|
|
+ } else if (camera instanceof FollowCamera) {
|
|
|
+ serializationObject.type = "FollowCamera";
|
|
|
+ } else if (camera instanceof OculusCamera) {
|
|
|
+ serializationObject.type = "OculusCamera";
|
|
|
+ } else if (camera instanceof OculusGamepadCamera) {
|
|
|
+ serializationObject.type = "OculusGamepadCamera";
|
|
|
+ } else if (camera instanceof TouchCamera) {
|
|
|
+ serializationObject.type = "TouchCamera";
|
|
|
+ } else if (camera instanceof VirtualJoysticksCamera) {
|
|
|
+ serializationObject.type = "VirtualJoysticksCamera";
|
|
|
+ } else if (camera instanceof WebVRCamera) {
|
|
|
+ serializationObject.type = "WebVRCamera";
|
|
|
+ } else if (camera instanceof VRDeviceOrientationCamera) {
|
|
|
+ serializationObject.type = "VRDeviceOrientationCamera";
|
|
|
+ }
|
|
|
+
|
|
|
+ //special properties of specific cameras
|
|
|
+ if (camera instanceof ArcRotateCamera || camera instanceof AnaglyphArcRotateCamera) {
|
|
|
+ var arcCamera = <ArcRotateCamera> camera;
|
|
|
+ serializationObject.alpha = arcCamera.alpha;
|
|
|
+ serializationObject.beta = arcCamera.beta;
|
|
|
+ serializationObject.radius = arcCamera.radius;
|
|
|
+ } else if (camera instanceof FollowCamera) {
|
|
|
+ var followCam = <FollowCamera> camera;
|
|
|
+ serializationObject.radius = followCam.radius;
|
|
|
+ serializationObject.heightOffset = followCam.heightOffset;
|
|
|
+ serializationObject.rotationOffset = followCam.rotationOffset;
|
|
|
+ } else if (camera instanceof AnaglyphFreeCamera || camera instanceof AnaglyphArcRotateCamera) {
|
|
|
+ //eye space is a private member and can only be access like this. Without changing the implementation this is the best way to get it.
|
|
|
+ if (camera['_eyeSpace'] !== undefined) {
|
|
|
+ serializationObject.eye_space = Tools.ToDegrees(camera['_eyeSpace']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //general properties that not all cameras have. The [] is due to typescript's type safety
|
|
|
+ if (camera['speed'] !== undefined) {
|
|
|
+ serializationObject.speed = camera['speed'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // Target
|
|
|
+ if (camera['rotation'] && camera['rotation'] instanceof Vector3) {
|
|
|
+ serializationObject.rotation = camera['rotation'].asArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Locked target
|
|
|
+ if (camera['lockedTarget'] && camera['lockedTarget'].id) {
|
|
|
+ serializationObject.lockedTargetId = camera['lockedTarget'].id;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (camera['checkCollisions'] !== undefined) {
|
|
|
+ serializationObject.checkCollisions = camera['checkCollisions'];
|
|
|
+ }
|
|
|
+ if (camera['applyGravity'] !== undefined) {
|
|
|
+ serializationObject.applyGravity = camera['applyGravity'];
|
|
|
+ }
|
|
|
|
|
|
- if (camera.ellipsoid) {
|
|
|
- serializationObject.ellipsoid = camera.ellipsoid.asArray();
|
|
|
+ if (camera['ellipsoid']) {
|
|
|
+ serializationObject.ellipsoid = camera['ellipsoid'].asArray();
|
|
|
}
|
|
|
|
|
|
// Animations
|
|
@@ -107,7 +164,7 @@
|
|
|
};
|
|
|
|
|
|
var serializeAnimation = (animation: Animation): any => {
|
|
|
- var serializationObject:any = {};
|
|
|
+ var serializationObject: any = {};
|
|
|
|
|
|
serializationObject.name = animation.name;
|
|
|
serializationObject.property = animation.targetProperty;
|
|
@@ -121,18 +178,18 @@
|
|
|
for (var index = 0; index < keys.length; index++) {
|
|
|
var animationKey = keys[index];
|
|
|
|
|
|
- var key:any = {};
|
|
|
+ var key: any = {};
|
|
|
key.frame = animationKey.frame;
|
|
|
|
|
|
switch (dataType) {
|
|
|
- case BABYLON.Animation.ANIMATIONTYPE_FLOAT:
|
|
|
- key.values = [animationKey.value];
|
|
|
- break;
|
|
|
- case BABYLON.Animation.ANIMATIONTYPE_QUATERNION:
|
|
|
- case BABYLON.Animation.ANIMATIONTYPE_MATRIX:
|
|
|
- case BABYLON.Animation.ANIMATIONTYPE_VECTOR3:
|
|
|
- key.values = animationKey.value.asArray();
|
|
|
- break;
|
|
|
+ case Animation.ANIMATIONTYPE_FLOAT:
|
|
|
+ key.values = [animationKey.value];
|
|
|
+ break;
|
|
|
+ case Animation.ANIMATIONTYPE_QUATERNION:
|
|
|
+ case Animation.ANIMATIONTYPE_MATRIX:
|
|
|
+ case Animation.ANIMATIONTYPE_VECTOR3:
|
|
|
+ key.values = animationKey.value.asArray();
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
serializationObject.keys.push(key);
|
|
@@ -142,7 +199,7 @@
|
|
|
};
|
|
|
|
|
|
var serializeMultiMaterial = (material: MultiMaterial): any => {
|
|
|
- var serializationObject:any = {};
|
|
|
+ var serializationObject: any = {};
|
|
|
|
|
|
serializationObject.name = material.name;
|
|
|
serializationObject.id = material.id;
|
|
@@ -164,7 +221,7 @@
|
|
|
};
|
|
|
|
|
|
var serializeMaterial = (material: StandardMaterial): any => {
|
|
|
- var serializationObject:any = {};
|
|
|
+ var serializationObject: any = {};
|
|
|
|
|
|
serializationObject.name = material.name;
|
|
|
|
|
@@ -228,13 +285,13 @@
|
|
|
};
|
|
|
|
|
|
var serializeTexture = (texture: BaseTexture): any => {
|
|
|
- var serializationObject:any = {};
|
|
|
+ var serializationObject: any = {};
|
|
|
|
|
|
if (!texture.name) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- if (texture instanceof BABYLON.CubeTexture) {
|
|
|
+ if (texture instanceof CubeTexture) {
|
|
|
serializationObject.name = texture.name;
|
|
|
serializationObject.hasAlpha = texture.hasAlpha;
|
|
|
serializationObject.level = texture.level;
|
|
@@ -243,7 +300,7 @@
|
|
|
return serializationObject;
|
|
|
}
|
|
|
|
|
|
- if (texture instanceof BABYLON.MirrorTexture) {
|
|
|
+ if (texture instanceof MirrorTexture) {
|
|
|
var mirrorTexture = <MirrorTexture>texture;
|
|
|
serializationObject.renderTargetSize = mirrorTexture.getRenderSize();
|
|
|
serializationObject.renderList = [];
|
|
@@ -253,7 +310,7 @@
|
|
|
}
|
|
|
|
|
|
serializationObject.mirrorPlane = mirrorTexture.mirrorPlane.asArray();
|
|
|
- } else if (texture instanceof BABYLON.RenderTargetTexture) {
|
|
|
+ } else if (texture instanceof RenderTargetTexture) {
|
|
|
var renderTargetTexture = <RenderTargetTexture>texture;
|
|
|
serializationObject.renderTargetSize = renderTargetTexture.getRenderSize();
|
|
|
serializationObject.renderList = [];
|
|
@@ -288,8 +345,8 @@
|
|
|
return serializationObject;
|
|
|
};
|
|
|
|
|
|
- var serializeSkeleton = (skeleton:Skeleton): any => {
|
|
|
- var serializationObject:any = {};
|
|
|
+ var serializeSkeleton = (skeleton: Skeleton): any => {
|
|
|
+ var serializationObject: any = {};
|
|
|
|
|
|
serializationObject.name = skeleton.name;
|
|
|
serializationObject.id = skeleton.id;
|
|
@@ -299,7 +356,7 @@
|
|
|
for (var index = 0; index < skeleton.bones.length; index++) {
|
|
|
var bone = skeleton.bones[index];
|
|
|
|
|
|
- var serializedBone:any = {
|
|
|
+ var serializedBone: any = {
|
|
|
parentBoneIndex: bone.getParent() ? skeleton.bones.indexOf(bone.getParent()) : -1,
|
|
|
name: bone.name,
|
|
|
matrix: bone.getLocalMatrix().toArray()
|
|
@@ -314,8 +371,8 @@
|
|
|
return serializationObject;
|
|
|
};
|
|
|
|
|
|
- var serializeParticleSystem = (particleSystem:ParticleSystem): any => {
|
|
|
- var serializationObject:any = {};
|
|
|
+ var serializeParticleSystem = (particleSystem: ParticleSystem): any => {
|
|
|
+ var serializationObject: any = {};
|
|
|
|
|
|
serializationObject.emitterId = particleSystem.emitter.id;
|
|
|
serializationObject.capacity = particleSystem.getCapacity();
|
|
@@ -347,8 +404,8 @@
|
|
|
return serializationObject;
|
|
|
};
|
|
|
|
|
|
- var serializeLensFlareSystem = (lensFlareSystem:LensFlareSystem):any => {
|
|
|
- var serializationObject:any = {};
|
|
|
+ var serializeLensFlareSystem = (lensFlareSystem: LensFlareSystem): any => {
|
|
|
+ var serializationObject: any = {};
|
|
|
|
|
|
serializationObject.emitterId = lensFlareSystem.getEmitter().id;
|
|
|
serializationObject.borderLimit = lensFlareSystem.borderLimit;
|
|
@@ -361,7 +418,7 @@
|
|
|
size: flare.size,
|
|
|
position: flare.position,
|
|
|
color: flare.color.asArray(),
|
|
|
- textureName: BABYLON.Tools.GetFilename(flare.texture.name)
|
|
|
+ textureName: Tools.GetFilename(flare.texture.name)
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -369,8 +426,8 @@
|
|
|
return serializationObject;
|
|
|
};
|
|
|
|
|
|
- var serializeShadowGenerator = (light: Light):any => {
|
|
|
- var serializationObject:any = {};
|
|
|
+ var serializeShadowGenerator = (light: Light): any => {
|
|
|
+ var serializationObject: any = {};
|
|
|
var shadowGenerator = light.getShadowGenerator();
|
|
|
|
|
|
serializationObject.lightId = light.id;
|
|
@@ -439,33 +496,33 @@
|
|
|
var serializeVertexData = (vertexData: Geometry): any => {
|
|
|
var serializationObject = serializeGeometryBase(vertexData);
|
|
|
|
|
|
- if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.PositionKind)) {
|
|
|
- serializationObject.positions = vertexData.getVerticesData(BABYLON.VertexBuffer.PositionKind);
|
|
|
+ if (vertexData.isVerticesDataPresent(VertexBuffer.PositionKind)) {
|
|
|
+ serializationObject.positions = vertexData.getVerticesData(VertexBuffer.PositionKind);
|
|
|
}
|
|
|
|
|
|
- if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
|
|
|
- serializationObject.normals = vertexData.getVerticesData(BABYLON.VertexBuffer.NormalKind);
|
|
|
+ if (vertexData.isVerticesDataPresent(VertexBuffer.NormalKind)) {
|
|
|
+ serializationObject.normals = vertexData.getVerticesData(VertexBuffer.NormalKind);
|
|
|
}
|
|
|
|
|
|
- if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
|
|
|
- serializationObject.uvs = vertexData.getVerticesData(BABYLON.VertexBuffer.UVKind);
|
|
|
+ if (vertexData.isVerticesDataPresent(VertexBuffer.UVKind)) {
|
|
|
+ serializationObject.uvs = vertexData.getVerticesData(VertexBuffer.UVKind);
|
|
|
}
|
|
|
|
|
|
- if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
|
|
|
- serializationObject.uvs2 = vertexData.getVerticesData(BABYLON.VertexBuffer.UV2Kind);
|
|
|
+ if (vertexData.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
|
|
|
+ serializationObject.uvs2 = vertexData.getVerticesData(VertexBuffer.UV2Kind);
|
|
|
}
|
|
|
|
|
|
- if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
|
|
|
- serializationObject.colors = vertexData.getVerticesData(BABYLON.VertexBuffer.ColorKind);
|
|
|
+ if (vertexData.isVerticesDataPresent(VertexBuffer.ColorKind)) {
|
|
|
+ serializationObject.colors = vertexData.getVerticesData(VertexBuffer.ColorKind);
|
|
|
}
|
|
|
|
|
|
- if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesIndicesKind)) {
|
|
|
- serializationObject.matricesIndices = vertexData.getVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind);
|
|
|
+ if (vertexData.isVerticesDataPresent(VertexBuffer.MatricesIndicesKind)) {
|
|
|
+ serializationObject.matricesIndices = vertexData.getVerticesData(VertexBuffer.MatricesIndicesKind);
|
|
|
serializationObject.matricesIndices._isExpanded = true;
|
|
|
}
|
|
|
|
|
|
- if (vertexData.isVerticesDataPresent(BABYLON.VertexBuffer.MatricesWeightsKind)) {
|
|
|
- serializationObject.matricesWeights = vertexData.getVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind);
|
|
|
+ if (vertexData.isVerticesDataPresent(VertexBuffer.MatricesWeightsKind)) {
|
|
|
+ serializationObject.matricesWeights = vertexData.getVerticesData(VertexBuffer.MatricesWeightsKind);
|
|
|
}
|
|
|
|
|
|
serializationObject.indices = vertexData.getIndices();
|
|
@@ -550,8 +607,8 @@
|
|
|
return serializationObject;
|
|
|
};
|
|
|
|
|
|
- var serializeMesh = (mesh: Mesh, serializationScene: any):any => {
|
|
|
- var serializationObject:any = {};
|
|
|
+ var serializeMesh = (mesh: Mesh, serializationScene: any): any => {
|
|
|
+ var serializationObject: any = {};
|
|
|
|
|
|
serializationObject.name = mesh.name;
|
|
|
serializationObject.id = mesh.id;
|
|
@@ -627,18 +684,18 @@
|
|
|
}
|
|
|
|
|
|
// Physics
|
|
|
- if (mesh.getPhysicsImpostor() !== BABYLON.PhysicsEngine.NoImpostor) {
|
|
|
+ if (mesh.getPhysicsImpostor() !== PhysicsEngine.NoImpostor) {
|
|
|
serializationObject.physicsMass = mesh.getPhysicsMass();
|
|
|
serializationObject.physicsFriction = mesh.getPhysicsFriction();
|
|
|
serializationObject.physicsRestitution = mesh.getPhysicsRestitution();
|
|
|
|
|
|
switch (mesh.getPhysicsImpostor()) {
|
|
|
- case BABYLON.PhysicsEngine.BoxImpostor:
|
|
|
- serializationObject.physicsImpostor = 1;
|
|
|
- break;
|
|
|
- case BABYLON.PhysicsEngine.SphereImpostor:
|
|
|
- serializationObject.physicsImpostor = 2;
|
|
|
- break;
|
|
|
+ case PhysicsEngine.BoxImpostor:
|
|
|
+ serializationObject.physicsImpostor = 1;
|
|
|
+ break;
|
|
|
+ case PhysicsEngine.SphereImpostor:
|
|
|
+ serializationObject.physicsImpostor = 2;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -671,7 +728,7 @@
|
|
|
|
|
|
export class SceneSerializer {
|
|
|
public static Serialize(scene: Scene): any {
|
|
|
- var serializationObject:any = {};
|
|
|
+ var serializationObject: any = {};
|
|
|
|
|
|
// Scene
|
|
|
serializationObject.useDelayedTextureLoading = scene.useDelayedTextureLoading;
|
|
@@ -701,11 +758,9 @@
|
|
|
serializationObject.cameras = [];
|
|
|
for (index = 0; index < scene.cameras.length; index++) {
|
|
|
var camera = scene.cameras[index];
|
|
|
-
|
|
|
- if (camera instanceof BABYLON.FreeCamera) {
|
|
|
- serializationObject.cameras.push(serializeCamera(<FreeCamera>camera));
|
|
|
- }
|
|
|
+ serializationObject.cameras.push(serializeCamera(camera));
|
|
|
}
|
|
|
+
|
|
|
if (scene.activeCamera) {
|
|
|
serializationObject.activeCameraID = scene.activeCamera.id;
|
|
|
}
|
|
@@ -716,9 +771,9 @@
|
|
|
for (index = 0; index < scene.materials.length; index++) {
|
|
|
var material = scene.materials[index];
|
|
|
|
|
|
- if (material instanceof BABYLON.StandardMaterial) {
|
|
|
+ if (material instanceof StandardMaterial) {
|
|
|
serializationObject.materials.push(serializeMaterial(<StandardMaterial>material));
|
|
|
- } else if (material instanceof BABYLON.MultiMaterial) {
|
|
|
+ } else if (material instanceof MultiMaterial) {
|
|
|
serializationObject.multiMaterials.push(serializeMultiMaterial(<MultiMaterial>material));
|
|
|
}
|
|
|
}
|
|
@@ -758,7 +813,7 @@
|
|
|
|
|
|
if (abstractMesh instanceof Mesh) {
|
|
|
var mesh = <Mesh>abstractMesh;
|
|
|
- if (mesh.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_LOADED || mesh.delayLoadState === BABYLON.Engine.DELAYLOADSTATE_NONE) {
|
|
|
+ if (mesh.delayLoadState === Engine.DELAYLOADSTATE_LOADED || mesh.delayLoadState === Engine.DELAYLOADSTATE_NONE) {
|
|
|
serializationObject.meshes.push(serializeMesh(mesh, serializationObject));
|
|
|
}
|
|
|
}
|