|
@@ -1,6 +1,6 @@
|
|
-/// <reference path="../../../dist/preview release/babylon.d.ts"/>
|
|
|
|
|
|
+/// <reference path="../../../../dist/preview release/babylon.d.ts"/>
|
|
|
|
|
|
-module BABYLON {
|
|
|
|
|
|
+module BABYLON.GLTF1 {
|
|
interface IGLTFMaterialsCommonExtensionValues {
|
|
interface IGLTFMaterialsCommonExtensionValues {
|
|
ambient?: number[] | string;
|
|
ambient?: number[] | string;
|
|
diffuse?: number[] | string;
|
|
diffuse?: number[] | string;
|
|
@@ -55,17 +55,17 @@ module BABYLON {
|
|
quadraticAttenuation: number;
|
|
quadraticAttenuation: number;
|
|
}
|
|
}
|
|
|
|
|
|
- export class GLTFMaterialsCommonExtension extends GLTFFileLoaderExtension {
|
|
|
|
|
|
+ export class GLTFMaterialsCommonExtension extends GLTFLoaderExtension {
|
|
|
|
|
|
constructor() {
|
|
constructor() {
|
|
super("KHR_materials_common");
|
|
super("KHR_materials_common");
|
|
}
|
|
}
|
|
|
|
|
|
- protected postCreateRuntime(runtime: IGLTFRuntime): void {
|
|
|
|
- if (!runtime.gltf.extensions) return;
|
|
|
|
|
|
+ public loadRuntimeExtensionsAsync(gltfRuntime: IGLTFRuntime, onSuccess: () => void, onError: () => void): boolean {
|
|
|
|
+ if (!gltfRuntime.extensions) return false;
|
|
|
|
|
|
- var extension = runtime.gltf.extensions[this.name];
|
|
|
|
- if (!extension) return;
|
|
|
|
|
|
+ var extension = gltfRuntime.extensions[this.name];
|
|
|
|
+ if (!extension) return false;
|
|
|
|
|
|
// Create lights
|
|
// Create lights
|
|
var lights: IGLTFRuntimeCommonExtension = extension.lights;
|
|
var lights: IGLTFRuntimeCommonExtension = extension.lights;
|
|
@@ -75,17 +75,17 @@ module BABYLON {
|
|
|
|
|
|
switch (light.type) {
|
|
switch (light.type) {
|
|
case "ambient":
|
|
case "ambient":
|
|
- var ambientLight = new HemisphericLight(light.name, new Vector3(0, 1, 0), runtime.babylonScene);
|
|
|
|
|
|
+ var ambientLight = new HemisphericLight(light.name, new Vector3(0, 1, 0), gltfRuntime.scene);
|
|
var ambient = light.ambient;
|
|
var ambient = light.ambient;
|
|
ambientLight.diffuse = Color3.FromArray(ambient.color || [1, 1, 1]);
|
|
ambientLight.diffuse = Color3.FromArray(ambient.color || [1, 1, 1]);
|
|
break;
|
|
break;
|
|
case "point":
|
|
case "point":
|
|
- var pointLight = new PointLight(light.name, new Vector3(10, 10, 10), runtime.babylonScene);
|
|
|
|
|
|
+ var pointLight = new PointLight(light.name, new Vector3(10, 10, 10), gltfRuntime.scene);
|
|
var point = light.point;
|
|
var point = light.point;
|
|
pointLight.diffuse = Color3.FromArray(point.color || [1, 1, 1]);
|
|
pointLight.diffuse = Color3.FromArray(point.color || [1, 1, 1]);
|
|
break;
|
|
break;
|
|
case "directional":
|
|
case "directional":
|
|
- var dirLight = new DirectionalLight(light.name, new Vector3(0, -1, 0), runtime.babylonScene);
|
|
|
|
|
|
+ var dirLight = new DirectionalLight(light.name, new Vector3(0, -1, 0), gltfRuntime.scene);
|
|
var directional = light.directional;
|
|
var directional = light.directional;
|
|
dirLight.diffuse = Color3.FromArray(directional.color || [1, 1, 1]);
|
|
dirLight.diffuse = Color3.FromArray(directional.color || [1, 1, 1]);
|
|
break;
|
|
break;
|
|
@@ -94,23 +94,25 @@ module BABYLON {
|
|
var spotLight = new SpotLight(light.name, new Vector3(0, 10, 0), new Vector3(0, -1, 0),
|
|
var spotLight = new SpotLight(light.name, new Vector3(0, 10, 0), new Vector3(0, -1, 0),
|
|
light.spot.fallOffAngle || Math.PI,
|
|
light.spot.fallOffAngle || Math.PI,
|
|
light.spot.fallOffExponent || 0.0,
|
|
light.spot.fallOffExponent || 0.0,
|
|
- runtime.babylonScene);
|
|
|
|
|
|
+ gltfRuntime.scene);
|
|
spotLight.diffuse = Color3.FromArray(spot.color || [1, 1, 1]);
|
|
spotLight.diffuse = Color3.FromArray(spot.color || [1, 1, 1]);
|
|
break;
|
|
break;
|
|
- default: Tools.Warn("GLTF Materials Common extension: light type \"" + light.type + "\” not supported"); break;
|
|
|
|
|
|
+ default: Tools.Warn("GLTF Material Common extension: light type \"" + light.type + "\” not supported"); break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
- protected loadMaterial(runtime: IGLTFRuntime, index: number): boolean {
|
|
|
|
- var material = runtime.gltf.materials[index];
|
|
|
|
|
|
+ public loadMaterialAsync(gltfRuntime: IGLTFRuntime, id: string, onSuccess: (material: Material) => void, onError: () => void): boolean {
|
|
|
|
+ var material: IGLTFMaterial = gltfRuntime.materials[id];
|
|
if (!material || !material.extensions) return false;
|
|
if (!material || !material.extensions) return false;
|
|
|
|
|
|
var extension: IGLTFMaterialsCommonExtension = material.extensions[this.name];
|
|
var extension: IGLTFMaterialsCommonExtension = material.extensions[this.name];
|
|
if (!extension) return false;
|
|
if (!extension) return false;
|
|
|
|
|
|
- var standardMaterial = new StandardMaterial(material.name || "mat" + index, runtime.babylonScene);
|
|
|
|
|
|
+ var standardMaterial = new StandardMaterial(id, gltfRuntime.scene);
|
|
standardMaterial.sideOrientation = Material.CounterClockWiseSideOrientation;
|
|
standardMaterial.sideOrientation = Material.CounterClockWiseSideOrientation;
|
|
|
|
|
|
if (extension.technique === "CONSTANT") {
|
|
if (extension.technique === "CONSTANT") {
|
|
@@ -120,11 +122,10 @@ module BABYLON {
|
|
standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
|
|
standardMaterial.backFaceCulling = extension.doubleSided === undefined ? false : !extension.doubleSided;
|
|
standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
|
|
standardMaterial.alpha = extension.values.transparency === undefined ? 1.0 : extension.values.transparency;
|
|
standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
|
|
standardMaterial.specularPower = extension.values.shininess === undefined ? 0.0 : extension.values.shininess;
|
|
-
|
|
|
|
- /*
|
|
|
|
|
|
+
|
|
// Ambient
|
|
// Ambient
|
|
if (typeof extension.values.ambient === "string") {
|
|
if (typeof extension.values.ambient === "string") {
|
|
- this._loadTexture(runtime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
|
|
|
|
|
|
+ this._loadTexture(gltfRuntime, extension.values.ambient, standardMaterial, "ambientTexture", onError);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
standardMaterial.ambientColor = Color3.FromArray(extension.values.ambient || [0, 0, 0]);
|
|
standardMaterial.ambientColor = Color3.FromArray(extension.values.ambient || [0, 0, 0]);
|
|
@@ -132,7 +133,7 @@ module BABYLON {
|
|
|
|
|
|
// Diffuse
|
|
// Diffuse
|
|
if (typeof extension.values.diffuse === "string") {
|
|
if (typeof extension.values.diffuse === "string") {
|
|
- this._loadTexture(runtime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
|
|
|
|
|
|
+ this._loadTexture(gltfRuntime, extension.values.diffuse, standardMaterial, "diffuseTexture", onError);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
standardMaterial.diffuseColor = Color3.FromArray(extension.values.diffuse || [0, 0, 0]);
|
|
standardMaterial.diffuseColor = Color3.FromArray(extension.values.diffuse || [0, 0, 0]);
|
|
@@ -140,7 +141,7 @@ module BABYLON {
|
|
|
|
|
|
// Emission
|
|
// Emission
|
|
if (typeof extension.values.emission === "string") {
|
|
if (typeof extension.values.emission === "string") {
|
|
- this._loadTexture(runtime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
|
|
|
|
|
|
+ this._loadTexture(gltfRuntime, extension.values.emission, standardMaterial, "emissiveTexture", onError);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
standardMaterial.emissiveColor = Color3.FromArray(extension.values.emission || [0, 0, 0]);
|
|
standardMaterial.emissiveColor = Color3.FromArray(extension.values.emission || [0, 0, 0]);
|
|
@@ -148,26 +149,23 @@ module BABYLON {
|
|
|
|
|
|
// Specular
|
|
// Specular
|
|
if (typeof extension.values.specular === "string") {
|
|
if (typeof extension.values.specular === "string") {
|
|
- this._loadTexture(runtime, extension.values.specular, standardMaterial, "specularTexture", onError);
|
|
|
|
|
|
+ this._loadTexture(gltfRuntime, extension.values.specular, standardMaterial, "specularTexture", onError);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
standardMaterial.specularColor = Color3.FromArray(extension.values.specular || [0, 0, 0]);
|
|
standardMaterial.specularColor = Color3.FromArray(extension.values.specular || [0, 0, 0]);
|
|
}
|
|
}
|
|
- */
|
|
|
|
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
- /*
|
|
|
|
- private _loadTexture(runtime: IGLTFRuntime, id: string, material: StandardMaterial, propertyPath: string, onError: () => void): void {
|
|
|
|
|
|
+ private _loadTexture(gltfRuntime: IGLTFRuntime, id: string, material: StandardMaterial, propertyPath: string, onError: () => void): void {
|
|
// Create buffer from texture url
|
|
// Create buffer from texture url
|
|
- GLTFFileLoaderBase.LoadTextureBufferAsync(runtime, id, (buffer) => {
|
|
|
|
|
|
+ GLTFLoaderBase.LoadTextureBufferAsync(gltfRuntime, id, (buffer) => {
|
|
// Create texture from buffer
|
|
// Create texture from buffer
|
|
- GLTFFileLoaderBase.CreateTextureAsync(runtime, id, buffer, (texture) => material[propertyPath] = texture, onError);
|
|
|
|
|
|
+ GLTFLoaderBase.CreateTextureAsync(gltfRuntime, id, buffer, (texture) => material[propertyPath] = texture, onError);
|
|
}, onError);
|
|
}, onError);
|
|
}
|
|
}
|
|
- */
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- GLTFFileLoader.RegisterExtension(new GLTFMaterialsCommonExtension());
|
|
|
|
|
|
+ GLTFLoader.RegisterExtension(new GLTFMaterialsCommonExtension());
|
|
}
|
|
}
|