points material, raw shader, fixed aspect ratios for orthographic cams

beta.r3js.org
-=yb4f310 2018-02-13 15:52:51 +01:00
parent e06f7094ce
commit 3b18b59852
26 changed files with 685 additions and 186 deletions

View File

@ -397,8 +397,10 @@ GameLib.Component.SHADER = 0x9e;
GameLib.Component.SHADER_VERTEX = 0x9f;
GameLib.Component.SHADER_FRAGMENT = 0xa0;
GameLib.Component.GEOMETRY_BUFFER_INSTANCED = 0xa1;
GameLib.Component.MATERIAL_SHADER_RAW = 0xa2;
GameLib.Component.MATERIAL_POINTS = 0xa3;
GameLib.Component.MAX_COMPONENTS = 0xa2;
GameLib.Component.MAX_COMPONENTS = 0xa4;
GameLib.Component.GRAPHICS_RUNTIME = 0x1;
GameLib.Component.PHYSICS_RUNTIME = 0x2;
@ -1385,6 +1387,18 @@ GameLib.Component.GetComponentInfo = function(number) {
constructor : GameLib.D3.Geometry.Buffer.Instanced,
apiConstructor : GameLib.D3.API.Geometry.Buffer.Instanced
};
case 0xa2 : return {
name : 'GameLib.D3.Material.Shader.Raw',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Material.Shader.Raw,
apiConstructor : GameLib.D3.API.Material.Shader.Raw
};
case 0xa3 : return {
name : 'GameLib.D3.Material.Points',
runtime : GameLib.Component.GRAPHICS_RUNTIME,
constructor : GameLib.D3.Material.Points,
apiConstructor : GameLib.D3.API.Material.Points
};
break;
}

View File

