many updates - starting to make stable
parent
eefd4a9603
commit
be64682142
|
@ -1,20 +1,227 @@
|
||||||
/**
|
/**
|
||||||
* Creates a camera object
|
* Creates a camera object
|
||||||
* @param graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param apiCamera GameLib.D3.Camera.API
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Camera = function(graphics) {
|
GameLib.D3.Camera = function(
|
||||||
|
graphics,
|
||||||
|
apiCamera
|
||||||
|
) {
|
||||||
|
for (var property in apiCamera) {
|
||||||
|
if (apiCamera.hasOwnProperty(property)) {
|
||||||
|
this[property] = apiCamera[property];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
|
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
||||||
|
this.needsUpdate = false;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Raw Camera API object - should always correspond with the Camera Schema
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
|
* @param cameraType GameLib.D3.Camera.CAMERA_TYPE_*
|
||||||
|
* @param fov
|
||||||
|
* @param aspect
|
||||||
|
* @param near
|
||||||
|
* @param far
|
||||||
|
* @param position GameLib.D3.Vector3
|
||||||
|
* @param lookAt GameLib.D3.Vector3
|
||||||
|
* @param minX
|
||||||
|
* @param maxX
|
||||||
|
* @param minY
|
||||||
|
* @param maxY
|
||||||
|
* @param minZ
|
||||||
|
* @param maxZ
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Camera.API = function(
|
||||||
|
id,
|
||||||
|
cameraType,
|
||||||
|
name,
|
||||||
|
fov,
|
||||||
|
aspect,
|
||||||
|
near,
|
||||||
|
far,
|
||||||
|
position,
|
||||||
|
lookAt,
|
||||||
|
minX,
|
||||||
|
maxX,
|
||||||
|
minY,
|
||||||
|
maxY,
|
||||||
|
minZ,
|
||||||
|
maxZ
|
||||||
|
) {
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.D3.Tools.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(cameraType)) {
|
||||||
|
cameraType = GameLib.D3.Material.CAMERA_TYPE_PERSPECTIVE;
|
||||||
|
}
|
||||||
|
this.cameraType = cameraType;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Camera (' + cameraType + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(fov)) {
|
||||||
|
fov = 75;
|
||||||
|
}
|
||||||
|
this.fov = fov;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(aspect)) {
|
||||||
|
aspect = window.innerWidth / window.innerHeight;
|
||||||
|
}
|
||||||
|
this.aspect = aspect;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(near)) {
|
||||||
|
near = 0.1;
|
||||||
|
}
|
||||||
|
this.near = near;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(far)) {
|
||||||
|
far = 1000;
|
||||||
|
}
|
||||||
|
this.far = far;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(position)) {
|
||||||
|
position = new GameLib.D3.Vector3(
|
||||||
|
15,
|
||||||
|
15,
|
||||||
|
15
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.position = position;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(lookAt)) {
|
||||||
|
lookAt = new GameLib.D3.Vector3(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.lookAt = lookAt;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(minX)) {
|
||||||
|
minX = -100;
|
||||||
|
}
|
||||||
|
this.minX = minX;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(maxX)) {
|
||||||
|
maxX = 100;
|
||||||
|
}
|
||||||
|
this.maxX = maxX;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(minY)) {
|
||||||
|
minY = -100;
|
||||||
|
}
|
||||||
|
this.minY = minY;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(maxY)) {
|
||||||
|
maxY = 100;
|
||||||
|
}
|
||||||
|
this.maxY = maxY;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(minZ)) {
|
||||||
|
minZ = -100;
|
||||||
|
}
|
||||||
|
this.minZ = minZ;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(maxZ)) {
|
||||||
|
maxZ = 100;
|
||||||
|
}
|
||||||
|
this.maxZ = maxZ;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Camera types
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE = 0x1;
|
||||||
|
GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL = 0x2;
|
||||||
|
GameLib.D3.Camera.CAMERA_TYPE_STEREO = 0x3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a camera instance of 'graphics' type (only THREE for now)
|
* Creates a camera instance of 'graphics' type (only THREE for now)
|
||||||
* @returns {THREE.Camera}
|
* @returns {THREE.Camera}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Camera.prototype.createInstance = function() {
|
GameLib.D3.Camera.prototype.createInstance = function(update) {
|
||||||
return new this.graphics.instance.Camera();
|
|
||||||
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!instance ||
|
||||||
|
(instance && this.cameraType != instance.cameraType)
|
||||||
|
) {
|
||||||
|
if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE) {
|
||||||
|
instance = new this.graphics.instance.PerspectiveCamera(
|
||||||
|
this.fov,
|
||||||
|
this.aspect,
|
||||||
|
this.near,
|
||||||
|
this.far
|
||||||
|
);
|
||||||
|
} else if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL) {
|
||||||
|
instance = new this.graphics.instance.OrthographicCamera(
|
||||||
|
this.minX,
|
||||||
|
this.maxX,
|
||||||
|
this.minY,
|
||||||
|
this.maxY,
|
||||||
|
this.minZ,
|
||||||
|
this.maxZ
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (update && this.cameraType == instance.cameraType) {
|
||||||
|
instance.minX = this.minX;
|
||||||
|
instance.maxX = this.maxX;
|
||||||
|
instance.minY = this.minY;
|
||||||
|
instance.maxY = this.maxY;
|
||||||
|
instance.minZ = this.minZ;
|
||||||
|
instance.maxZ = this.maxZ;
|
||||||
|
instance.fov = this.fov;
|
||||||
|
instance.aspect = this.aspect;
|
||||||
|
instance.near = this.near;
|
||||||
|
instance.far = this.far;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance.cameraType = this.cameraType;
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.position.x = this.position.x;
|
||||||
|
instance.position.y = this.position.y;
|
||||||
|
instance.position.z = this.position.z;
|
||||||
|
|
||||||
|
instance.lookAt(
|
||||||
|
new this.graphics.instance.Vector3(
|
||||||
|
this.lookAt.x,
|
||||||
|
this.lookAt.y,
|
||||||
|
this.lookAt.z
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
instance.updateProjectionMatrix();
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Camera.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
};
|
};
|
|
@ -12,3 +12,16 @@ GameLib.D3.Color = function(r, g, b, a) {
|
||||||
this.b = b;
|
this.b = b;
|
||||||
this.a = a;
|
this.a = a;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the current color to HTML hex format (ex. #ffffff)
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Color.prototype.toHex = function() {
|
||||||
|
|
||||||
|
var rf = Math.floor(this.r == 1? 255 : this.r * 256.0).toString(16);
|
||||||
|
var gf = Math.floor(this.g == 1? 255 : this.g * 256.0).toString(16);
|
||||||
|
var bf = Math.floor(this.b == 1? 255 : this.b * 256.0).toString(16);
|
||||||
|
|
||||||
|
return '#' + rf + gf + bf;
|
||||||
|
};
|
|
@ -21,7 +21,7 @@ GameLib.D3.ImageFactory = function (graphics) {
|
||||||
return promiseList[url];
|
return promiseList[url];
|
||||||
}
|
}
|
||||||
|
|
||||||
var defer = q.defer();
|
var defer = Q.defer();
|
||||||
|
|
||||||
promiseList[url] = defer.promise;
|
promiseList[url] = defer.promise;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
/**
|
/**
|
||||||
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
|
* Light Superset - The apiLight properties get moved into the Light object itself, and then the instance is created
|
||||||
* @param id
|
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param apiLight GameLib.D3.Light.API
|
* @param apiLight GameLib.D3.Light.API
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Light = function(
|
GameLib.D3.Light = function(
|
||||||
id,
|
|
||||||
graphics,
|
graphics,
|
||||||
apiLight
|
apiLight
|
||||||
) {
|
) {
|
||||||
|
@ -73,11 +71,18 @@ GameLib.D3.Light.API = function(
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(color)) {
|
||||||
|
color = new GameLib.D3.Color(1,1,1,1);
|
||||||
|
}
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
|
||||||
|
if (GameLib.D3.Utils.UndefinedOrNull(intensity)) {
|
||||||
|
intensity = 1;
|
||||||
|
}
|
||||||
this.intensity = intensity;
|
this.intensity = intensity;
|
||||||
|
|
||||||
if (typeof position == 'undefined') {
|
if (typeof position == 'undefined') {
|
||||||
position = new GameLib.D3.Vector3(0,0,0);
|
position = new GameLib.D3.Vector3(0,10,0);
|
||||||
}
|
}
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
|
||||||
|
@ -140,34 +145,72 @@ GameLib.D3.Light.LIGHT_TYPE_SPOT = 0x4;
|
||||||
* Creates a light instance
|
* Creates a light instance
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Light.createInstance = function() {
|
GameLib.D3.Light.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!instance) ||
|
||||||
|
(instance && instance.lightType != this.lightType)) {
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_AMBIENT) {
|
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_AMBIENT) {
|
||||||
instance = new this.graphics.instance.AmbientLight(this.color, this.intensity);
|
instance = new this.graphics.instance.AmbientLight(
|
||||||
|
new this.graphics.instance.Color(
|
||||||
|
this.color.r,
|
||||||
|
this.color.g,
|
||||||
|
this.color.b
|
||||||
|
),
|
||||||
|
this.intensity
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
||||||
instance = new this.graphics.instance.DirectionalLight(this.color, this.intensity);
|
instance = new this.graphics.instance.DirectionalLight(
|
||||||
|
new this.graphics.instance.Color(
|
||||||
|
this.color.r,
|
||||||
|
this.color.g,
|
||||||
|
this.color.b
|
||||||
|
),
|
||||||
|
this.intensity
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
||||||
instance = new this.graphics.instance.PointLight(this.color, this.intensity);
|
instance = new this.graphics.instance.PointLight(
|
||||||
|
new this.graphics.instance.Color(
|
||||||
|
this.color.r,
|
||||||
|
this.color.g,
|
||||||
|
this.color.b
|
||||||
|
),
|
||||||
|
this.intensity
|
||||||
|
);
|
||||||
instance.distance = this.distance;
|
instance.distance = this.distance;
|
||||||
instance.decay = this.decay;
|
instance.decay = this.decay;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_SPOT ) {
|
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_SPOT ) {
|
||||||
instance = new this.graphics.instance.SpotLight(this.color, this.intensity);
|
instance = new this.graphics.instance.SpotLight(
|
||||||
|
new this.graphics.instance.Color(
|
||||||
|
this.color.r,
|
||||||
|
this.color.g,
|
||||||
|
this.color.b
|
||||||
|
),
|
||||||
|
this.intensity
|
||||||
|
);
|
||||||
instance.distance = this.distance;
|
instance.distance = this.distance;
|
||||||
instance.angle = this.angle;
|
instance.angle = this.angle;
|
||||||
instance.penumbra = this.penumbra;
|
instance.penumbra = this.penumbra;
|
||||||
instance.decay = this.decay;
|
instance.decay = this.decay;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
instance.gameLibObject = this;
|
instance.gameLibObject = this;
|
||||||
|
|
||||||
|
instance.name = this.name;
|
||||||
|
|
||||||
instance.position.x = this.position.x;
|
instance.position.x = this.position.x;
|
||||||
instance.position.y = this.position.y;
|
instance.position.y = this.position.y;
|
||||||
instance.position.z = this.position.z;
|
instance.position.z = this.position.z;
|
||||||
|
@ -178,3 +221,10 @@ GameLib.D3.Light.createInstance = function() {
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Light.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
|
@ -20,6 +20,8 @@ GameLib.D3.Material = function(
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
||||||
|
this.needsUpdate = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,7 +149,7 @@ GameLib.D3.Material.API = function(
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
if (typeof materialType == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(materialType)) {
|
||||||
materialType = GameLib.D3.Material.MATERIAL_TYPE_STANDARD;
|
materialType = GameLib.D3.Material.MATERIAL_TYPE_STANDARD;
|
||||||
}
|
}
|
||||||
this.materialType = materialType;
|
this.materialType = materialType;
|
||||||
|
@ -157,272 +159,272 @@ GameLib.D3.Material.API = function(
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
if (typeof opacity == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(opacity)) {
|
||||||
opacity = 1.0;
|
opacity = 1.0;
|
||||||
}
|
}
|
||||||
this.opacity = opacity;
|
this.opacity = opacity;
|
||||||
|
|
||||||
if (typeof side == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(side)) {
|
||||||
side = GameLib.D3.Material.TYPE_FRONT_SIDE;
|
side = GameLib.D3.Material.TYPE_FRONT_SIDE;
|
||||||
}
|
}
|
||||||
this.side = side;
|
this.side = side;
|
||||||
|
|
||||||
if (typeof transparent == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(transparent)) {
|
||||||
transparent = false;
|
transparent = false;
|
||||||
}
|
}
|
||||||
this.transparent = transparent;
|
this.transparent = transparent;
|
||||||
|
|
||||||
if (typeof maps == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(maps)) {
|
||||||
maps = new GameLib.D3.TextureMapTemplate.API();
|
maps = GameLib.D3.TextureMapTemplate.API();
|
||||||
}
|
}
|
||||||
this.maps = maps;
|
this.maps = maps;
|
||||||
|
|
||||||
if (typeof specular == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(specular)) {
|
||||||
specular = new GameLib.D3.Color(0.06, 0.06, 0.06, 0.06);
|
specular = new GameLib.D3.Color(0.06, 0.06, 0.06, 0.06);
|
||||||
}
|
}
|
||||||
this.specular = specular;
|
this.specular = specular;
|
||||||
|
|
||||||
if (typeof lightMapIntensity == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(lightMapIntensity)) {
|
||||||
lightMapIntensity = 1;
|
lightMapIntensity = 1;
|
||||||
}
|
}
|
||||||
this.lightMapIntensity = lightMapIntensity;
|
this.lightMapIntensity = lightMapIntensity;
|
||||||
|
|
||||||
if (typeof aoMapIntensity == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(aoMapIntensity)) {
|
||||||
aoMapIntensity = 1;
|
aoMapIntensity = 1;
|
||||||
}
|
}
|
||||||
this.aoMapIntensity = aoMapIntensity;
|
this.aoMapIntensity = aoMapIntensity;
|
||||||
|
|
||||||
if (typeof color == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(color)) {
|
||||||
color = new GameLib.D3.Color(1, 1, 1, 1)
|
color = new GameLib.D3.Color(1, 1, 1, 1)
|
||||||
}
|
}
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
|
||||||
if (typeof emissive == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(emissive)) {
|
||||||
emissive = new GameLib.D3.Color(0, 0, 0, 0);
|
emissive = new GameLib.D3.Color(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
this.emissive = emissive;
|
this.emissive = emissive;
|
||||||
|
|
||||||
if (typeof emissiveIntensity == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(emissiveIntensity)) {
|
||||||
emissiveIntensity = 1;
|
emissiveIntensity = 1;
|
||||||
}
|
}
|
||||||
this.emissiveIntensity = emissiveIntensity;
|
this.emissiveIntensity = emissiveIntensity;
|
||||||
|
|
||||||
if (typeof combine == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(combine)) {
|
||||||
combine = GameLib.D3.Material.TYPE_MULTIPLY_OPERATION;
|
combine = GameLib.D3.Material.TYPE_MULTIPLY_OPERATION;
|
||||||
}
|
}
|
||||||
this.combine = combine;
|
this.combine = combine;
|
||||||
|
|
||||||
if (typeof shininess == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(shininess)) {
|
||||||
shininess = 30;
|
shininess = 30;
|
||||||
}
|
}
|
||||||
this.shininess = shininess;
|
this.shininess = shininess;
|
||||||
|
|
||||||
if (typeof reflectivity == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(reflectivity)) {
|
||||||
reflectivity = 1;
|
reflectivity = 1;
|
||||||
}
|
}
|
||||||
this.reflectivity = reflectivity;
|
this.reflectivity = reflectivity;
|
||||||
|
|
||||||
if (typeof refractionRatio == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(refractionRatio)) {
|
||||||
refractionRatio = 0.98;
|
refractionRatio = 0.98;
|
||||||
}
|
}
|
||||||
this.refractionRatio = refractionRatio;
|
this.refractionRatio = refractionRatio;
|
||||||
|
|
||||||
if (typeof fog == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(fog)) {
|
||||||
fog = true;
|
fog = true;
|
||||||
}
|
}
|
||||||
this.fog = fog;
|
this.fog = fog;
|
||||||
|
|
||||||
if (typeof wireframe == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(wireframe)) {
|
||||||
wireframe = false;
|
wireframe = false;
|
||||||
}
|
}
|
||||||
this.wireframe = wireframe;
|
this.wireframe = wireframe;
|
||||||
|
|
||||||
if (typeof wireframeLineWidth == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(wireframeLineWidth)) {
|
||||||
wireframeLineWidth = 1;
|
wireframeLineWidth = 1;
|
||||||
}
|
}
|
||||||
this.wireframeLineWidth = wireframeLineWidth;
|
this.wireframeLineWidth = wireframeLineWidth;
|
||||||
|
|
||||||
if (typeof wireframeLineCap == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(wireframeLineCap)) {
|
||||||
wireframeLineCap = 'round';
|
wireframeLineCap = 'round';
|
||||||
}
|
}
|
||||||
this.wireframeLineCap = wireframeLineCap;
|
this.wireframeLineCap = wireframeLineCap;
|
||||||
|
|
||||||
if (typeof wireframeLineJoin == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(wireframeLineJoin)) {
|
||||||
wireframeLineJoin = 'round';
|
wireframeLineJoin = 'round';
|
||||||
}
|
}
|
||||||
this.wireframeLineJoin = wireframeLineJoin;
|
this.wireframeLineJoin = wireframeLineJoin;
|
||||||
|
|
||||||
if (typeof vertexColors == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(vertexColors)) {
|
||||||
vertexColors = GameLib.D3.Material.TYPE_NO_COLORS;
|
vertexColors = GameLib.D3.Material.TYPE_NO_COLORS;
|
||||||
}
|
}
|
||||||
this.vertexColors = vertexColors;
|
this.vertexColors = vertexColors;
|
||||||
|
|
||||||
if (typeof skinning == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(skinning)) {
|
||||||
skinning = false;
|
skinning = false;
|
||||||
}
|
}
|
||||||
this.skinning = skinning;
|
this.skinning = skinning;
|
||||||
|
|
||||||
if (typeof morphTargets == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(morphTargets)) {
|
||||||
morphTargets = false;
|
morphTargets = false;
|
||||||
}
|
}
|
||||||
this.morphTargets = morphTargets;
|
this.morphTargets = morphTargets;
|
||||||
|
|
||||||
if (typeof morphNormals == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(morphNormals)) {
|
||||||
morphNormals = false;
|
morphNormals = false;
|
||||||
}
|
}
|
||||||
this.morphNormals = morphNormals;
|
this.morphNormals = morphNormals;
|
||||||
|
|
||||||
if (typeof overdraw == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(overdraw)) {
|
||||||
overdraw = 0;
|
overdraw = 0;
|
||||||
}
|
}
|
||||||
this.overdraw = overdraw;
|
this.overdraw = overdraw;
|
||||||
|
|
||||||
if (typeof lineWidth == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(lineWidth)) {
|
||||||
lineWidth = 1;
|
lineWidth = 1;
|
||||||
}
|
}
|
||||||
this.lineWidth = lineWidth;
|
this.lineWidth = lineWidth;
|
||||||
|
|
||||||
if (typeof lineCap == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(lineCap)) {
|
||||||
lineCap = 'round';
|
lineCap = 'round';
|
||||||
}
|
}
|
||||||
this.lineCap = lineCap;
|
this.lineCap = lineCap;
|
||||||
|
|
||||||
if (typeof lineJoin == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(lineJoin)) {
|
||||||
lineJoin = 'round';
|
lineJoin = 'round';
|
||||||
}
|
}
|
||||||
this.lineJoin = lineJoin;
|
this.lineJoin = lineJoin;
|
||||||
|
|
||||||
if (typeof dashSize == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(dashSize)) {
|
||||||
dashSize = 3;
|
dashSize = 3;
|
||||||
}
|
}
|
||||||
this.dashSize = dashSize;
|
this.dashSize = dashSize;
|
||||||
|
|
||||||
if (typeof gapWidth == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(gapWidth)) {
|
||||||
gapWidth = 1;
|
gapWidth = 1;
|
||||||
}
|
}
|
||||||
this.gapWidth = gapWidth;
|
this.gapWidth = gapWidth;
|
||||||
|
|
||||||
if (typeof blending == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(blending)) {
|
||||||
blending = GameLib.D3.Material.TYPE_NORMAL_BLENDING;
|
blending = GameLib.D3.Material.TYPE_NORMAL_BLENDING;
|
||||||
}
|
}
|
||||||
this.blending = blending;
|
this.blending = blending;
|
||||||
|
|
||||||
if (typeof blendSrc == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(blendSrc)) {
|
||||||
blendSrc = GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR;
|
blendSrc = GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR;
|
||||||
}
|
}
|
||||||
this.blendSrc = blendSrc;
|
this.blendSrc = blendSrc;
|
||||||
|
|
||||||
if (typeof blendDst == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(blendDst)) {
|
||||||
blendDst = GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR;
|
blendDst = GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR;
|
||||||
}
|
}
|
||||||
this.blendDst = blendDst;
|
this.blendDst = blendDst;
|
||||||
|
|
||||||
if (typeof blendEquation == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(blendEquation)) {
|
||||||
blendEquation = GameLib.D3.Material.TYPE_ADD_EQUATION;
|
blendEquation = GameLib.D3.Material.TYPE_ADD_EQUATION;
|
||||||
}
|
}
|
||||||
this.blendEquation = blendEquation;
|
this.blendEquation = blendEquation;
|
||||||
|
|
||||||
if (typeof depthTest == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(depthTest)) {
|
||||||
depthTest = true;
|
depthTest = true;
|
||||||
}
|
}
|
||||||
this.depthTest = depthTest;
|
this.depthTest = depthTest;
|
||||||
|
|
||||||
if (typeof depthFunc == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(depthFunc)) {
|
||||||
depthFunc = GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH;
|
depthFunc = GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH;
|
||||||
}
|
}
|
||||||
this.depthFunc = depthFunc;
|
this.depthFunc = depthFunc;
|
||||||
|
|
||||||
if (typeof depthWrite == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(depthWrite)) {
|
||||||
depthWrite = true;
|
depthWrite = true;
|
||||||
}
|
}
|
||||||
this.depthWrite = depthWrite;
|
this.depthWrite = depthWrite;
|
||||||
|
|
||||||
if (typeof polygonOffset == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(polygonOffset)) {
|
||||||
polygonOffset = false;
|
polygonOffset = false;
|
||||||
}
|
}
|
||||||
this.polygonOffset = polygonOffset;
|
this.polygonOffset = polygonOffset;
|
||||||
|
|
||||||
if (typeof polygonOffsetFactor == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(polygonOffsetFactor)) {
|
||||||
polygonOffsetFactor = 1;
|
polygonOffsetFactor = 1;
|
||||||
}
|
}
|
||||||
this.polygonOffsetFactor = polygonOffsetFactor;
|
this.polygonOffsetFactor = polygonOffsetFactor;
|
||||||
|
|
||||||
if (typeof polygonOffsetUnits == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(polygonOffsetUnits)) {
|
||||||
polygonOffsetUnits = 1;
|
polygonOffsetUnits = 1;
|
||||||
}
|
}
|
||||||
this.polygonOffsetUnits = polygonOffsetUnits;
|
this.polygonOffsetUnits = polygonOffsetUnits;
|
||||||
|
|
||||||
if (typeof alphaTest == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(alphaTest)) {
|
||||||
alphaTest = 0;
|
alphaTest = 0;
|
||||||
}
|
}
|
||||||
this.alphaTest = alphaTest;
|
this.alphaTest = alphaTest;
|
||||||
|
|
||||||
if (typeof clippingPlanes == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(clippingPlanes)) {
|
||||||
clippingPlanes = [];
|
clippingPlanes = [];
|
||||||
}
|
}
|
||||||
this.clippingPlanes = clippingPlanes;
|
this.clippingPlanes = clippingPlanes;
|
||||||
|
|
||||||
if (typeof clipShadows == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(clipShadows)) {
|
||||||
clipShadows = false;
|
clipShadows = false;
|
||||||
}
|
}
|
||||||
this.clipShadows = clipShadows;
|
this.clipShadows = clipShadows;
|
||||||
|
|
||||||
if (typeof visible == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(visible)) {
|
||||||
visible = true;
|
visible = true;
|
||||||
}
|
}
|
||||||
this.visible = visible;
|
this.visible = visible;
|
||||||
|
|
||||||
if (typeof shading == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(shading)) {
|
||||||
shading = GameLib.D3.Material.TYPE_FLAT_SHADING;
|
shading = GameLib.D3.Material.TYPE_FLAT_SHADING;
|
||||||
}
|
}
|
||||||
this.shading = shading;
|
this.shading = shading;
|
||||||
|
|
||||||
if (typeof bumpScale == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(bumpScale)) {
|
||||||
bumpScale = 1;
|
bumpScale = 1;
|
||||||
}
|
}
|
||||||
this.bumpScale = bumpScale;
|
this.bumpScale = bumpScale;
|
||||||
|
|
||||||
if (typeof normalScale == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(normalScale)) {
|
||||||
normalScale = 1;
|
normalScale = 1;
|
||||||
}
|
}
|
||||||
this.normalScale = normalScale;
|
this.normalScale = normalScale;
|
||||||
|
|
||||||
if (typeof displacementScale == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(displacementScale)) {
|
||||||
displacementScale = 1;
|
displacementScale = 1;
|
||||||
}
|
}
|
||||||
this.displacementScale = displacementScale;
|
this.displacementScale = displacementScale;
|
||||||
|
|
||||||
if (typeof displacementBias == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(displacementBias)) {
|
||||||
displacementBias = 0;
|
displacementBias = 0;
|
||||||
}
|
}
|
||||||
this.displacementBias = displacementBias;
|
this.displacementBias = displacementBias;
|
||||||
|
|
||||||
if (typeof roughness == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(roughness)) {
|
||||||
roughness = 0.5;
|
roughness = 0.5;
|
||||||
}
|
}
|
||||||
this.roughness = roughness;
|
this.roughness = roughness;
|
||||||
|
|
||||||
if (typeof metalness == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(metalness)) {
|
||||||
metalness = 0.5;
|
metalness = 0.5;
|
||||||
}
|
}
|
||||||
this.metalness = metalness;
|
this.metalness = metalness;
|
||||||
|
|
||||||
if (typeof pointSize == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(pointSize)) {
|
||||||
pointSize = 1;
|
pointSize = 1;
|
||||||
}
|
}
|
||||||
this.pointSize = pointSize;
|
this.pointSize = pointSize;
|
||||||
|
|
||||||
if (typeof pointSizeAttenuation == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(pointSizeAttenuation)) {
|
||||||
pointSizeAttenuation = true;
|
pointSizeAttenuation = true;
|
||||||
}
|
}
|
||||||
this.pointSizeAttenuation = pointSizeAttenuation;
|
this.pointSizeAttenuation = pointSizeAttenuation;
|
||||||
|
|
||||||
if (typeof spriteRotation == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(spriteRotation)) {
|
||||||
spriteRotation = 0;
|
spriteRotation = 0;
|
||||||
}
|
}
|
||||||
this.spriteRotation = spriteRotation;
|
this.spriteRotation = spriteRotation;
|
||||||
|
|
||||||
if (typeof envMapIntensity == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(envMapIntensity)) {
|
||||||
envMapIntensity = 1.0;
|
envMapIntensity = 1.0;
|
||||||
}
|
}
|
||||||
this.envMapIntensity = envMapIntensity;
|
this.envMapIntensity = envMapIntensity;
|
||||||
|
@ -528,10 +530,19 @@ GameLib.D3.Material.MATERIAL_TYPE_MULTIPLE = "MultiMaterial";
|
||||||
* Material instance
|
* Material instance
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Material.prototype.createInstance = function() {
|
GameLib.D3.Material.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(!instance) ||
|
||||||
|
(instance && instance.materialType != this.materialType)
|
||||||
|
) {
|
||||||
|
|
||||||
if (this.materialType == GameLib.D3.Material.MATERIAL_TYPE_STANDARD) {
|
if (this.materialType == GameLib.D3.Material.MATERIAL_TYPE_STANDARD) {
|
||||||
|
|
||||||
instance = new this.graphics.instance.MeshStandardMaterial({
|
instance = new this.graphics.instance.MeshStandardMaterial({
|
||||||
|
@ -646,6 +657,14 @@ GameLib.D3.Material.prototype.createInstance = function() {
|
||||||
} else {
|
} else {
|
||||||
console.log("material type is not implemented yet: " + this.materialType + " - material indexes could be screwed up");
|
console.log("material type is not implemented yet: " + this.materialType + " - material indexes could be screwed up");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Material.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
|
@ -1,20 +1,15 @@
|
||||||
/**
|
/**
|
||||||
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
|
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
|
||||||
* @param id String
|
|
||||||
* @param name String
|
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param computeNormals Boolean
|
* @param computeNormals Boolean
|
||||||
* @param apiMesh GameLib.D3.Mesh.API
|
* @param apiMesh GameLib.D3.Mesh.API
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Mesh = function(
|
GameLib.D3.Mesh = function(
|
||||||
id,
|
|
||||||
name,
|
|
||||||
graphics,
|
graphics,
|
||||||
computeNormals,
|
computeNormals,
|
||||||
apiMesh
|
apiMesh
|
||||||
) {
|
) {
|
||||||
|
|
||||||
for (var property in apiMesh) {
|
for (var property in apiMesh) {
|
||||||
if (apiMesh.hasOwnProperty(property)) {
|
if (apiMesh.hasOwnProperty(property)) {
|
||||||
this[property] = apiMesh[property];
|
this[property] = apiMesh[property];
|
||||||
|
@ -27,7 +22,9 @@ GameLib.D3.Mesh = function(
|
||||||
|
|
||||||
this.computeNormals = computeNormals;
|
this.computeNormals = computeNormals;
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance(false);
|
||||||
|
|
||||||
|
this.needsUpdate = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,62 +92,62 @@ GameLib.D3.Mesh.API = function(
|
||||||
}
|
}
|
||||||
this.faces = faces;
|
this.faces = faces;
|
||||||
|
|
||||||
if (typeof parentMeshId == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(parentMeshId)) {
|
||||||
parentMeshId = null;
|
parentMeshId = null;
|
||||||
}
|
}
|
||||||
this.parentMeshId = parentMeshId;
|
this.parentMeshId = parentMeshId;
|
||||||
|
|
||||||
if (typeof parentSceneId == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(parentSceneId)) {
|
||||||
parentSceneId = null;
|
parentSceneId = null;
|
||||||
}
|
}
|
||||||
this.parentSceneId = parentSceneId;
|
this.parentSceneId = parentSceneId;
|
||||||
|
|
||||||
if (typeof skeleton == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(skeleton)) {
|
||||||
skeleton = null;
|
skeleton = null;
|
||||||
}
|
}
|
||||||
this.skeleton = skeleton;
|
this.skeleton = skeleton;
|
||||||
|
|
||||||
if (typeof faceVertexUvs == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(faceVertexUvs)) {
|
||||||
faceVertexUvs = [];
|
faceVertexUvs = [];
|
||||||
}
|
}
|
||||||
this.faceVertexUvs = faceVertexUvs;
|
this.faceVertexUvs = faceVertexUvs;
|
||||||
|
|
||||||
if (typeof skinIndices == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(skinIndices)) {
|
||||||
skinIndices = [];
|
skinIndices = [];
|
||||||
}
|
}
|
||||||
this.skinIndices = skinIndices;
|
this.skinIndices = skinIndices;
|
||||||
|
|
||||||
if (typeof skinWeights == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(skinWeights)) {
|
||||||
skinWeights = [];
|
skinWeights = [];
|
||||||
}
|
}
|
||||||
this.skinWeights = skinWeights;
|
this.skinWeights = skinWeights;
|
||||||
|
|
||||||
if (typeof materials == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(materials)) {
|
||||||
materials = [];
|
materials = [];
|
||||||
}
|
}
|
||||||
this.materials = materials;
|
this.materials = materials;
|
||||||
|
|
||||||
if (typeof position == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(position)) {
|
||||||
position = new GameLib.D3.Vector3(0,0,0);
|
position = new GameLib.D3.Vector3(0,0,0);
|
||||||
}
|
}
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
|
||||||
if (typeof quaternion == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(quaternion)) {
|
||||||
new GameLib.D3.Vector4();
|
quaternion = new GameLib.D3.Vector4();
|
||||||
}
|
}
|
||||||
this.quaternion = quaternion;
|
this.quaternion = quaternion;
|
||||||
|
|
||||||
if (typeof rotation == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(rotation)) {
|
||||||
rotation = new GameLib.D3.Vector3(0,0,0);
|
rotation = new GameLib.D3.Vector3(0,0,0);
|
||||||
}
|
}
|
||||||
this.rotation = rotation;
|
this.rotation = rotation;
|
||||||
|
|
||||||
if (typeof scale == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(scale)) {
|
||||||
scale = new GameLib.D3.Vector3(1,1,1);
|
scale = new GameLib.D3.Vector3(1,1,1);
|
||||||
}
|
}
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
|
|
||||||
if (typeof up == 'undefined') {
|
if (GameLib.D3.Utils.UndefinedOrNull(up)) {
|
||||||
up = new GameLib.D3.Vector3(0,1,0);
|
up = new GameLib.D3.Vector3(0,1,0);
|
||||||
}
|
}
|
||||||
this.up = up;
|
this.up = up;
|
||||||
|
@ -164,12 +161,17 @@ GameLib.D3.Mesh.TYPE_NORMAL = 0;
|
||||||
GameLib.D3.Mesh.TYPE_SKINNED = 1;
|
GameLib.D3.Mesh.TYPE_SKINNED = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a mesh instance
|
* Creates a mesh instance or updates it
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Mesh.prototype.createInstance = function() {
|
GameLib.D3.Mesh.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!update) {
|
||||||
var instanceGeometry = new this.graphics.instance.Geometry();
|
var instanceGeometry = new this.graphics.instance.Geometry();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -394,8 +396,7 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
console.log('cannot handle meshes of type ' + this.meshType + ' yet.');
|
console.log('cannot handle meshes of type ' + this.meshType + ' yet.');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.threeMeshId = instance.id;
|
|
||||||
|
|
||||||
instance.name = this.name;
|
instance.name = this.name;
|
||||||
|
|
||||||
|
@ -421,6 +422,10 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Mesh.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
GameLib.D3.prototype.invertWindingOrder = function(triangles) {
|
GameLib.D3.prototype.invertWindingOrder = function(triangles) {
|
||||||
|
|
||||||
for (var i = 0; i < triangles.length; i++) {
|
for (var i = 0; i < triangles.length; i++) {
|
||||||
|
|
|
@ -30,6 +30,8 @@ GameLib.D3.Scene = function(
|
||||||
this.progressCallback = progressCallback;
|
this.progressCallback = progressCallback;
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
||||||
|
this.needsUpdate = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,6 +186,7 @@ GameLib.D3.Scene.prototype.createInstance = function() {
|
||||||
* @param graphics
|
* @param graphics
|
||||||
* @param uploadUrl
|
* @param uploadUrl
|
||||||
* @param progressCallback
|
* @param progressCallback
|
||||||
|
* @param computeNormals
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Scene.LoadScene = function(
|
GameLib.D3.Scene.LoadScene = function(
|
||||||
|
@ -191,7 +194,8 @@ GameLib.D3.Scene.LoadScene = function(
|
||||||
onLoaded,
|
onLoaded,
|
||||||
graphics,
|
graphics,
|
||||||
uploadUrl,
|
uploadUrl,
|
||||||
progressCallback
|
progressCallback,
|
||||||
|
computeNormals
|
||||||
) {
|
) {
|
||||||
var entities = [];
|
var entities = [];
|
||||||
|
|
||||||
|
@ -281,7 +285,7 @@ GameLib.D3.Scene.LoadScene = function(
|
||||||
apiMaterial.opacity,
|
apiMaterial.opacity,
|
||||||
apiMaterial.side,
|
apiMaterial.side,
|
||||||
apiMaterial.transparent,
|
apiMaterial.transparent,
|
||||||
null,
|
GameLib.D3.TextureMapTemplate.API(),
|
||||||
new GameLib.D3.Color(
|
new GameLib.D3.Color(
|
||||||
apiMaterial.specular.r,
|
apiMaterial.specular.r,
|
||||||
apiMaterial.specular.g,
|
apiMaterial.specular.g,
|
||||||
|
@ -402,28 +406,31 @@ GameLib.D3.Scene.LoadScene = function(
|
||||||
}
|
}
|
||||||
|
|
||||||
var gameLibMesh = new GameLib.D3.Mesh(
|
var gameLibMesh = new GameLib.D3.Mesh(
|
||||||
apiMesh.id,
|
|
||||||
apiMesh.name,
|
|
||||||
graphics,
|
graphics,
|
||||||
false,
|
computeNormals,
|
||||||
|
new GameLib.D3.Mesh.API(
|
||||||
|
apiMesh.id,
|
||||||
apiMesh.meshType,
|
apiMesh.meshType,
|
||||||
|
apiMesh.name,
|
||||||
apiMesh.vertices,
|
apiMesh.vertices,
|
||||||
apiMesh.faces,
|
apiMesh.faces,
|
||||||
apiMesh.skeleton,
|
|
||||||
apiMesh.faceVertexUvs,
|
apiMesh.faceVertexUvs,
|
||||||
|
gameLibMaterials,
|
||||||
|
apiMesh.parentMeshId,
|
||||||
|
apiMesh.parentSceneId,
|
||||||
|
apiMesh.skeleton,
|
||||||
apiMesh.skinIndices,
|
apiMesh.skinIndices,
|
||||||
apiMesh.skinWeights,
|
apiMesh.skinWeights,
|
||||||
gameLibMaterials,
|
|
||||||
new GameLib.D3.Vector3(
|
new GameLib.D3.Vector3(
|
||||||
apiMesh.position.x,
|
apiMesh.position.x,
|
||||||
apiMesh.position.y,
|
apiMesh.position.y,
|
||||||
apiMesh.position.z
|
apiMesh.position.z
|
||||||
),
|
),
|
||||||
new GameLib.D3.Vector3(
|
new GameLib.D3.Vector4(
|
||||||
apiMesh.quaternion.w,
|
|
||||||
apiMesh.quaternion.x,
|
apiMesh.quaternion.x,
|
||||||
apiMesh.quaternion.y,
|
apiMesh.quaternion.y,
|
||||||
apiMesh.quaternion.z
|
apiMesh.quaternion.z,
|
||||||
|
apiMesh.quaternion.w
|
||||||
),
|
),
|
||||||
new GameLib.D3.Vector3(
|
new GameLib.D3.Vector3(
|
||||||
apiMesh.rotation.x,
|
apiMesh.rotation.x,
|
||||||
|
@ -439,9 +446,8 @@ GameLib.D3.Scene.LoadScene = function(
|
||||||
apiMesh.up.x,
|
apiMesh.up.x,
|
||||||
apiMesh.up.y,
|
apiMesh.up.y,
|
||||||
apiMesh.up.z
|
apiMesh.up.z
|
||||||
),
|
)
|
||||||
apiMesh.parentMeshId,
|
)
|
||||||
apiMesh.parentSceneId
|
|
||||||
);
|
);
|
||||||
|
|
||||||
gameLibMeshes.push(gameLibMesh);
|
gameLibMeshes.push(gameLibMesh);
|
||||||
|
@ -454,7 +460,7 @@ GameLib.D3.Scene.LoadScene = function(
|
||||||
scene.id,
|
scene.id,
|
||||||
scene.path,
|
scene.path,
|
||||||
scene.name,
|
scene.name,
|
||||||
scene.meshes,
|
gameLibMeshes,
|
||||||
new GameLib.D3.Vector4(
|
new GameLib.D3.Vector4(
|
||||||
scene.quaternion.x,
|
scene.quaternion.x,
|
||||||
scene.quaternion.y,
|
scene.quaternion.y,
|
||||||
|
@ -534,7 +540,7 @@ GameLib.D3.Scene.LoadSceneFromApi = function(
|
||||||
|
|
||||||
var scene = response.scene[0];
|
var scene = response.scene[0];
|
||||||
|
|
||||||
GameLib.D3.Scene.LoadScene(scene, onLoaded, graphics, uploadUrl, progressCallback);
|
GameLib.D3.Scene.LoadScene(scene, onLoaded, graphics, uploadUrl, progressCallback, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(xhr);
|
}(xhr);
|
||||||
|
|
|
@ -38,6 +38,9 @@ GameLib.D3.Texture = function(
|
||||||
function (imageInstance){
|
function (imageInstance){
|
||||||
this.imageInstance = imageInstance;
|
this.imageInstance = imageInstance;
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
||||||
|
this.needsUpdate = false;
|
||||||
|
|
||||||
this.parentMaterial[this.parentMaterialInstanceMapId] = this.instance;
|
this.parentMaterial[this.parentMaterialInstanceMapId] = this.instance;
|
||||||
this.parentMaterial.needsUpdate = true;
|
this.parentMaterial.needsUpdate = true;
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
|
@ -267,9 +270,14 @@ GameLib.D3.Texture.TYPE_RGBD_ENCODING = 3006; // MAXRANGE IS 256.
|
||||||
* Creates an instance of our texture object
|
* Creates an instance of our texture object
|
||||||
* @returns {GameLib.D3.Texture|THREE.SoftwareRenderer.Texture|THREE.Texture|*|Texture}
|
* @returns {GameLib.D3.Texture|THREE.SoftwareRenderer.Texture|THREE.Texture|*|Texture}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Texture.prototype.createInstance = function() {
|
GameLib.D3.Texture.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
var instance = new this.graphics.instance.Texture(
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
} else {
|
||||||
|
instance = new this.graphics.instance.Texture(
|
||||||
this.imageInstance,
|
this.imageInstance,
|
||||||
this.mapping,
|
this.mapping,
|
||||||
this.wrapS,
|
this.wrapS,
|
||||||
|
@ -280,6 +288,7 @@ GameLib.D3.Texture.prototype.createInstance = function() {
|
||||||
undefined,
|
undefined,
|
||||||
this.anisotropy
|
this.anisotropy
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
instance.name = this.name;
|
instance.name = this.name;
|
||||||
instance.flipY = this.flipY;
|
instance.flipY = this.flipY;
|
||||||
|
@ -294,3 +303,10 @@ GameLib.D3.Texture.prototype.createInstance = function() {
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Texture.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ GameLib.D3.Vector4 = function(x, y, z, w) {
|
||||||
this.x = 0;
|
this.x = 0;
|
||||||
this.y = 0;
|
this.y = 0;
|
||||||
this.z = 0;
|
this.z = 0;
|
||||||
this.w = 0;
|
this.w = 1;
|
||||||
|
|
||||||
if (x) {
|
if (x) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
|
|
Loading…
Reference in New Issue