many updates - starting to make stable
parent
eefd4a9603
commit
be64682142
|
@ -1,20 +1,227 @@
|
|||
/**
|
||||
* Creates a camera object
|
||||
* @param graphics
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param apiCamera GameLib.D3.Camera.API
|
||||
* @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.isNotThreeThrow();
|
||||
|
||||
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)
|
||||
* @returns {THREE.Camera}
|
||||
*/
|
||||
GameLib.D3.Camera.prototype.createInstance = function() {
|
||||
return new this.graphics.instance.Camera();
|
||||
GameLib.D3.Camera.prototype.createInstance = function(update) {
|
||||
|
||||
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.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];
|
||||
}
|
||||
|
||||
var defer = q.defer();
|
||||
var defer = Q.defer();
|
||||
|
||||
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
|
||||
* @param id
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param apiLight GameLib.D3.Light.API
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Light = function(
|
||||
id,
|
||||
graphics,
|
||||
apiLight
|
||||
) {
|
||||
|
@ -73,11 +71,18 @@ GameLib.D3.Light.API = function(
|
|||
}
|
||||
this.name = name;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(color)) {
|
||||
color = new GameLib.D3.Color(1,1,1,1);
|
||||
}
|
||||
this.color = color;
|
||||
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(intensity)) {
|
||||
intensity = 1;
|
||||
}
|
||||
this.intensity = intensity;
|
||||
|
||||
if (typeof position == 'undefined') {
|
||||
position = new GameLib.D3.Vector3(0,0,0);
|
||||
position = new GameLib.D3.Vector3(0,10,0);
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
|
@ -140,34 +145,72 @@ GameLib.D3.Light.LIGHT_TYPE_SPOT = 0x4;
|
|||
* Creates a light instance
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Light.createInstance = function() {
|
||||
GameLib.D3.Light.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
}
|
||||
|
||||
if ((!instance) ||
|
||||
(instance && instance.lightType != this.lightType)) {
|
||||
|
||||
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) {
|
||||
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) {
|
||||
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.decay = this.decay;
|
||||
}
|
||||
|
||||
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.angle = this.angle;
|
||||
instance.penumbra = this.penumbra;
|
||||
instance.decay = this.decay;
|
||||
}
|
||||
}
|
||||
|
||||
instance.gameLibObject = this;
|
||||
|
||||
instance.name = this.name;
|
||||
|
||||
instance.position.x = this.position.x;
|
||||
instance.position.y = this.position.y;
|
||||
instance.position.z = this.position.z;
|
||||
|
@ -178,3 +221,10 @@ GameLib.D3.Light.createInstance = function() {
|
|||
|
||||
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.instance = this.createInstance();
|
||||
|
||||
this.needsUpdate = false;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -147,7 +149,7 @@ GameLib.D3.Material.API = function(
|
|||
}
|
||||
this.id = id;
|
||||
|
||||
if (typeof materialType == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(materialType)) {
|
||||
materialType = GameLib.D3.Material.MATERIAL_TYPE_STANDARD;
|
||||
}
|
||||
this.materialType = materialType;
|
||||
|
@ -157,272 +159,272 @@ GameLib.D3.Material.API = function(
|
|||
}
|
||||
this.name = name;
|
||||
|
||||
if (typeof opacity == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(opacity)) {
|
||||
opacity = 1.0;
|
||||
}
|
||||
this.opacity = opacity;
|
||||
|
||||
if (typeof side == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(side)) {
|
||||
side = GameLib.D3.Material.TYPE_FRONT_SIDE;
|
||||
}
|
||||
this.side = side;
|
||||
|
||||
if (typeof transparent == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(transparent)) {
|
||||
transparent = false;
|
||||
}
|
||||
this.transparent = transparent;
|
||||
|
||||
if (typeof maps == 'undefined') {
|
||||
maps = new GameLib.D3.TextureMapTemplate.API();
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(maps)) {
|
||||
maps = GameLib.D3.TextureMapTemplate.API();
|
||||
}
|
||||
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);
|
||||
}
|
||||
this.specular = specular;
|
||||
|
||||
if (typeof lightMapIntensity == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(lightMapIntensity)) {
|
||||
lightMapIntensity = 1;
|
||||
}
|
||||
this.lightMapIntensity = lightMapIntensity;
|
||||
|
||||
if (typeof aoMapIntensity == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(aoMapIntensity)) {
|
||||
aoMapIntensity = 1;
|
||||
}
|
||||
this.aoMapIntensity = aoMapIntensity;
|
||||
|
||||
if (typeof color == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(color)) {
|
||||
color = new GameLib.D3.Color(1, 1, 1, 1)
|
||||
}
|
||||
this.color = color;
|
||||
|
||||
if (typeof emissive == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(emissive)) {
|
||||
emissive = new GameLib.D3.Color(0, 0, 0, 0);
|
||||
}
|
||||
this.emissive = emissive;
|
||||
|
||||
if (typeof emissiveIntensity == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(emissiveIntensity)) {
|
||||
emissiveIntensity = 1;
|
||||
}
|
||||
this.emissiveIntensity = emissiveIntensity;
|
||||
|
||||
if (typeof combine == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(combine)) {
|
||||
combine = GameLib.D3.Material.TYPE_MULTIPLY_OPERATION;
|
||||
}
|
||||
this.combine = combine;
|
||||
|
||||
if (typeof shininess == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(shininess)) {
|
||||
shininess = 30;
|
||||
}
|
||||
this.shininess = shininess;
|
||||
|
||||
if (typeof reflectivity == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(reflectivity)) {
|
||||
reflectivity = 1;
|
||||
}
|
||||
this.reflectivity = reflectivity;
|
||||
|
||||
if (typeof refractionRatio == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(refractionRatio)) {
|
||||
refractionRatio = 0.98;
|
||||
}
|
||||
this.refractionRatio = refractionRatio;
|
||||
|
||||
if (typeof fog == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(fog)) {
|
||||
fog = true;
|
||||
}
|
||||
this.fog = fog;
|
||||
|
||||
if (typeof wireframe == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(wireframe)) {
|
||||
wireframe = false;
|
||||
}
|
||||
this.wireframe = wireframe;
|
||||
|
||||
if (typeof wireframeLineWidth == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(wireframeLineWidth)) {
|
||||
wireframeLineWidth = 1;
|
||||
}
|
||||
this.wireframeLineWidth = wireframeLineWidth;
|
||||
|
||||
if (typeof wireframeLineCap == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(wireframeLineCap)) {
|
||||
wireframeLineCap = 'round';
|
||||
}
|
||||
this.wireframeLineCap = wireframeLineCap;
|
||||
|
||||
if (typeof wireframeLineJoin == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(wireframeLineJoin)) {
|
||||
wireframeLineJoin = 'round';
|
||||
}
|
||||
this.wireframeLineJoin = wireframeLineJoin;
|
||||
|
||||
if (typeof vertexColors == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(vertexColors)) {
|
||||
vertexColors = GameLib.D3.Material.TYPE_NO_COLORS;
|
||||
}
|
||||
this.vertexColors = vertexColors;
|
||||
|
||||
if (typeof skinning == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(skinning)) {
|
||||
skinning = false;
|
||||
}
|
||||
this.skinning = skinning;
|
||||
|
||||
if (typeof morphTargets == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(morphTargets)) {
|
||||
morphTargets = false;
|
||||
}
|
||||
this.morphTargets = morphTargets;
|
||||
|
||||
if (typeof morphNormals == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(morphNormals)) {
|
||||
morphNormals = false;
|
||||
}
|
||||
this.morphNormals = morphNormals;
|
||||
|
||||
if (typeof overdraw == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(overdraw)) {
|
||||
overdraw = 0;
|
||||
}
|
||||
this.overdraw = overdraw;
|
||||
|
||||
if (typeof lineWidth == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(lineWidth)) {
|
||||
lineWidth = 1;
|
||||
}
|
||||
this.lineWidth = lineWidth;
|
||||
|
||||
if (typeof lineCap == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(lineCap)) {
|
||||
lineCap = 'round';
|
||||
}
|
||||
this.lineCap = lineCap;
|
||||
|
||||
if (typeof lineJoin == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(lineJoin)) {
|
||||
lineJoin = 'round';
|
||||
}
|
||||
this.lineJoin = lineJoin;
|
||||
|
||||
if (typeof dashSize == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(dashSize)) {
|
||||
dashSize = 3;
|
||||
}
|
||||
this.dashSize = dashSize;
|
||||
|
||||
if (typeof gapWidth == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(gapWidth)) {
|
||||
gapWidth = 1;
|
||||
}
|
||||
this.gapWidth = gapWidth;
|
||||
|
||||
if (typeof blending == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(blending)) {
|
||||
blending = GameLib.D3.Material.TYPE_NORMAL_BLENDING;
|
||||
}
|
||||
this.blending = blending;
|
||||
|
||||
if (typeof blendSrc == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(blendSrc)) {
|
||||
blendSrc = GameLib.D3.Material.TYPE_SRC_ALPHA_FACTOR;
|
||||
}
|
||||
this.blendSrc = blendSrc;
|
||||
|
||||
if (typeof blendDst == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(blendDst)) {
|
||||
blendDst = GameLib.D3.Material.TYPE_ONE_MINUS_SRC_ALPHA_FACTOR;
|
||||
}
|
||||
this.blendDst = blendDst;
|
||||
|
||||
if (typeof blendEquation == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(blendEquation)) {
|
||||
blendEquation = GameLib.D3.Material.TYPE_ADD_EQUATION;
|
||||
}
|
||||
this.blendEquation = blendEquation;
|
||||
|
||||
if (typeof depthTest == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(depthTest)) {
|
||||
depthTest = true;
|
||||
}
|
||||
this.depthTest = depthTest;
|
||||
|
||||
if (typeof depthFunc == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(depthFunc)) {
|
||||
depthFunc = GameLib.D3.Material.TYPE_LESS_EQUAL_DEPTH;
|
||||
}
|
||||
this.depthFunc = depthFunc;
|
||||
|
||||
if (typeof depthWrite == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(depthWrite)) {
|
||||
depthWrite = true;
|
||||
}
|
||||
this.depthWrite = depthWrite;
|
||||
|
||||
if (typeof polygonOffset == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(polygonOffset)) {
|
||||
polygonOffset = false;
|
||||
}
|
||||
this.polygonOffset = polygonOffset;
|
||||
|
||||
if (typeof polygonOffsetFactor == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(polygonOffsetFactor)) {
|
||||
polygonOffsetFactor = 1;
|
||||
}
|
||||
this.polygonOffsetFactor = polygonOffsetFactor;
|
||||
|
||||
if (typeof polygonOffsetUnits == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(polygonOffsetUnits)) {
|
||||
polygonOffsetUnits = 1;
|
||||
}
|
||||
this.polygonOffsetUnits = polygonOffsetUnits;
|
||||
|
||||
if (typeof alphaTest == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(alphaTest)) {
|
||||
alphaTest = 0;
|
||||
}
|
||||
this.alphaTest = alphaTest;
|
||||
|
||||
if (typeof clippingPlanes == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(clippingPlanes)) {
|
||||
clippingPlanes = [];
|
||||
}
|
||||
this.clippingPlanes = clippingPlanes;
|
||||
|
||||
if (typeof clipShadows == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(clipShadows)) {
|
||||
clipShadows = false;
|
||||
}
|
||||
this.clipShadows = clipShadows;
|
||||
|
||||
if (typeof visible == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(visible)) {
|
||||
visible = true;
|
||||
}
|
||||
this.visible = visible;
|
||||
|
||||
if (typeof shading == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(shading)) {
|
||||
shading = GameLib.D3.Material.TYPE_FLAT_SHADING;
|
||||
}
|
||||
this.shading = shading;
|
||||
|
||||
if (typeof bumpScale == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(bumpScale)) {
|
||||
bumpScale = 1;
|
||||
}
|
||||
this.bumpScale = bumpScale;
|
||||
|
||||
if (typeof normalScale == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(normalScale)) {
|
||||
normalScale = 1;
|
||||
}
|
||||
this.normalScale = normalScale;
|
||||
|
||||
if (typeof displacementScale == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(displacementScale)) {
|
||||
displacementScale = 1;
|
||||
}
|
||||
this.displacementScale = displacementScale;
|
||||
|
||||
if (typeof displacementBias == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(displacementBias)) {
|
||||
displacementBias = 0;
|
||||
}
|
||||
this.displacementBias = displacementBias;
|
||||
|
||||
if (typeof roughness == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(roughness)) {
|
||||
roughness = 0.5;
|
||||
}
|
||||
this.roughness = roughness;
|
||||
|
||||
if (typeof metalness == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(metalness)) {
|
||||
metalness = 0.5;
|
||||
}
|
||||
this.metalness = metalness;
|
||||
|
||||
if (typeof pointSize == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(pointSize)) {
|
||||
pointSize = 1;
|
||||
}
|
||||
this.pointSize = pointSize;
|
||||
|
||||
if (typeof pointSizeAttenuation == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(pointSizeAttenuation)) {
|
||||
pointSizeAttenuation = true;
|
||||
}
|
||||
this.pointSizeAttenuation = pointSizeAttenuation;
|
||||
|
||||
if (typeof spriteRotation == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(spriteRotation)) {
|
||||
spriteRotation = 0;
|
||||
}
|
||||
this.spriteRotation = spriteRotation;
|
||||
|
||||
if (typeof envMapIntensity == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(envMapIntensity)) {
|
||||
envMapIntensity = 1.0;
|
||||
}
|
||||
this.envMapIntensity = envMapIntensity;
|
||||
|
@ -528,10 +530,19 @@ GameLib.D3.Material.MATERIAL_TYPE_MULTIPLE = "MultiMaterial";
|
|||
* Material instance
|
||||
* @returns {*}
|
||||
*/
|
||||
GameLib.D3.Material.prototype.createInstance = function() {
|
||||
GameLib.D3.Material.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
}
|
||||
|
||||
if (
|
||||
(!instance) ||
|
||||
(instance && instance.materialType != this.materialType)
|
||||
) {
|
||||
|
||||
if (this.materialType == GameLib.D3.Material.MATERIAL_TYPE_STANDARD) {
|
||||
|
||||
instance = new this.graphics.instance.MeshStandardMaterial({
|
||||
|
@ -646,6 +657,14 @@ GameLib.D3.Material.prototype.createInstance = function() {
|
|||
} else {
|
||||
console.log("material type is not implemented yet: " + this.materialType + " - material indexes could be screwed up");
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param computeNormals Boolean
|
||||
* @param apiMesh GameLib.D3.Mesh.API
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Mesh = function(
|
||||
id,
|
||||
name,
|
||||
graphics,
|
||||
computeNormals,
|
||||
apiMesh
|
||||
) {
|
||||
|
||||
for (var property in apiMesh) {
|
||||
if (apiMesh.hasOwnProperty(property)) {
|
||||
this[property] = apiMesh[property];
|
||||
|
@ -27,7 +22,9 @@ GameLib.D3.Mesh = function(
|
|||
|
||||
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;
|
||||
|
||||
if (typeof parentMeshId == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(parentMeshId)) {
|
||||
parentMeshId = null;
|
||||
}
|
||||
this.parentMeshId = parentMeshId;
|
||||
|
||||
if (typeof parentSceneId == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(parentSceneId)) {
|
||||
parentSceneId = null;
|
||||
}
|
||||
this.parentSceneId = parentSceneId;
|
||||
|
||||
if (typeof skeleton == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(skeleton)) {
|
||||
skeleton = null;
|
||||
}
|
||||
this.skeleton = skeleton;
|
||||
|
||||
if (typeof faceVertexUvs == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(faceVertexUvs)) {
|
||||
faceVertexUvs = [];
|
||||
}
|
||||
this.faceVertexUvs = faceVertexUvs;
|
||||
|
||||
if (typeof skinIndices == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(skinIndices)) {
|
||||
skinIndices = [];
|
||||
}
|
||||
this.skinIndices = skinIndices;
|
||||
|
||||
if (typeof skinWeights == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(skinWeights)) {
|
||||
skinWeights = [];
|
||||
}
|
||||
this.skinWeights = skinWeights;
|
||||
|
||||
if (typeof materials == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(materials)) {
|
||||
materials = [];
|
||||
}
|
||||
this.materials = materials;
|
||||
|
||||
if (typeof position == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(position)) {
|
||||
position = new GameLib.D3.Vector3(0,0,0);
|
||||
}
|
||||
this.position = position;
|
||||
|
||||
if (typeof quaternion == 'undefined') {
|
||||
new GameLib.D3.Vector4();
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(quaternion)) {
|
||||
quaternion = new GameLib.D3.Vector4();
|
||||
}
|
||||
this.quaternion = quaternion;
|
||||
|
||||
if (typeof rotation == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(rotation)) {
|
||||
rotation = new GameLib.D3.Vector3(0,0,0);
|
||||
}
|
||||
this.rotation = rotation;
|
||||
|
||||
if (typeof scale == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(scale)) {
|
||||
scale = new GameLib.D3.Vector3(1,1,1);
|
||||
}
|
||||
this.scale = scale;
|
||||
|
||||
if (typeof up == 'undefined') {
|
||||
if (GameLib.D3.Utils.UndefinedOrNull(up)) {
|
||||
up = new GameLib.D3.Vector3(0,1,0);
|
||||
}
|
||||
this.up = up;
|
||||
|
@ -164,12 +161,17 @@ GameLib.D3.Mesh.TYPE_NORMAL = 0;
|
|||
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;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
}
|
||||
|
||||
if (!update) {
|
||||
var instanceGeometry = new this.graphics.instance.Geometry();
|
||||
|
||||
/**
|
||||
|
@ -394,8 +396,7 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
|||
if (instance == null) {
|
||||
console.log('cannot handle meshes of type ' + this.meshType + ' yet.');
|
||||
}
|
||||
|
||||
this.threeMeshId = instance.id;
|
||||
}
|
||||
|
||||
instance.name = this.name;
|
||||
|
||||
|
@ -421,6 +422,10 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
|||
return instance;
|
||||
};
|
||||
|
||||
GameLib.D3.Mesh.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
};
|
||||
|
||||
GameLib.D3.prototype.invertWindingOrder = function(triangles) {
|
||||
|
||||
for (var i = 0; i < triangles.length; i++) {
|
||||
|
|
|
@ -30,6 +30,8 @@ GameLib.D3.Scene = function(
|
|||
this.progressCallback = progressCallback;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
|
||||
this.needsUpdate = false;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -184,6 +186,7 @@ GameLib.D3.Scene.prototype.createInstance = function() {
|
|||
* @param graphics
|
||||
* @param uploadUrl
|
||||
* @param progressCallback
|
||||
* @param computeNormals
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Scene.LoadScene = function(
|
||||
|
@ -191,7 +194,8 @@ GameLib.D3.Scene.LoadScene = function(
|
|||
onLoaded,
|
||||
graphics,
|
||||
uploadUrl,
|
||||
progressCallback
|
||||
progressCallback,
|
||||
computeNormals
|
||||
) {
|
||||
var entities = [];
|
||||
|
||||
|
@ -281,7 +285,7 @@ GameLib.D3.Scene.LoadScene = function(
|
|||
apiMaterial.opacity,
|
||||
apiMaterial.side,
|
||||
apiMaterial.transparent,
|
||||
null,
|
||||
GameLib.D3.TextureMapTemplate.API(),
|
||||
new GameLib.D3.Color(
|
||||
apiMaterial.specular.r,
|
||||
apiMaterial.specular.g,
|
||||
|
@ -402,28 +406,31 @@ GameLib.D3.Scene.LoadScene = function(
|
|||
}
|
||||
|
||||
var gameLibMesh = new GameLib.D3.Mesh(
|
||||
apiMesh.id,
|
||||
apiMesh.name,
|
||||
graphics,
|
||||
false,
|
||||
computeNormals,
|
||||
new GameLib.D3.Mesh.API(
|
||||
apiMesh.id,
|
||||
apiMesh.meshType,
|
||||
apiMesh.name,
|
||||
apiMesh.vertices,
|
||||
apiMesh.faces,
|
||||
apiMesh.skeleton,
|
||||
apiMesh.faceVertexUvs,
|
||||
gameLibMaterials,
|
||||
apiMesh.parentMeshId,
|
||||
apiMesh.parentSceneId,
|
||||
apiMesh.skeleton,
|
||||
apiMesh.skinIndices,
|
||||
apiMesh.skinWeights,
|
||||
gameLibMaterials,
|
||||
new GameLib.D3.Vector3(
|
||||
apiMesh.position.x,
|
||||
apiMesh.position.y,
|
||||
apiMesh.position.z
|
||||
),
|
||||
new GameLib.D3.Vector3(
|
||||
apiMesh.quaternion.w,
|
||||
new GameLib.D3.Vector4(
|
||||
apiMesh.quaternion.x,
|
||||
apiMesh.quaternion.y,
|
||||
apiMesh.quaternion.z
|
||||
apiMesh.quaternion.z,
|
||||
apiMesh.quaternion.w
|
||||
),
|
||||
new GameLib.D3.Vector3(
|
||||
apiMesh.rotation.x,
|
||||
|
@ -439,9 +446,8 @@ GameLib.D3.Scene.LoadScene = function(
|
|||
apiMesh.up.x,
|
||||
apiMesh.up.y,
|
||||
apiMesh.up.z
|
||||
),
|
||||
apiMesh.parentMeshId,
|
||||
apiMesh.parentSceneId
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
gameLibMeshes.push(gameLibMesh);
|
||||
|
@ -454,7 +460,7 @@ GameLib.D3.Scene.LoadScene = function(
|
|||
scene.id,
|
||||
scene.path,
|
||||
scene.name,
|
||||
scene.meshes,
|
||||
gameLibMeshes,
|
||||
new GameLib.D3.Vector4(
|
||||
scene.quaternion.x,
|
||||
scene.quaternion.y,
|
||||
|
@ -534,7 +540,7 @@ GameLib.D3.Scene.LoadSceneFromApi = function(
|
|||
|
||||
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);
|
||||
|
|
|
@ -38,6 +38,9 @@ GameLib.D3.Texture = function(
|
|||
function (imageInstance){
|
||||
this.imageInstance = imageInstance;
|
||||
this.instance = this.createInstance();
|
||||
|
||||
this.needsUpdate = false;
|
||||
|
||||
this.parentMaterial[this.parentMaterialInstanceMapId] = this.instance;
|
||||
this.parentMaterial.needsUpdate = true;
|
||||
}.bind(this),
|
||||
|
@ -267,9 +270,14 @@ GameLib.D3.Texture.TYPE_RGBD_ENCODING = 3006; // MAXRANGE IS 256.
|
|||
* Creates an instance of our texture object
|
||||
* @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.mapping,
|
||||
this.wrapS,
|
||||
|
@ -280,6 +288,7 @@ GameLib.D3.Texture.prototype.createInstance = function() {
|
|||
undefined,
|
||||
this.anisotropy
|
||||
);
|
||||
}
|
||||
|
||||
instance.name = this.name;
|
||||
instance.flipY = this.flipY;
|
||||
|
@ -294,3 +303,10 @@ GameLib.D3.Texture.prototype.createInstance = function() {
|
|||
|
||||
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.y = 0;
|
||||
this.z = 0;
|
||||
this.w = 0;
|
||||
this.w = 1;
|
||||
|
||||
if (x) {
|
||||
this.x = x;
|
||||
|
|
Loading…
Reference in New Issue