@ -67,7 +67,7 @@ GameLib.Controls.prototype.updateInstance = function(property) {
);
}
console.log('default controls update instance');
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -98,7 +98,7 @@ GameLib.Controls.D3.Editor.prototype.updateInstance = function(property) {
console.warn('an update instance was called on editor controls - which, if not called from within a running system at the right time will affect the order of input event handling and cause system instability');
GameLib.Controls.prototype.updateInstance.call(this);
GameLib.Controls.prototype.updateInstance.call(this, property);
};
/**

View File

@ -46,8 +46,8 @@ GameLib.Controls.Keyboard.prototype.createInstance = function() {
/**
* Update Instance
*/
GameLib.Controls.Keyboard.prototype.updateInstance = function() {
GameLib.Controls.prototype.updateInstance.call(this);
GameLib.Controls.Keyboard.prototype.updateInstance = function(property) {
GameLib.Controls.prototype.updateInstance.call(this, property);
};
/**

View File

@ -47,8 +47,8 @@ GameLib.Controls.Touch.prototype.createInstance = function() {
/**
* Update Instance
*/
GameLib.Controls.Touch.prototype.updateInstance = function() {
GameLib.Controls.prototype.updateInstance.call(this);
GameLib.Controls.Touch.prototype.updateInstance = function(property) {
GameLib.Controls.prototype.updateInstance.call(this, property);
};
/**

View File

@ -58,7 +58,6 @@ GameLib.D3.API.Camera = function(
this.name = name;
if (GameLib.Utils.UndefinedOrNull(aspect)) {
//aspect = new GameLib.API.Number(1, 0.001, 0, 5);
aspect = 1;
}
this.aspect = aspect;
@ -91,9 +90,21 @@ GameLib.D3.API.Camera = function(
}
this.quaternion = quaternion;
GameLib.API.Component.call(
this,
GameLib.D3.API.Camera.GetComponentType(this.cameraType),
parentEntity
);
};
GameLib.D3.API.Camera.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.Camera.prototype.constructor = GameLib.D3.API.Camera;
GameLib.D3.API.Camera.GetComponentType = function(cameraType) {
var componentType = null;
switch (this.cameraType) {
switch (cameraType) {
case GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE :
componentType = GameLib.Component.CAMERA_PERSPECTIVE;
break;
@ -107,20 +118,16 @@ GameLib.D3.API.Camera = function(
componentType = GameLib.Component.CAMERA_CUBE;
break;
default:
throw new Error('unsupported camera type: ' + this.cameraType);
throw new Error('unsupported camera type: ' + cameraType);
}
GameLib.API.Component.call(
this,
componentType,
parentEntity
);
};
return componentType;
GameLib.D3.API.Camera.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.Camera.prototype.constructor = GameLib.D3.API.Camera;
};
GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE = 0x1;
GameLib.D3.API.Camera.CAMERA_TYPE_ORTHOGRAPHIC = 0x2;
GameLib.D3.API.Camera.CAMERA_TYPE_STEREO = 0x3;
GameLib.D3.API.Camera.CAMERA_TYPE_CUBE = 0x4;

View File

@ -17,7 +17,9 @@
*
* @constructor
* @param apiCamera
* @param aspectRatioMode
* @param width
* @param height
* @param near
* @param far
* @param left
@ -28,7 +30,11 @@
*/
GameLib.D3.API.Camera.Orthographic = function(
apiCamera,
aspectRatioMode,
minWidth,
minHeight,
width,
height,
near,
far,
left,
@ -56,50 +62,67 @@ GameLib.D3.API.Camera.Orthographic = function(
apiCamera.lookAt = new GameLib.API.Vector3(0,0,-1);
}
if (GameLib.Utils.UndefinedOrNull(aspectRatioMode)) {
aspectRatioMode = GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT;
}
this.aspectRatioMode = aspectRatioMode;
if (GameLib.Utils.UndefinedOrNull(minWidth)) {
minWidth = 10;
}
this.minWidth = minWidth;
if (GameLib.Utils.UndefinedOrNull(minHeight)) {
minHeight = 10;
}
this.minHeight = minHeight;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 10;
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(width)) {
//width = GameLib.API.Number(10, 1, 1, 2000);
width = 10;
}
this.width = width;
if (GameLib.Utils.UndefinedOrNull(height)) {
height = 10;
}
this.height = height;
if (GameLib.Utils.UndefinedOrNull(near)) {
//near = GameLib.API.Number(0.1, 0, 0.1, 2000);
near = 0.1;
}
this.near = near;
if (GameLib.Utils.UndefinedOrNull(far)) {
// far = GameLib.API.Number(2000, 0, 0.1, 4000);
far = 2000;
}
this.far = far;
if (GameLib.Utils.UndefinedOrNull(left)) {
// left = GameLib.API.Number(-5, 1, -2000, 0);
left = -5;
}
this.left = left;
if (GameLib.Utils.UndefinedOrNull(right)) {
//right = GameLib.API.Number(5, 1, 0, 2000);
right = 5;
}
this.right = right;
if (GameLib.Utils.UndefinedOrNull(top)) {
//top = GameLib.API.Number(5, 1, 0, 2000);
top = 5;
}
this.top = top;
if (GameLib.Utils.UndefinedOrNull(bottom)) {
// bottom = GameLib.API.Number(-5, 1, -2000, 0);
bottom = -5;
}
this.bottom = bottom;
if (GameLib.Utils.UndefinedOrNull(zoom)) {
// zoom = new GameLib.API.Number(1, 0.01, 0, 10);
zoom = 1;
}
this.zoom = zoom;
@ -119,4 +142,8 @@ GameLib.D3.API.Camera.Orthographic = function(
};
GameLib.D3.API.Camera.Orthographic.prototype = Object.create(GameLib.D3.API.Camera.prototype);
GameLib.D3.API.Camera.Orthographic.prototype.constructor = GameLib.D3.API.Camera.Orthographic;
GameLib.D3.API.Camera.Orthographic.prototype.constructor = GameLib.D3.API.Camera.Orthographic;
GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE = 0x0;
GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED = 0x1;
GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT = 0x2;

View File

@ -106,6 +106,12 @@ GameLib.D3.API.Material = function(
case GameLib.D3.API.Material.MATERIAL_TYPE_SHADER :
name = 'Material Shader';
break;
case GameLib.D3.API.Material.MATERIAL_TYPE_SHADER_RAW :
name = 'Material Shader Raw';
break;
case GameLib.D3.API.Material.MATERIAL_TYPE_POINTS :
name = 'Material Points';
break;
default :
console.warn('no nice name for material');
name = 'Material';
@ -219,7 +225,9 @@ GameLib.D3.API.Material = function(
if (
this.materialType === GameLib.D3.API.Material.MATERIAL_TYPE_BASIC ||
this.materialType === GameLib.D3.API.Material.MATERIAL_TYPE_SHADER
this.materialType === GameLib.D3.API.Material.MATERIAL_TYPE_SHADER ||
this.materialType === GameLib.D3.API.Material.MATERIAL_TYPE_SHADER_RAW ||
this.materialType === GameLib.D3.API.Material.MATERIAL_TYPE_POINTS
) {
lights = false;
} else {
@ -322,6 +330,12 @@ GameLib.D3.API.Material.GetComponentType = function(materialType) {
case GameLib.D3.API.Material.MATERIAL_TYPE_SHADER :
componentType = GameLib.Component.MATERIAL_SHADER;
break;
case GameLib.D3.API.Material.MATERIAL_TYPE_SHADER_RAW :
componentType = GameLib.Component.MATERIAL_SHADER_RAW;
break;
case GameLib.D3.API.Material.MATERIAL_TYPE_POINTS :
componentType = GameLib.Component.MATERIAL_POINTS;
break;
default :
throw new Error('unhandled material type: ' + materialType);
}
@ -431,6 +445,7 @@ GameLib.D3.API.Material.MATERIAL_TYPE_POINTS = 0x9;
GameLib.D3.API.Material.MATERIAL_TYPE_SPRITE = 0xa;
GameLib.D3.API.Material.MATERIAL_TYPE_TOON = 0xb;
GameLib.D3.API.Material.MATERIAL_TYPE_SHADER = 0xc;
GameLib.D3.API.Material.MATERIAL_TYPE_SHADER_RAW = 0xd;
/**
* Line Cap

View File

@ -0,0 +1,92 @@
/**
* GameLib.D3.API.Material.Points
* @param apiMaterial
* @param color
* @param diffuseMap
* @param size
* @param sizeAttenuation
* @constructor
*/
GameLib.D3.API.Material.Points = function(
apiMaterial,
color,
diffuseMap,
size,
sizeAttenuation
) {
if (GameLib.Utils.UndefinedOrNull(apiMaterial)) {
apiMaterial = {
materialType: GameLib.D3.API.Material.MATERIAL_TYPE_POINTS
};
}
if (GameLib.Utils.UndefinedOrNull(apiMaterial.materialType)) {
apiMaterial.materialType = GameLib.D3.API.Material.MATERIAL_TYPE_POINTS;
}
if (GameLib.Utils.UndefinedOrNull(color)) {
color = new GameLib.API.Color(1, 1, 1, 1)
}
this.color = color;
if (GameLib.Utils.UndefinedOrNull(diffuseMap)) {
diffuseMap = null;
}
this.diffuseMap = diffuseMap;
if (GameLib.Utils.UndefinedOrNull(size)) {
size = 1;
}
this.size = size;
if (GameLib.Utils.UndefinedOrNull(sizeAttenuation)) {
sizeAttenuation = true;
}
this.sizeAttenuation = sizeAttenuation;
GameLib.D3.API.Material.call(
this,
apiMaterial.id,
apiMaterial.name,
apiMaterial.materialType,
apiMaterial.parentEntity,
apiMaterial.parentMeshes,
apiMaterial.alphaTest,
apiMaterial.blendDst,
apiMaterial.blendDstAlpha,
apiMaterial.blendEquation,
apiMaterial.blendEquationAlpha,
apiMaterial.blending,
apiMaterial.blendSrc,
apiMaterial.blendSrcAlpha,
apiMaterial.clipIntersection,
apiMaterial.clippingPlanes,
apiMaterial.clipShadows,
apiMaterial.colorWrite,
apiMaterial.customDepthMaterial,
apiMaterial.customDistanceMaterial,
apiMaterial.defines,
apiMaterial.depthFunc,
apiMaterial.depthTest,
apiMaterial.depthWrite,
apiMaterial.fog,
apiMaterial.lights,
apiMaterial.opacity,
apiMaterial.overdraw,
apiMaterial.polygonOffset,
apiMaterial.polygonOffsetFactor,
apiMaterial.polygonOffsetUnits,
apiMaterial.precision,
apiMaterial.premultipliedAlpha,
apiMaterial.dithering,
apiMaterial.flatShading,
apiMaterial.side,
apiMaterial.transparent,
apiMaterial.vertexColors,
apiMaterial.visible
);
};
GameLib.D3.API.Material.Points.prototype = Object.create(GameLib.D3.API.Material.prototype);
GameLib.D3.API.Material.Points.prototype.constructor = GameLib.D3.API.Material.Points;

View File

@ -0,0 +1,43 @@
/**
* GameLib.D3.API.Material.Shader.Raw
* @param apiMaterialShader
* @constructor
*/
GameLib.D3.API.Material.Shader.Raw = function(
apiMaterialShader
) {
if (GameLib.Utils.UndefinedOrNull(apiMaterialShader)) {
apiMaterialShader = {
materialType: GameLib.D3.API.Material.MATERIAL_TYPE_SHADER_RAW
};
}
if (GameLib.Utils.UndefinedOrNull(apiMaterialShader.materialType)) {
apiMaterialShader.materialType = GameLib.D3.API.Material.MATERIAL_TYPE_SHADER_RAW;
}
GameLib.D3.API.Material.Shader.call(
this,
apiMaterialShader,
apiMaterialShader.clipping,
apiMaterialShader.defaultAttributeValues,
apiMaterialShader.extensions,
apiMaterialShader.fog,
apiMaterialShader.fragmentShader,
apiMaterialShader.index0AttributeName,
apiMaterialShader.linewidth,
apiMaterialShader.morphTargets,
apiMaterialShader.morphNormals,
apiMaterialShader.program,
apiMaterialShader.skinning,
apiMaterialShader.uniforms,
apiMaterialShader.vertexColors,
apiMaterialShader.vertexShader,
apiMaterialShader.wireframe,
apiMaterialShader.wireframeLinewidth
);
};
GameLib.D3.API.Material.Shader.Raw.prototype = Object.create(GameLib.D3.API.Material.Shader.prototype);
GameLib.D3.API.Material.Shader.Raw.prototype.constructor = GameLib.D3.API.Material.Shader.Raw;

View File

@ -63,6 +63,9 @@ GameLib.D3.API.Mesh = function(
if (GameLib.Utils.UndefinedOrNull(name)) {
switch (this.meshType) {
case GameLib.D3.API.Mesh.MESH_TYPE_NORMAL :
name = 'Mesh';
break;
case GameLib.D3.API.Mesh.MESH_TYPE_BOX :
name = 'Mesh Box';
break;

View File

@ -172,6 +172,8 @@ GameLib.D3.Animation.prototype.updateInstance = function(property, item) {
)
}
GameLib.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -111,15 +111,14 @@ GameLib.D3.Camera.prototype.createInstance = function() {
this.instance.aspect = this.aspect;
}
if (GameLib.Utils.Defined(this.instance.lookAt)) {
if (this.instance.isCamera) {
/**
* For some reason - cube camera does not think it is a camera - so it does a lookAt differently -
* which messes up its rotation
*/
this.instance.lookAt(this.lookAt.instance);
}
/**
* Only do lookAt for stereo and cube cameras
*/
if (
this.cameraType === GameLib.D3.API.Camera.CAMERA_TYPE_STEREO ||
this.cameraType === GameLib.D3.API.Camera.CAMERA_TYPE_PERSPECTIVE
) {
this.instance.lookAt(this.lookAt.instance);
}
if (GameLib.Utils.Defined(this.instance.updateProjectionMatrix)) {

View File

@ -23,7 +23,11 @@ GameLib.D3.Camera.Orthographic = function(
GameLib.D3.API.Camera.Orthographic.call(
this,
apiOrthographicCamera,
apiOrthographicCamera.aspectRatioMode,
apiOrthographicCamera.minWidth,
apiOrthographicCamera.minHeight,
apiOrthographicCamera.width,
apiOrthographicCamera.height,
apiOrthographicCamera.near,
apiOrthographicCamera.far,
apiOrthographicCamera.left,
@ -59,6 +63,21 @@ GameLib.D3.Camera.Orthographic.prototype.createInstance = function() {
this.far
);
if (
this.aspectRatioMode === GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED ||
this.aspectRatioMode === GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT
) {
if (this.aspectRatioMode === GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) {
var size = GameLib.Utils.GetWindowSize();
this.aspect = size.width / size.height;
}
this.updateFromAspectRatio();
}
GameLib.D3.Camera.prototype.createInstance.call(this);
};
@ -67,32 +86,53 @@ GameLib.D3.Camera.Orthographic.prototype.createInstance = function() {
*/
GameLib.D3.Camera.Orthographic.prototype.updateInstance = function(property) {
var width, height;
var size;
if (
property === 'width' ||
property === 'aspect'
) {
if (property === 'aspectRatioMode') {
if (!this.fixedAspectRatio) {
console.warn('changing the aspect ratio when this camera is not in fixedAspectRatio mode has no effect');
if (this.aspectRatioMode === GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE) {
this.updateFromDimensions();
return;
}
height = this.width / this.aspect;
if (this.aspectRatioMode === GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED) {
this.updateFromAspectRatio();
return;
}
this.left = this.width / -2;
this.right = this.width / 2;
if (this.aspectRatioMode === GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) {
this.top = height / 2;
this.bottom = height / -2;
size = GameLib.Utils.GetWindowSize();
this.instance.left = this.left;
this.instance.right = this.right;
this.instance.top = this.top;
this.instance.bottom = this.bottom;
this.aspect = size.width / size.height;
this.instance.updateProjectionMatrix();
this.updateFromAspectRatio();
return;
}
}
if (
property === 'width' ||
property === 'height' ||
property === 'minWidth' ||
property === 'minHeight' ||
property === 'aspect'
) {
if (
this.aspectRatioMode !== GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED &&
this.aspectRatioMode !== GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT
) {
console.warn('changing the this value when this camera is not in the right aspect ratio mode has no effect');
return;
}
if (this.aspectRatioMode === GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) {
size = GameLib.Utils.GetWindowSize();
this.aspect = size.width / size.height;
}
this.updateFromAspectRatio();
return;
}
@ -103,18 +143,25 @@ GameLib.D3.Camera.Orthographic.prototype.updateInstance = function(property) {
property === 'top' ||
property === 'bottom'
) {
this.instance.left = this.left;
this.instance.right = this.right;
this.instance.top = this.top;
this.instance.bottom = this.bottom;
width = this.right - this.left;
height = this.top - this.bottom;
if (
this.aspectRatioMode === GameLib.D3.API.Camera.ASPECT_RATIO_MODE_FIXED ||
this.aspectRatioMode === GameLib.D3.API.Camera.ASPECT_RATIO_MODE_BASED_ON_CURRENT
) {
console.warn('changing this value within a fixed aspect ratio has no effect');
return;
}
this.updateFromDimensions();
this.aspect = width / height;
return;
}
if (property === 'zoom') {
this.instance.zoom = this.zoom;
this.instance.updateProjectionMatrix();
}
GameLib.D3.Camera.prototype.updateInstance.call(this, property);
};
@ -128,7 +175,11 @@ GameLib.D3.Camera.Orthographic.prototype.toApiObject = function() {
var apiOrthographicCamera = new GameLib.D3.API.Camera.Orthographic(
apiCamera,
this.aspectRatioMode,
this.minWidth,
this.minHeight,
this.width,
this.height,
this.near,
this.far,
this.left,
@ -142,13 +193,77 @@ GameLib.D3.Camera.Orthographic.prototype.toApiObject = function() {
};
GameLib.D3.Camera.Orthographic.prototype.updateFromInstance = function() {
this.width = this.instance.right - this.instance.left;
this.near = this.instance.near;
this.far = this.instance.far;
this.left = this.instance.left;
this.right = this.instance.right;
this.top = this.instance.top;
this.width = this.instance.right - this.instance.left;
this.height = this.instance.top - this.instance.bottom;
this.near = this.instance.near;
this.far = this.instance.far;
this.left = this.instance.left;
this.right = this.instance.right;
this.top = this.instance.top;
this.bottom = this.instance.bottom;
this.zoom = this.instance.zoom;
this.zoom = this.instance.zoom;
GameLib.D3.Camera.prototype.updateFromInstance.call(this);
};
GameLib.D3.Camera.Orthographic.prototype.updateFromAspectRatio = function() {
if (this.aspect < 1) {
/**
* Make height dependend on width
*/
this.width = this.minWidth;
this.height = this.minWidth / this.aspect;
if (this.height < this.minHeight) {
/**
* We have a problem - our new height is less than our minimum height
*/
this.height = this.minHeight;
this.width = this.aspect * this.height;
}
} else {
/**
* Make width dependend on height
*/
this.height = this.minHeight;
this.width = this.aspect * this.minHeight;
if (this.width < this.minWidth) {
/**
* We have a problem - our new width is less than our minimum width
*/
this.width = this.minWidth;
this.height = this.width / this.aspect;
}
}
this.left = this.width / -2;
this.right = this.width / 2;
this.top = this.height / 2;
this.bottom = this.height / -2;
this.instance.left = this.left;
this.instance.right = this.right;
this.instance.top = this.top;
this.instance.bottom = this.bottom;
this.instance.updateProjectionMatrix();
};
GameLib.D3.Camera.Orthographic.prototype.updateFromDimensions = function() {
this.instance.left = this.left;
this.instance.right = this.right;
this.instance.top = this.top;
this.instance.bottom = this.bottom;
this.width = this.right - this.left;
this.height = this.top - this.bottom;
this.aspect = this.width / this.height;
this.instance.updateProjectionMatrix();
};

View File

@ -100,9 +100,13 @@ GameLib.D3.Material = function(
linkedObjects.specularMap = GameLib.D3.Texture;
break;
case GameLib.D3.API.Material.MATERIAL_TYPE_SHADER :
case GameLib.D3.API.Material.MATERIAL_TYPE_SHADER_RAW :
linkedObjects.vertexShader = GameLib.D3.Shader.Vertex;
linkedObjects.fragmentShader = GameLib.D3.Shader.Fragment;
break;
case GameLib.D3.API.Material.MATERIAL_TYPE_POINTS :
linkedObjects.diffuseMap = GameLib.D3.Texture;
break;
default :
throw new Error('unhandled material type: ' + this.materialType);

View File

@ -41,17 +41,11 @@ GameLib.D3.Material.Basic = function(
);
if (this.alphaMap instanceof GameLib.D3.API.Texture) {
this.alphaMap = new GameLib.D3.Texture(
this.graphics,
this.alphaMap
);
this.alphaMap = GameLib.Component.ConstructFromObject(this.alphaMap);
}
if (this.aoMap instanceof GameLib.D3.API.Texture) {
this.aoMap = new GameLib.D3.Texture(
this.graphics,
this.aoMap
);
this.aoMap = GameLib.Component.ConstructFromObject(this.aoMap);
}
this.color = new GameLib.Color(
@ -61,31 +55,19 @@ GameLib.D3.Material.Basic = function(
);
if (this.envMap instanceof GameLib.D3.API.Texture) {
this.envMap = new GameLib.D3.Texture(
this.graphics,
this.envMap
);
this.envMap = GameLib.Component.ConstructFromObject(this.envMap);
}
if (this.lightMap instanceof GameLib.D3.API.Texture) {
this.lightMap = new GameLib.D3.Texture(
this.graphics,
this.lightMap
);
this.lightMap = GameLib.Component.ConstructFromObject(this.lightMap);
}
if (this.diffuseMap instanceof GameLib.D3.API.Texture) {
this.diffuseMap = new GameLib.D3.Texture(
this.graphics,
this.diffuseMap
);
this.diffuseMap = GameLib.Component.ConstructFromObject(this.diffuseMap);
}
if (this.specularMap instanceof GameLib.D3.API.Texture) {
this.specularMap = new GameLib.D3.Texture(
this.graphics,
this.specularMap
);
this.specularMap = GameLib.Component.ConstructFromObject(this.specularMap);
}
GameLib.D3.Material.call(

View File

@ -54,24 +54,15 @@ GameLib.D3.Material.Phong = function(
);
if (this.alphaMap instanceof GameLib.D3.API.Texture) {
this.alphaMap = new GameLib.D3.Texture(
this.graphics,
this.alphaMap
);
this.alphaMap = GameLib.Component.ConstructFromObject(this.alphaMap);
}
if (this.aoMap instanceof GameLib.D3.API.Texture) {
this.aoMap = new GameLib.D3.Texture(
this.graphics,
this.aoMap
);
this.aoMap = GameLib.Component.ConstructFromObject(this.aoMap);
}
if (this.bumpMap instanceof GameLib.D3.API.Texture) {
this.bumpMap = new GameLib.D3.Texture(
this.graphics,
this.bumpMap
);
this.bumpMap = GameLib.Component.ConstructFromObject(this.bumpMap);
}
this.color = new GameLib.Color(
@ -81,10 +72,7 @@ GameLib.D3.Material.Phong = function(
);
if (this.displacementMap instanceof GameLib.D3.API.Texture) {
this.displacementMap = new GameLib.D3.Texture(
this.graphics,
this.displacementMap
);
this.displacementMap = GameLib.Component.ConstructFromObject(this.displacementMap);
}
this.emissive = new GameLib.Color(
@ -94,38 +82,23 @@ GameLib.D3.Material.Phong = function(
);
if (this.emissiveMap instanceof GameLib.D3.API.Texture) {
this.emissiveMap = new GameLib.D3.Texture(
this.graphics,
this.emissiveMap
);
this.emissiveMap = GameLib.Component.ConstructFromObject(this.emissiveMap);
}
if (this.envMap instanceof GameLib.D3.API.Texture) {
this.envMap = new GameLib.D3.Texture(
this.graphics,
this.envMap
);
this.envMap = GameLib.Component.ConstructFromObject(this.envMap);
}
if (this.lightMap instanceof GameLib.D3.API.Texture) {
this.lightMap = new GameLib.D3.Texture(
this.graphics,
this.lightMap
);
this.lightMap = GameLib.Component.ConstructFromObject(this.lightMap);
}
if (this.diffuseMap instanceof GameLib.D3.API.Texture) {
this.diffuseMap = new GameLib.D3.Texture(
this.graphics,
this.diffuseMap
);
this.diffuseMap = GameLib.Component.ConstructFromObject(this.diffuseMap);
}
if (this.normalMap instanceof GameLib.D3.API.Texture) {
this.normalMap = new GameLib.D3.Texture(
this.graphics,
this.normalMap
);
this.normalMap = GameLib.Component.ConstructFromObject(this.normalMap);
}
this.specular = new GameLib.Color(
@ -135,10 +108,7 @@ GameLib.D3.Material.Phong = function(
);
if (this.specularMap instanceof GameLib.D3.API.Texture) {
this.specularMap = new GameLib.D3.Texture(
this.graphics,
this.specularMap
);
this.specularMap = GameLib.Component.ConstructFromObject(this.specularMap);
}
GameLib.D3.Material.call(

View File

@ -0,0 +1,114 @@
/**
* GameLib.D3.Material.Points
* @param graphics
* @param apiMaterialPoints
* @constructor
*/
GameLib.D3.Material.Points = function(
graphics,
apiMaterialPoints
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiMaterialPoints)) {
apiMaterialPoints = {
materialType : GameLib.D3.API.Material.MATERIAL_TYPE_POINTS
};
}
GameLib.D3.API.Material.Points.call(
this,
apiMaterialPoints,
apiMaterialPoints.color,
apiMaterialPoints.diffuseMap,
apiMaterialPoints.size,
apiMaterialPoints.sizeAttenuation
);
this.color = new GameLib.Color(
this.graphics,
this.color,
this
);
if (this.diffuseMap instanceof GameLib.D3.API.Texture) {
this.diffuseMap = GameLib.Component.ConstructFromObject(this.diffuseMap);
}
GameLib.D3.Material.call(
this,
this.graphics,
this
);
};
GameLib.D3.Material.Points.prototype = Object.create(GameLib.D3.Material.prototype);
GameLib.D3.Material.Points.prototype.constructor = GameLib.D3.Material.Points;
/**
* Creates an instance of our texture object
* @returns {*}
*/
GameLib.D3.Material.Points.prototype.createInstance = function() {
this.instance = new THREE.PointsMaterial(
{
color : this.color.instance,
map : this.diffuseMap ? this.diffuseMap.instance : null,
size : this.size,
sizeAttenuation : this.sizeAttenuation
}
);
GameLib.D3.Material.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Material.Points.prototype.updateInstance = function(property) {
if (property === 'color') {
this.instance.color = this.color.instance;
return;
}
if (property === 'diffuseMap') {
this.assignTexture('map', property);
return;
}
if (property === 'size') {
this.instance.size = this.size;
return;
}
if (property === 'sizeAttenuation') {
this.instance.sizeAttenuation = this.sizeAttenuation;
this.instance.needsUpdate = true;
return;
}
GameLib.D3.Material.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Material.Points to a GameLib.D3.API.Material.Points
* @returns {GameLib.D3.API.Material.Points}
*/
GameLib.D3.Material.Points.prototype.toApiObject = function() {
var apiMaterial = GameLib.D3.Material.prototype.toApiObject.call(this);
var apiMaterialPoints = new GameLib.D3.API.Material.Points(
apiMaterial,
this.color.toApiObject(),
GameLib.Utils.IdOrNull(this.diffuseMap),
this.size,
this.sizeAttenuation
);
return apiMaterialPoints;
};

View File

@ -0,0 +1,99 @@
/**
* GameLib.D3.Material.Shader.Raw
* @param graphics
* @param apiMaterialShaderRaw
* @constructor
*/
GameLib.D3.Material.Shader.Raw = function(
graphics,
apiMaterialShaderRaw
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiMaterialShaderRaw)) {
apiMaterialShaderRaw = {
materialType : GameLib.D3.API.Material.MATERIAL_TYPE_SHADER_RAW
};
}
GameLib.D3.API.Material.Shader.Raw.call(
this,
apiMaterialShaderRaw
);
GameLib.D3.Material.Shader.call(
this,
this.graphics,
this
);
};
GameLib.D3.Material.Shader.Raw.prototype = Object.create(GameLib.D3.Material.Shader.prototype);
GameLib.D3.Material.Shader.Raw.prototype.constructor = GameLib.D3.Material.Shader.Raw;
/**
* Creates an instance of our texture object
* @returns {*}
*/
GameLib.D3.Material.Shader.Raw.prototype.createInstance = function() {
var fragmentShader = '';
var vertexShader = '';
if (this.fragmentShader && this.fragmentShader.instance) {
fragmentShader = this.fragmentShader.instance;
}
if (this.vertexShader && this.vertexShader.instance) {
vertexShader = this.vertexShader.instance;
}
this.instance = new THREE.RawShaderMaterial(
{
clipping : this.clipping,
defaultAttributeValues : this.defaultAttributeValues,
extensions : this.extensions,
fog : this.fog,
fragmentShader : fragmentShader,
linewidth : this.linewidth,
morphTargets : this.morphTargets,
morphNormals : this.morphNormals,
skinning : this.skinning,
uniforms : this.uniforms,
vertexColors : this.vertexColors,
vertexShader : vertexShader,
wireframe : this.wireframe,
wireframeLinewidth : this.wireframeLinewidth
}
);
if (GameLib.Utils.Defined(this.index0AttributeName)) {
this.instance.index0AttributeName = this.index0AttributeName;
}
GameLib.D3.Material.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
GameLib.D3.Material.Shader.Raw.prototype.updateInstance = function(property) {
GameLib.D3.Material.Shader.prototype.updateInstance.call(this, property);
};
/**
* Converts a GameLib.D3.Material.Shader.Raw to a GameLib.D3.API.Material.Shader.Raw
* @returns {GameLib.D3.API.Material.Shader.Raw}
*/
GameLib.D3.Material.Shader.Raw.prototype.toApiObject = function() {
var apiMaterialShader = GameLib.D3.Material.Shader.prototype.toApiObject.call(this);
var apiMaterialShaderRaw = new GameLib.D3.API.Material.Shader.Raw(
apiMaterialShader
);
return apiMaterialShaderRaw;
};

View File

@ -54,24 +54,15 @@ GameLib.D3.Material.Standard = function(
);
if (this.alphaMap instanceof GameLib.D3.API.Texture) {
this.alphaMap = new GameLib.D3.Texture(
this.graphics,
this.alphaMap
);
this.alphaMap = GameLib.Component.ConstructFromObject(this.alphaMap);
}
if (this.aoMap instanceof GameLib.D3.API.Texture) {
this.aoMap = new GameLib.D3.Texture(
this.graphics,
this.aoMap
);
this.aoMap = GameLib.Component.ConstructFromObject(this.aoMap);
}
if (this.bumpMap instanceof GameLib.D3.API.Texture) {
this.bumpMap = new GameLib.D3.Texture(
this.graphics,
this.bumpMap
);
this.bumpMap = GameLib.Component.ConstructFromObject(this.bumpMap);
}
@ -82,10 +73,7 @@ GameLib.D3.Material.Standard = function(
);
if (this.displacementMap instanceof GameLib.D3.API.Texture) {
this.displacementMap = new GameLib.D3.Texture(
this.graphics,
this.displacementMap
);
this.displacementMap = GameLib.Component.ConstructFromObject(this.displacementMap);
}
this.emissive = new GameLib.Color(
@ -95,52 +83,31 @@ GameLib.D3.Material.Standard = function(
);
if (this.emissiveMap instanceof GameLib.D3.API.Texture) {
this.emissiveMap = new GameLib.D3.Texture(
this.graphics,
this.emissiveMap
);
this.emissiveMap = GameLib.Component.ConstructFromObject(this.emissiveMap);
}
if (this.envMap instanceof GameLib.D3.API.Texture) {
this.envMap = new GameLib.D3.Texture(
this.graphics,
this.envMap
);
this.envMap = GameLib.Component.ConstructFromObject(this.envMap);
}
if (this.lightMap instanceof GameLib.D3.API.Texture) {
this.lightMap = new GameLib.D3.Texture(
this.graphics,
this.lightMap
);
this.lightMap = GameLib.Component.ConstructFromObject(this.lightMap);
}
if (this.diffuseMap instanceof GameLib.D3.API.Texture) {
this.diffuseMap = new GameLib.D3.Texture(
this.graphics,
this.diffuseMap
);
this.diffuseMap = GameLib.Component.ConstructFromObject(this.diffuseMap);
}
if (this.metalnessMap instanceof GameLib.D3.API.Texture) {
this.metalnessMap = new GameLib.D3.Texture(
this.graphics,
this.metalnessMap
);
this.metalnessMap = GameLib.Component.ConstructFromObject(this.metalnessMap);
}
if (this.normalMap instanceof GameLib.D3.API.Texture) {
this.normalMap = new GameLib.D3.Texture(
this.graphics,
this.normalMap
);
this.normalMap = GameLib.Component.ConstructFromObject(this.normalMap);
}
if (this.roughnessMap instanceof GameLib.D3.API.Texture) {
this.roughnessMap = new GameLib.D3.Texture(
this.graphics,
this.roughnessMap
);
this.roughnessMap = GameLib.Component.ConstructFromObject(this.roughnessMap);
}
GameLib.D3.Material.call(

View File

@ -190,12 +190,13 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
}
if (GameLib.Utils.Defined(this.parentScene)) {
if (GameLib.Utils.UndefinedOrNull(this.parentScene.instance)) {
console.warn('parent scene not linked at time of create instance');
} else {
this.parentScene.add(this.instance, this);
}
if (
GameLib.Utils.Defined(this.parentScene) &&
GameLib.Utils.Defined(this.parentScene.instance)
) {
this.parentScene.addObject(this);
} else {
console.warn('parent scene not linked yet');
}
this.instance.position.x = this.position.x;

View File

@ -375,6 +375,8 @@ GameLib.D3.Scene.prototype.addObject = function(object) {
if (this.instance.children.indexOf(object.instance) === -1) {
this.instance.add(object.instance);
}
} else {
console.warn('either scene or mesh instance not ready');
}
// if (this.parentEntity) {
@ -389,11 +391,21 @@ GameLib.D3.Scene.prototype.addClone = function(component) {
component instanceof GameLib.D3.Light
) {
if (this.instance && component.instance) {
this.instance.add(component.instance);
if (this.instance.children.indexOf(component.instance) === -1) {
this.instance.add(component.instance);
}
}
component.isClone = true;
GameLib.Utils.PushUnique(this.clones, component);
var index = this.meshes.indexOf(component);
if (index !== -1) {
this.meshes.splice(index, 1);
}
component.parentScene = this;
}
};

View File

@ -940,6 +940,18 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
}
)
);
} else if (property === 'aspectRatioMode') {
controllers.push(
folder.add(
object,
property,
{
'none' : GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE,
'fixed' : GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED,
'based on current' : GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT
}
)
);
} else if (property === 'socketType') {
controllers.push(
folder.add(
@ -1192,8 +1204,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
'standard': GameLib.D3.API.Material.MATERIAL_TYPE_STANDARD,
'basic': GameLib.D3.API.Material.MATERIAL_TYPE_BASIC,
'phong': GameLib.D3.API.Material.MATERIAL_TYPE_PHONG,
'shader': GameLib.D3.API.Material.MATERIAL_TYPE_SHADER
// 'points': GameLib.D3.API.Material.MATERIAL_TYPE_POINTS,
'shader': GameLib.D3.API.Material.MATERIAL_TYPE_SHADER,
'points': GameLib.D3.API.Material.MATERIAL_TYPE_POINTS
// 'toon': GameLib.D3.API.Material.MATERIAL_TYPE_TOON,
// 'line basic' : GameLib.D3.API.Material.MATERIAL_TYPE_LINE_BASIC
}
@ -1655,7 +1667,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
) {
controllers.push(folder.add(object, property, -2, 2, 0.0001));
} else if (
property === 'arc'
property === 'arc' ||
property === 'size'
) {
controllers.push(folder.add(object, property, 0, 200, 0.001));
} else {

View File

@ -244,6 +244,26 @@ GameLib.System.Render.prototype.windowResize = function(data) {
}
);
GameLib.EntityManager.Instance.queryComponentsByConstructor(GameLib.D3.Camera).map(
function(camera){
if (
camera instanceof GameLib.D3.Camera.Orthographic &&
camera.aspectRatioMode !== GameLib.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE
) {
camera.updateInstance('aspect');
}
if (
camera instanceof GameLib.D3.Camera.Perspective ||
camera instanceof GameLib.D3.Camera.Stereo
) {
camera.aspect = data.width / data.height;
camera.updateInstance('aspect');
}
}
);
GameLib.EntityManager.Instance.queryComponents(GameLib.Component.COMPOSER).map(
function(composer){