beta.r3js.org
-=ybafelo 2019-08-07 05:17:41 +02:00
parent b28b1bc99b
commit 7106e3368a
50 changed files with 1981 additions and 2993 deletions

View File

@ -17,7 +17,6 @@ R3.API.Renderer.D3.Target = function(
R3.API.Renderer.D3.call( R3.API.Renderer.D3.call(
this, this,
this.apiRendererD3, this.apiRendererD3,
this.apiRendererD3.renderMode,
this.apiRendererD3.autoClear, this.apiRendererD3.autoClear,
this.apiRendererD3.autoClearColor, this.apiRendererD3.autoClearColor,
this.apiRendererD3.autoClearDepth, this.apiRendererD3.autoClearDepth,
@ -49,7 +48,8 @@ R3.API.Renderer.D3.Target = function(
this.apiRendererD3.clearColor, this.apiRendererD3.clearColor,
this.apiRendererD3.viewports, this.apiRendererD3.viewports,
this.apiRendererD3.alpha, this.apiRendererD3.alpha,
this.apiRendererD3.opacity this.apiRendererD3.opacity,
this.apiRendererD3.pixelRatio
); );
if (R3.Utils.UndefinedOrNull(target)) { if (R3.Utils.UndefinedOrNull(target)) {

View File

@ -114,8 +114,15 @@ R3.Renderer.D3.Target = function(
}; };
R3.Renderer.D3.prototype = Object.create(R3.Renderer.prototype); R3.Renderer.D3.Target.prototype = Object.create(R3.Renderer.D3.prototype);
R3.Renderer.D3.prototype.constructor = R3.Renderer.D3; R3.Renderer.D3.Target.prototype.constructor = R3.Renderer.D3.Target;
R3.Renderer.D3.Target.prototype.getSize = function() {
return {
width : this.target.width,
height : this.target.height
}
};
/** /**
* Create R3.Renderer.D3 Instance * Create R3.Renderer.D3 Instance

View File

@ -141,6 +141,8 @@ R3.Event.GET_DEFAULT_SCENE = 0x77;
R3.Event.GET_DEFAULT_CAMERA = 0x78; R3.Event.GET_DEFAULT_CAMERA = 0x78;
R3.Event.GET_WEBSOCKET_CONFIG = 0x79; R3.Event.GET_WEBSOCKET_CONFIG = 0x79;
R3.Event.GET_PROJECT = 0x7a; R3.Event.GET_PROJECT = 0x7a;
R3.Event.GET_APPLICATION_MODE = 0x80;
R3.Event.RENDERER_SIZE_CHANGE = 0x81;
/** /**
* Returns string name of event ID * Returns string name of event ID
@ -273,6 +275,8 @@ R3.Event.GetEventName = function(number) {
case 0x78 : return 'get_default_camera'; case 0x78 : return 'get_default_camera';
case 0x79 : return 'get_websocket_config'; case 0x79 : return 'get_websocket_config';
case 0x7a : return 'get_project'; case 0x7a : return 'get_project';
case 0x80 : return 'get_application_mode';
case 0x81 : return 'renderer_size_change';
break; break;
} }

View File

@ -1,5 +1,120 @@
R3.Utils = function() {}; R3.Utils = function() {};
/**
* Gets the first parent of the object which is an instance of constructor
* @param object
* @param constructor
* @returns {*}
* @constructor
*/
R3.Utils.GetFirstParent = function(object, constructor) {
if (R3.Utils.UndefinedOrNull(constructor)) {
throw new Error('You need to specify a constructor');
}
if (object.parent === null) {
return null;
}
if (object.parent instanceof constructor) {
return object.parent;
} else {
return R3.Utils.GetFirstParent(object.parent, constructor);
}
};
/**
* Gets the parent of object whith property of optional type constructor. If index is specified, get the parent of the
* object with property[index] - which means the property should be an array
* @param object
* @param property
* @param index
* @param constructor
* @returns {*}
* @constructor
*/
R3.Utils.GetParent = function(object, property, index, constructor) {
if (R3.Utils.UndefinedOrNull(constructor)) {
constructor = null;
}
if (R3.Utils.UndefinedOrNull(index)) {
index = null;
}
if (object.parent) {
/**
* Parent defined
*/
if (object.parent.hasOwnProperty(property)) {
if (constructor) {
if (index) {
if (object.parent[property][index] instanceof constructor) {
return object.parent[property][index];
} else {
if (typeof object.parent.getParent === 'function') {
return object.parent.getParent(property, index, constructor);
} else {
console.warn('getParent not defined on API object : ' + object.parent + ' - you should avoid having these messsages');
return null;
}
}
} else {
if (object.parent[property] instanceof constructor) {
return object.parent[property];
} else {
if (typeof object.parent.getParent === 'function') {
return object.parent.getParent(property, index, constructor);
} else {
console.warn('getParent not defined on API object : ' + object.parent + ' - you should avoid having these messsages');
return null;
}
}
}
} else {
if (index) {
return object.parent[property][index];
} else {
return object.parent[property];
}
}
} else {
/**
* This parent does not have the property - go a level higher
*/
if (typeof object.parent.getParent === 'function') {
return object.parent.getParent(property, index, constructor);
} else {
console.warn('getParent not defined on API object : ' + object.parent + ' - you should avoid having these messsages');
return null;
}
}
} else {
/**
* No parent defined
*/
console.warn('property : ' + property + ' of type ' + constructor + ' was not found in the parent chain');
return null;
}
};
/** /**
* Strips image extension from given path * Strips image extension from given path
* @param imagePath * @param imagePath

View File

@ -31,82 +31,24 @@ R3.API.Component = function(
R3.API.Component.prototype.constructor = R3.API.Component; R3.API.Component.prototype.constructor = R3.API.Component;
R3.API.Component.prototype.getParent = function(property, index, constructor) { /**
* Wrapper for R3.Utils.GetFirstParent
if (R3.Utils.UndefinedOrNull(constructor)) { * @param constructor
constructor = null; * @returns {*}
} */
R3.API.Component.prototype.getFirstParent = function(constructor) {
if (R3.Utils.UndefinedOrNull(index)) { return R3.D3.GetFirstParent(this, constructor);
index = null; };
}
if (this.parent) {
/**
* Parent defined
*/
if (this.parent.hasOwnProperty(property)) {
if (constructor) {
if (index) {
if (this.parent[property][index] instanceof constructor) {
return this.parent[property][index];
} else {
if (typeof this.parent.getParent === 'function') {
return this.parent.getParent(property, index, constructor);
} else {
console.warn('getParent not defined on API object : ' + this.parent + ' - you should avoid having these messsages');
return null;
}
}
} else {
if (this.parent[property] instanceof constructor) {
return this.parent[property];
} else {
if (typeof this.parent.getParent === 'function') {
return this.parent.getParent(property, index, constructor);
} else {
console.warn('getParent not defined on API object : ' + this.parent + ' - you should avoid having these messsages');
return null;
}
}
}
} else {
if (index) {
return this.parent[property][index];
} else {
return this.parent[property];
}
}
} else {
/**
* This parent does not have the property - go a level higher
*/
if (typeof this.parent.getParent === 'function') {
return this.parent.getParent(property, index, constructor);
} else {
console.warn('getParent not defined on API object : ' + this.parent + ' - you should avoid having these messsages');
return null;
}
}
} else {
/**
* No parent defined
*/
console.warn('property : ' + property + ' of type ' + constructor + ' was not found in the parent chain');
return null;
}
/**
* Wrapper for R3.Utils.GetParent
* @param property
* @param index
* @param constructor
* @returns {*}
*/
R3.API.Component.getParent = function(property, index, constructor) {
return R3.D3.GetParent(this, property, index, constructor);
}; };
R3.API.Component.prototype.getComponentType = function() { R3.API.Component.prototype.getComponentType = function() {

View File

@ -257,7 +257,7 @@ R3.Component.prototype.updateFromInstance = function(property) {
} }
if ( if (
this[property] instanceof R3.Vector4 | this[property] instanceof R3.Vector4 ||
this[property] instanceof R3.Quaternion this[property] instanceof R3.Quaternion
) { ) {
this[property].x = this.instance[property].x; this[property].x = this.instance[property].x;
@ -280,63 +280,26 @@ R3.Component.prototype.updateFromInstance = function(property) {
}; };
/** /**
* R3.Component.prototype.getParent traverses the parent chain looking for the first parent which has a certain * Wrapper for R3.Utils.GetFirstParent
* property. If the constructor is given, then not only does the property have to exist - it also has to match the
* constructor
* @param property
* @param constructor * @param constructor
* @returns {null|*} * @returns {*}
*/ */
R3.Component.prototype.getParent = function(property, constructor) { R3.Component.prototype.getFirstParent = function(constructor) {
return R3.D3.GetFirstParent(this, constructor);
if (R3.Utils.UndefinedOrNull(constructor)) {
constructor = null;
}
if (this.parent) {
if (this.parent.hasOwnProperty(property)) {
if (constructor) {
if (this.parent[property] instanceof constructor) {
return this.parent[property];
} else {
return this.parent.getParent(property, constructor);
}
} else {
return this.parent[property];
}
} else {
return this.parent.getParent(property, constructor);
}
} else {
console.warn('property : ' + property + ' of type ' + constructor + ' was not found in the parent chain');
return null;
}
}; };
/** /**
* This function traverses the parent chain to find the first parent which matches the constructor * Wrapper for R3.Utils.GetParent
* @param property
* @param index
* @param constructor * @param constructor
* @returns {*}
*/ */
R3.Component.prototype.getFirstParent = function(constructor) { R3.Component.getParent = function(property, index, constructor) {
return R3.D3.GetParent(this, property, index, constructor);
if (R3.Utils.UndefinedOrNull(constructor)) {
throw new Error('You need to specify a constructor');
}
if (this.parent === null) {
return null;
}
if (this.parent instanceof constructor) {
return this.parent;
} else {
return this.getFirstParent(constructor);
}
}; };
R3.Component.prototype.toString = function() { R3.Component.prototype.toString = function() {
return this.id; return this.id;
}; };
@ -2107,11 +2070,11 @@ R3.Component.prototype.getPropertyValue = function(item) {
* Handle colors, vectors and matrices - they are not components so they have their own toApiObject functions * Handle colors, vectors and matrices - they are not components so they have their own toApiObject functions
*/ */
if ( if (
item instanceof R3.Color | item instanceof R3.Color ||
item instanceof R3.Vector2 | item instanceof R3.Vector2 ||
item instanceof R3.Vector3 | item instanceof R3.Vector3 ||
item instanceof R3.Vector4 | item instanceof R3.Vector4 ||
item instanceof R3.Quaternion | item instanceof R3.Quaternion ||
item instanceof R3.Matrix4 item instanceof R3.Matrix4
) { ) {
return item.toApiObject(); return item.toApiObject();
@ -2172,13 +2135,23 @@ R3.Component.prototype.toApiObject = function() {
* the array to the apiObject * the array to the apiObject
*/ */
apiObject[property] = this[property].reduce( apiObject[property] = this[property].reduce(
function(result, item) { function(result, item, index) {
if (item instanceof R3.Runtime) { if (item instanceof R3.Runtime) {
throw new Error('Please don\'t store Runtime Objects in Arrays'); throw new Error('Please don\'t store Runtime Objects in Arrays');
} }
result.push(this.getPropertyValue(item)); if (item.isArray) {
result[index] = item.reduce(
function (subResult, subItem) {
subResult.push(this.getPropertyValue(subItem));
return subResult;
}.bind(this),
[]
)
} else {
result.push(this.getPropertyValue(item));
}
return result; return result;

View File

@ -5,9 +5,10 @@
* @param isPublic * @param isPublic
* @param entities * @param entities
* @param renderers * @param renderers
* @param renderTargets
* @param cameras * @param cameras
* @param audios * @param audios
* @param mode * @param applicationMode
* @constructor * @constructor
*/ */
R3.API.Project = function( R3.API.Project = function(
@ -16,9 +17,10 @@ R3.API.Project = function(
isPublic, isPublic,
entities, entities,
renderers, renderers,
renderTargets,
cameras, cameras,
audios, audios,
mode applicationMode
) { ) {
__API_COMPONENT_MACRO__; __API_COMPONENT_MACRO__;
@ -43,6 +45,11 @@ R3.API.Project = function(
} }
this.renderers = renderers; this.renderers = renderers;
if (R3.Utils.UndefinedOrNull(renderTargets)) {
renderTargets = [];
}
this.renderTargets = renderTargets;
if (R3.Utils.UndefinedOrNull(cameras)) { if (R3.Utils.UndefinedOrNull(cameras)) {
var editCamera = new R3.D3.API.Camera.Perspective( var editCamera = new R3.D3.API.Camera.Perspective(
{ {
@ -63,10 +70,10 @@ R3.API.Project = function(
} }
this.audios = audios; this.audios = audios;
if (R3.Utils.UndefinedOrNull(mode)) { if (R3.Utils.UndefinedOrNull(applicationMode)) {
mode = R3.API.Project.APPLICATION_MODE_EDIT; applicationMode = R3.API.Project.APPLICATION_MODE_EDIT;
} }
this.mode = mode; this.applicationMode = applicationMode;
}; };
R3.API.Project.prototype = Object.create(R3.API.Component.prototype); R3.API.Project.prototype = Object.create(R3.API.Component.prototype);
@ -76,4 +83,8 @@ R3.API.Project.APPLICATION_MODE_RUN = 0x1;
R3.API.Project.APPLICATION_MODE_EDIT = 0x2; R3.API.Project.APPLICATION_MODE_EDIT = 0x2;
R3.API.Project.CAMERA_INDEX_EDIT = 0x0; R3.API.Project.CAMERA_INDEX_EDIT = 0x0;
R3.API.Project.CAMERA_INDEX_RUN = 0x1; R3.API.Project.CAMERA_INDEX_RUN = 0x1;
R3.API.Project.RENDERER_INDEX_MAIN = 0x0;
R3.API.Project.RENDER_TARGET_INDEX_NONE = -0x1;

View File

@ -26,4 +26,15 @@ R3.API.Renderer.D3.Canvas.Target = function(
}; };
R3.API.Renderer.D3.Canvas.Target.prototype = Object.create(R3.API.Renderer.D3.Canvas.prototype); R3.API.Renderer.D3.Canvas.Target.prototype = Object.create(R3.API.Renderer.D3.Canvas.prototype);
R3.API.Renderer.D3.prototype.constructor = R3.API.Renderer.D3.Canvas.Target; R3.API.Renderer.D3.Canvas.Target.prototype.constructor = R3.API.Renderer.D3.Canvas.Target;
/**
* Return the size of the target instead of the canvas
* @returns {{width: *, height: *}}
*/
R3.API.Renderer.D3.Canvas.Target.prototype.getSize = function() {
return {
width : this.target.width,
height : this.target.height
}
};

View File

@ -17,7 +17,6 @@ R3.API.Renderer.D3.Canvas = function(
R3.API.Renderer.D3.call( R3.API.Renderer.D3.call(
this, this,
this.apiRendererD3, this.apiRendererD3,
this.apiRendererD3.renderMode,
this.apiRendererD3.autoClear, this.apiRendererD3.autoClear,
this.apiRendererD3.autoClearColor, this.apiRendererD3.autoClearColor,
this.apiRendererD3.autoClearDepth, this.apiRendererD3.autoClearDepth,
@ -49,7 +48,8 @@ R3.API.Renderer.D3.Canvas = function(
this.apiRendererD3.clearColor, this.apiRendererD3.clearColor,
this.apiRendererD3.viewports, this.apiRendererD3.viewports,
this.apiRendererD3.alpha, this.apiRendererD3.alpha,
this.apiRendererD3.opacity this.apiRendererD3.opacity,
this.apiRendererD3.pixelRatio
); );
if (R3.Utils.UndefinedOrNull(canvas)) { if (R3.Utils.UndefinedOrNull(canvas)) {
@ -60,4 +60,13 @@ R3.API.Renderer.D3.Canvas = function(
}; };
R3.API.Renderer.D3.Canvas.prototype = Object.create(R3.API.Renderer.D3.prototype); R3.API.Renderer.D3.Canvas.prototype = Object.create(R3.API.Renderer.D3.prototype);
R3.API.Renderer.D3.Canvas.prototype.constructor = R3.API.Renderer.D3.Canvas; R3.API.Renderer.D3.Canvas.prototype.constructor = R3.API.Renderer.D3.Canvas;
R3.API.Renderer.D3.Canvas.prototype.getSize = function() {
return {
width : this.canvas.width,
height : this.canvas.height
}
};

View File

@ -1,7 +1,6 @@
/** /**
* R3.API.Renderer.D3 * R3.API.Renderer.D3
* @param apiRenderer * @param apiRenderer
* @param renderMode
* @param autoClear * @param autoClear
* @param autoClearColor * @param autoClearColor
* @param autoClearDepth * @param autoClearDepth
@ -34,11 +33,11 @@
* @param viewports * @param viewports
* @param alpha * @param alpha
* @param opacity * @param opacity
* @param pixelRatio
* @constructor * @constructor
*/ */
R3.API.Renderer.D3 = function( R3.API.Renderer.D3 = function(
apiRenderer, apiRenderer,
renderMode,
autoClear, autoClear,
autoClearColor, autoClearColor,
autoClearDepth, autoClearDepth,
@ -70,7 +69,8 @@ R3.API.Renderer.D3 = function(
clearColor, clearColor,
viewports, viewports,
alpha, alpha,
opacity opacity,
pixelRatio
) { ) {
if (R3.Utils.UndefinedOrNull(apiRenderer)) { if (R3.Utils.UndefinedOrNull(apiRenderer)) {
@ -83,11 +83,6 @@ R3.API.Renderer.D3 = function(
this.apiRenderer this.apiRenderer
); );
if (R3.Utils.UndefinedOrNull(renderMode)) {
renderMode = R3.API.Renderer.MODE_CANVAS;
}
this.renderMode = renderMode;
if (R3.Utils.UndefinedOrNull(autoClear)) { if (R3.Utils.UndefinedOrNull(autoClear)) {
autoClear = true; autoClear = true;
} }
@ -248,7 +243,12 @@ R3.API.Renderer.D3 = function(
} }
this.opacity = opacity; this.opacity = opacity;
if (R3.Utils.UndefinedOrNull(pixelRatio)) {
pixelRatio = window.devicePixelRatio;
}
this.pixelRatio = pixelRatio;
}; };
R3.API.Renderer.D3.prototype = Object.create(R3.API.Renderer.prototype); R3.API.Renderer.D3.prototype = Object.create(R3.API.Renderer.prototype);
R3.API.Renderer.D3.prototype.constructor = R3.API.Renderer.D3; R3.API.Renderer.D3.prototype.constructor = R3.API.Renderer.D3;

View File

@ -9,6 +9,9 @@ R3.Color = function(
apiComponent apiComponent
) { ) {
/**
* Color does not extend component so initialize the parent
*/
if (R3.Utils.UndefinedOrNull(parent)) { if (R3.Utils.UndefinedOrNull(parent)) {
parent = null; parent = null;
} }

View File

@ -35,7 +35,7 @@ R3.D3.API.Camera = function(
); );
if (R3.Utils.UndefinedOrNull(aspect)) { if (R3.Utils.UndefinedOrNull(aspect)) {
aspect = 1; aspect = R3.D3.API.Camera.ASPECT_RATIO_1_1;
} }
this.aspect = aspect; this.aspect = aspect;
@ -44,8 +44,8 @@ R3.D3.API.Camera = function(
R3.D3.API.Camera.prototype = Object.create(R3.D3.API.Object.prototype); R3.D3.API.Camera.prototype = Object.create(R3.D3.API.Object.prototype);
R3.D3.API.Camera.prototype.constructor = R3.D3.API.Camera; R3.D3.API.Camera.prototype.constructor = R3.D3.API.Camera;
R3.D3.API.Camera.ASPECT_RATIO_1_1 = 0x1; R3.D3.API.Camera.ASPECT_RATIO_1_1 = 1;
R3.D3.API.Camera.ASPECT_RATIO_3_2 = 0x2; R3.D3.API.Camera.ASPECT_RATIO_3_2 = 3/2;
R3.D3.API.Camera.ASPECT_RATIO_4_3 = 0x3; R3.D3.API.Camera.ASPECT_RATIO_4_3 = 4/3;
R3.D3.API.Camera.ASPECT_RATIO_16_9 = 0x4; R3.D3.API.Camera.ASPECT_RATIO_16_9 = 16/9;
R3.D3.API.Camera.ASPECT_RATIO_16_10 = 0x5; R3.D3.API.Camera.ASPECT_RATIO_16_10 = 16/10;

View File

@ -1,16 +1,14 @@
/** /**
* R3.D3.API.Camera.Orthographic.FixedAspect * R3.D3.API.Camera.Orthographic.FixedAspect
* *
* This camera calculates left, right, top and bottom coordinates from the provided aspect ratio. It uses the inherited * - This camera calculates left, right, top and bottom coordinates from the provided aspect ratio. It uses the
* default values for near and far values for the Z space * inherited default values for near and far values for the Z space
* *
* @param apiD3CameraOrthographic * @param apiD3CameraOrthographic
* @param aspectRatio
* @constructor * @constructor
*/ */
R3.D3.API.Camera.Orthographic.FixedAspect = function( R3.D3.API.Camera.Orthographic.FixedAspect = function(
apiD3CameraOrthographic, apiD3CameraOrthographic
aspectRatio
) { ) {
if (R3.Utils.UndefinedOrNull(apiD3CameraOrthographic)) { if (R3.Utils.UndefinedOrNull(apiD3CameraOrthographic)) {
@ -26,11 +24,6 @@ R3.D3.API.Camera.Orthographic.FixedAspect = function(
this.apiD3CameraOrthographic.zoom this.apiD3CameraOrthographic.zoom
); );
if (R3.Utils.UndefinedOrNull(aspectRatio)) {
aspectRatio = R3.D3.API.Camera.ASPECT_RATIO_1_1;
}
this.aspectRatio = aspectRatio;
}; };
R3.D3.API.Camera.Orthographic.FixedAspect.prototype = Object.create(R3.D3.API.Camera.Orthographic.prototype); R3.D3.API.Camera.Orthographic.FixedAspect.prototype = Object.create(R3.D3.API.Camera.Orthographic.prototype);

View File

@ -1,5 +1,5 @@
/** /**
* R3.D3.API.Camera.Orthographic.ZoomedAspect * R3.D3.API.Camera.Orthographic.ScaledAspect
* *
* This camera does not automatically adjust its left, right, top and bottom values - it assumes they have been defined * This camera does not automatically adjust its left, right, top and bottom values - it assumes they have been defined
* and are correct. It uses the inherited default near and far values for the Z space. It essentially ignores aspect * and are correct. It uses the inherited default near and far values for the Z space. It essentially ignores aspect
@ -12,7 +12,7 @@
* @param bottom * @param bottom
* @constructor * @constructor
*/ */
R3.D3.API.Camera.Orthographic.ZoomedAspect = function( R3.D3.API.Camera.Orthographic.ScaledAspect = function(
apiD3CameraOrthographic, apiD3CameraOrthographic,
left, left,
right, right,
@ -55,5 +55,5 @@ R3.D3.API.Camera.Orthographic.ZoomedAspect = function(
}; };
R3.D3.API.Camera.Orthographic.ZoomedAspect.prototype = Object.create(R3.D3.API.Camera.Orthographic.prototype); R3.D3.API.Camera.Orthographic.ScaledAspect.prototype = Object.create(R3.D3.API.Camera.Orthographic.prototype);
R3.D3.API.Camera.Orthographic.ZoomedAspect.prototype.constructor = R3.D3.API.Camera.Orthographic.ZoomedAspect; R3.D3.API.Camera.Orthographic.ScaledAspect.prototype.constructor = R3.D3.API.Camera.Orthographic.ScaledAspect;

View File

@ -2,7 +2,7 @@
* R3.D3.API.Camera.Orthographic * R3.D3.API.Camera.Orthographic
* *
* Base class for Orthographic Cameras - do define an aspect ratio for the camera, use FixedAspect child class, to * Base class for Orthographic Cameras - do define an aspect ratio for the camera, use FixedAspect child class, to
* manually set the camera size, use the ZoomedAspect child class * manually set the camera size, use the ScaledAspect child class
* *
* @constructor * @constructor
* @param apiD3Camera * @param apiD3Camera

View File

@ -0,0 +1,53 @@
/**
* R3.D3.API.Composer.RenderTarget
* @param apiComposer
* @param renderTarget
* @constructor
*/
R3.D3.API.Composer.RenderTarget = function(
apiComposer,
renderTarget
) {
if (R3.Utils.UndefinedOrNull(apiComposer)) {
apiComposer = {};
}
this.apiComposer = apiComposer;
R3.D3.API.Composer.call(
this,
this.apiComposer,
this.apiComposer.width,
this.apiComposer.height,
this.apiComposer.passes
);
if (R3.Utils.UndefinedOrNull(renderTarget)) {
/**
* We look at the project to see if any renderTargets exist - we use the most recent created one or
* construct a new one if none exist
* @type {number|*}
*/
R3.Event.Emit(
R3.Event.GET_PROJECT,
null,
function(project) {
if (project.renderTargets.length > 0) {
renderTarget = project.renderTargets[project.renderTargets.length - 1];
} else {
renderTarget = new R3.D3.API.RenderTarget();
project.renderTargets.push(renderTarget);
}
}.bind(this)
);
}
this.renderTarget = renderTarget
};
R3.D3.API.Composer.RenderTarget.prototype = Object.create(R3.D3.API.Composer.prototype);
R3.D3.API.Composer.RenderTarget.prototype.constructor = R3.D3.API.Composer.RenderTarget;

View File

@ -0,0 +1,33 @@
/**
* R3.D3.API.Composer.Renderer
* @param apiComposer
* @param renderer
* @constructor
*/
R3.D3.API.Composer.Renderer = function(
apiComposer,
renderer
) {
if (R3.Utils.UndefinedOrNull(apiComposer)) {
apiComposer = {};
}
this.apiComposer = apiComposer;
R3.D3.API.Composer.call(
this,
this.apiComposer,
this.apiComposer.width,
this.apiComposer.height,
this.apiComposer.passes
);
if (R3.Utils.UndefinedOrNull(renderer)) {
renderer = this.getFirstParent(R3.API.Renderer.D3);
}
this.renderer = renderer;
};
R3.D3.API.Composer.Renderer.prototype = Object.create(R3.D3.API.Composer.prototype);
R3.D3.API.Composer.Renderer.prototype.constructor = R3.D3.API.Composer.Renderer;

View File

@ -1,7 +1,6 @@
/** /**
* R3.D3.API.Composer * R3.D3.API.Composer
* @param apiComponent * @param apiComponent
* @param autoUpdateSize
* @param width * @param width
* @param height * @param height
* @param passes * @param passes
@ -9,7 +8,6 @@
*/ */
R3.D3.API.Composer = function( R3.D3.API.Composer = function(
apiComponent, apiComponent,
autoUpdateSize,
width, width,
height, height,
passes passes
@ -17,18 +15,13 @@ R3.D3.API.Composer = function(
__API_COMPONENT_MACRO__; __API_COMPONENT_MACRO__;
if (R3.Utils.UndefinedOrNull(autoUpdateSize)) {
autoUpdateSize = true;
}
this.autoUpdateSize = autoUpdateSize;
if (R3.Utils.UndefinedOrNull(width)) { if (R3.Utils.UndefinedOrNull(width)) {
width = 512; width = 0;
} }
this.width = width; this.width = width;
if (R3.Utils.UndefinedOrNull(height)) { if (R3.Utils.UndefinedOrNull(height)) {
height = 512; height = 0;
} }
this.height = height; this.height = height;

View File

@ -1,30 +1,37 @@
/** /**
* R3.D3.API.Effect * R3.D3.API.Effect
* @param apiComponent * @param apiComponent
* @param renderer
* @param width * @param width
* @param height * @param height
*
* @property effectType
*
* @constructor * @constructor
*/ */
R3.D3.API.Effect = function( R3.D3.API.Effect = function(
apiComponent, apiComponent,
renderer,
width, width,
height height
) { ) {
__API_COMPONENT_MACRO__; __API_COMPONENT_MACRO__;
if (R3.Utils.UndefinedOrNull(renderer)) {
renderer = this.getFirstParent(R3.API.Renderer.D3);
}
this.renderer = renderer;
var size = renderer.getSize();
if (R3.Utils.UndefinedOrNull(width)) { if (R3.Utils.UndefinedOrNull(width)) {
width = 512; width = size.width;
} }
this.width = width; this.width = width;
if (R3.Utils.UndefinedOrNull(height)) { if (R3.Utils.UndefinedOrNull(height)) {
height = 512; height = size.height;
} }
this.height = height; this.height = height;
}; };
R3.D3.API.Effect.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.Effect.prototype = Object.create(R3.API.Component.prototype);

View File

@ -15,6 +15,7 @@ R3.D3.API.Effect.Anaglyph = function(
R3.D3.API.Effect.call( R3.D3.API.Effect.call(
this, this,
this.apiEffect, this.apiEffect,
this.apiEffect.renderer,
this.apiEffect.width, this.apiEffect.width,
this.apiEffect.height this.apiEffect.height
); );

View File

@ -15,6 +15,7 @@ R3.D3.API.Effect.Parallax = function(
R3.D3.API.Effect.call( R3.D3.API.Effect.call(
this, this,
this.apiEffect, this.apiEffect,
this.apiEffect.renderer,
this.apiEffect.width, this.apiEffect.width,
this.apiEffect.height this.apiEffect.height
); );

View File

@ -17,6 +17,7 @@ R3.D3.API.Effect.Stereo = function(
R3.D3.API.Effect.call( R3.D3.API.Effect.call(
this, this,
this.apiEffect, this.apiEffect,
this.apiEffect.renderer,
this.apiEffect.width, this.apiEffect.width,
this.apiEffect.height this.apiEffect.height
); );

View File

@ -0,0 +1,110 @@
/**
* R3.D3.API.Face
* @param apiFace
* @param materialIndex
* @param uvs [[v0uv (R3.Vector2), v1uv(R3.Vector2), v2uv(R3.Vector2)]]
* @param color
* @param vertexColors
* @constructor
*/
R3.D3.API.Face.Graphics = function(
apiFace,
materialIndex,
uvs,
color,
vertexColors
) {
R3.D3.API.Face.call(
this,
apiFace,
apiFace.v0index,
apiFace.v1index,
apiFace.v2index,
apiFace.vertexNormals,
apiFace.normal,
apiFace.selected
);
if (R3.Utils.UndefinedOrNull(v0index)) {
v0index = -1;
}
this.v0index = v0index;
if (R3.Utils.UndefinedOrNull(v1index)) {
v1index = -1;
}
this.v1index = v1index;
if (R3.Utils.UndefinedOrNull(v2index)) {
v2index = -1;
}
this.v2index = v2index;
if (R3.Utils.UndefinedOrNull(materialIndex)) {
materialIndex = -1;
}
this.materialIndex = materialIndex;
if (R3.Utils.UndefinedOrNull(uvs)) {
uvs = [[]];
}
this.uvs = uvs;
if (R3.Utils.UndefinedOrNull(color)) {
color = new R3.API.Color();
}
this.color = color;
if (R3.Utils.UndefinedOrNull(vertexColors)) {
vertexColors = [
new R3.API.Color(),
new R3.API.Color(),
new R3.API.Color()
];
}
this.vertexColors = vertexColors;
if (R3.Utils.UndefinedOrNull(vertexNormals)) {
vertexNormals = [];
}
this.vertexNormals = vertexNormals;
if (R3.Utils.UndefinedOrNull(normal)) {
normal = null;
}
this.normal = normal;
if (R3.Utils.UndefinedOrNull(selected)) {
selected = false;
}
this.selected = selected;
};
/**
* We don't inherit from component - it makes the entitymanager too heavy - all faces end up in the register etc..
*/
R3.D3.API.Face.Graphics.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Face.Graphics.prototype.constructor = R3.D3.API.Face.Graphics;
/**
* Clone a Face
* @returns {R3.D3.API.Face}
*/
R3.D3.API.Face.Graphics.prototype.clone = function(){
return new R3.D3.API.Face(
null,
this.v0index,
this.v1index,
this.v2index,
this.materialIndex,
this.uvs,
this.color,
this.vertexColors,
this.vertexNormals,
this.normal,
this.selected
);
};

View File

@ -4,10 +4,6 @@
* @param v0index * @param v0index
* @param v1index * @param v1index
* @param v2index * @param v2index
* @param materialIndex
* @param uvs [[v0uv (R3.Vector2), v1uv(R3.Vector2), v2uv(R3.Vector2)]]
* @param color
* @param vertexColors
* @param vertexNormals * @param vertexNormals
* @param normal * @param normal
* @param selected * @param selected
@ -18,10 +14,6 @@ R3.D3.API.Face = function(
v0index, v0index,
v1index, v1index,
v2index, v2index,
materialIndex,
uvs,
color,
vertexColors,
vertexNormals, vertexNormals,
normal, normal,
selected selected
@ -44,30 +36,6 @@ R3.D3.API.Face = function(
} }
this.v2index = v2index; this.v2index = v2index;
if (R3.Utils.UndefinedOrNull(materialIndex)) {
materialIndex = -1;
}
this.materialIndex = materialIndex;
if (R3.Utils.UndefinedOrNull(uvs)) {
uvs = [[]];
}
this.uvs = uvs;
if (R3.Utils.UndefinedOrNull(color)) {
color = new R3.API.Color();
}
this.color = color;
if (R3.Utils.UndefinedOrNull(vertexColors)) {
vertexColors = [
new R3.API.Color(),
new R3.API.Color(),
new R3.API.Color()
];
}
this.vertexColors = vertexColors;
if (R3.Utils.UndefinedOrNull(vertexNormals)) { if (R3.Utils.UndefinedOrNull(vertexNormals)) {
vertexNormals = []; vertexNormals = [];
} }
@ -99,16 +67,12 @@ R3.D3.API.Face.prototype.constructor = R3.D3.API.Face;
R3.D3.API.Face.prototype.clone = function(){ R3.D3.API.Face.prototype.clone = function(){
return new R3.D3.API.Face( return new R3.D3.API.Face(
null, null,
this.v0index, this.v0index,
this.v1index, this.v1index,
this.v2index, this.v2index,
this.materialIndex, this.vertexNormals,
this.uvs, this.normal,
this.color, this.selected
this.vertexColors,
this.vertexNormals,
this.normal,
this.selected
); );
}; };

View File

@ -13,6 +13,7 @@
* @param gridColor * @param gridColor
* @param cameraIndexEdit * @param cameraIndexEdit
* @param cameraIndexRun * @param cameraIndexRun
* @param cubeCameras
* @param effect * @param effect
* @param composer * @param composer
* @param enableEffect * @param enableEffect
@ -34,6 +35,7 @@ R3.D3.API.Scene = function(
gridColor, gridColor,
cameraIndexEdit, cameraIndexEdit,
cameraIndexRun, cameraIndexRun,
cubeCameras,
effect, effect,
composer, composer,
enableEffect, enableEffect,
@ -103,6 +105,11 @@ R3.D3.API.Scene = function(
} }
this.cameraIndexRun = cameraIndexRun; this.cameraIndexRun = cameraIndexRun;
if (R3.Utils.UndefinedOrNull(cubeCameras)) {
cubeCameras = [];
}
this.cubeCameras = cubeCameras;
if (R3.Utils.UndefinedOrNull(composer)) { if (R3.Utils.UndefinedOrNull(composer)) {
composer = new R3.API.Composer(); composer = new R3.API.Composer();
} }

View File

@ -1,4 +1,4 @@
/** ,/**
* R3.D3.API.Viewport * R3.D3.API.Viewport
* *
* Ignore aspect ratio and make viewport respect x,y,width and height as is * Ignore aspect ratio and make viewport respect x,y,width and height as is

View File

@ -111,8 +111,5 @@ R3.D3.Camera.Cube.prototype.updateInstance = function(property) {
* @param scene * @param scene
*/ */
R3.D3.Camera.Cube.prototype.update = function(renderer, scene) { R3.D3.Camera.Cube.prototype.update = function(renderer, scene) {
this.instance.update(
renderer.instance,
scene.instance
)
}; };

View File

@ -1,289 +1,193 @@
/** /**
* R3.D3.Camera.Orthographic * R3.D3.Camera.Orthographic.FixedAspect
* @param graphics R3.Runtime.Graphics * @param parent
* @param apiD3OBjectOrthographicCamera * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Camera.Orthographic.FixedAspect = function( R3.D3.Camera.Orthographic.FixedAspect = function(
graphics, parent,
apiD3OBjectOrthographicCamera apiComponent
) { ) {
this.graphics = graphics; __RUNTIME_COMPONENT_MACRO__;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiD3OBjectOrthographicCamera)) { R3.D3.API.Camera.Orthographic.FixedAspect.call(
apiD3OBjectOrthographicCamera = {
objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC,
position : R3.API.Vector3(0,0,10),
lookAt: R3.API.Vector3(0,0,-10)
};
}
R3.D3.API.Camera.Orthographic.call(
this, this,
apiD3OBjectOrthographicCamera, apiComponent
apiD3OBjectOrthographicCamera.aspectRatioMode,
apiD3OBjectOrthographicCamera.minWidth,
apiD3OBjectOrthographicCamera.minHeight,
apiD3OBjectOrthographicCamera.width,
apiD3OBjectOrthographicCamera.height,
apiD3OBjectOrthographicCamera.near,
apiD3OBjectOrthographicCamera.far,
apiD3OBjectOrthographicCamera.left,
apiD3OBjectOrthographicCamera.right,
apiD3OBjectOrthographicCamera.top,
apiD3OBjectOrthographicCamera.bottom,
apiD3OBjectOrthographicCamera.zoom
); );
R3.D3.Camera.call( var linkedObjects = {};
R3.D3.Camera.Orthographic.call(
this, this,
this.graphics, parent,
this linkedObjects
); );
}; };
R3.D3.Camera.Orthographic.prototype = Object.create(R3.D3.Camera.prototype); R3.D3.Camera.Orthographic.FixedAspect.prototype = Object.create(R3.D3.Camera.Orthographic.prototype);
R3.D3.Camera.Orthographic.prototype.constructor = R3.D3.Camera.Orthographic; R3.D3.Camera.Orthographic.FixedAspect.prototype.constructor = R3.D3.Camera.Orthographic.FixedAspect;
/** /**
* Creates a camera instance * Creates a camera instance
* @returns {*} * @returns {*}
*/ */
R3.D3.Camera.Orthographic.prototype.createInstance = function() { R3.D3.Camera.Orthographic.FixedAspect.prototype.createInstance = function() {
this.instance = new THREE.OrthographicCamera( /**
this.left, * We need to get the viewport width and height
this.right, * @type {void|*}
this.top, */
this.bottom,
var dimensions = this.getDimensions();
this.instance = this.graphics.OrthographicCamera(
dimensions.left,
dimensions.right,
dimensions.top,
dimensions.bottom,
this.near, this.near,
this.far this.far
); );
if ( R3.Component.prototype.createInstance.call(this);
this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED ||
this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT
) {
if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) {
var size = R3.Utils.GetWindowSize();
this.aspect = size.width / size.height;
}
this.updateFromAspectRatio();
}
R3.D3.Camera.prototype.createInstance.call(this);
}; };
/** /**
* Updates the instance with the current state * Updates the instance with the current state
*/ */
R3.D3.Camera.Orthographic.prototype.updateInstance = function(property) { R3.D3.Camera.Orthographic.FixedAspect.prototype.updateInstance = function(property) {
var size; if (property === 'aspect') {
if (property === 'aspectRatioMode') { var dimensions = this.getDimensions();
if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE) { this.instance.left = dimensions.left;
this.updateFromDimensions(); this.instance.right = dimensions.right;
return; this.instance.top = dimensions.top;
} this.instance.bottom = dimensions.bottom;
if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED) {
this.updateFromAspectRatio();
return;
}
if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) {
size = R3.Utils.GetWindowSize();
this.aspect = size.width / size.height;
this.updateFromAspectRatio();
return;
}
}
if (
property === 'width' ||
property === 'height' ||
property === 'minWidth' ||
property === 'minHeight' ||
property === 'aspect'
) {
if (
this.aspectRatioMode !== R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED &&
this.aspectRatioMode !== R3.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 === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) {
size = R3.Utils.GetWindowSize();
this.aspect = size.width / size.height;
}
this.updateFromAspectRatio();
return;
}
if (
property === 'left' ||
property === 'right' ||
property === 'top' ||
property === 'bottom'
) {
if (
this.aspectRatioMode === R3.D3.API.Camera.ASPECT_RATIO_MODE_FIXED ||
this.aspectRatioMode === R3.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();
return;
}
if (property === 'zoom') {
this.instance.zoom = this.zoom;
this.instance.updateProjectionMatrix(); this.instance.updateProjectionMatrix();
return;
} }
R3.D3.Camera.prototype.updateInstance.call(this, property); R3.D3.Camera.Orthographic.prototype.updateInstance.call(this, property);
}; };
/** /**
* Converts a R3.D3.Camera to a R3.D3.API.Camera * This calculates the dimensions of the camera based on the following example info:
* @returns {R3.D3.API.Camera} *
* aspect = width
* ------
* height
*
* width = aspect * height;
* height = width / aspect;
*
* aspect > 1 (width > height) (landscape)
* aspect < 1 (height > width) (portrait)
*
* 4 / 3 = 1.33333 (1920 x 1440)
* 16 / 9 = 1.77777 (1920 x 1080)
*
* w h w h
* 9 / 16 = 0.5625 (1080 x 1920) - required
* 3 / 4 = 0.75 (1440 x 1920) - current
*
* @returns {{left: number, right: number, top: number, bottom: number}}
*/ */
R3.D3.Camera.Orthographic.prototype.toApiObject = function() { R3.D3.Camera.Orthographic.FixedAspect.prototype.getDimensions = function() {
var apiCamera = R3.D3.Camera.prototype.toApiObject.call(this);
var apiOrthographicCamera = new R3.D3.API.Camera.Orthographic( var size = R3.Utils.GetWindowSize();
apiCamera,
this.aspectRatioMode,
this.minWidth,
this.minHeight,
this.width,
this.height,
this.near,
this.far,
this.left,
this.right,
this.top,
this.bottom,
this.zoom
);
return apiOrthographicCamera; var currentAspect = size.width / size.height;
};
R3.D3.Camera.Orthographic.prototype.updateFromInstance = function() { var width, height;
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;
R3.D3.Camera.prototype.updateFromInstance.call(this);
};
R3.D3.Camera.Orthographic.prototype.updateFromAspectRatio = function() { if (currentAspect > 1) {
var requiredAspect = this.minWidth / this.minHeight;
if (this.aspect < requiredAspect) {
/** /**
* Make height dependend on width * Width is greater than height (landscape)
*/ */
this.width = this.minWidth; if (this.aspect < 1) {
this.height = this.minWidth / this.aspect;
// if (this.height < this.minHeight) { /**
// /** * The required aspect is more high than wide - use the full height
// * We have a problem - our new height is less than our minimum height */
// */ width = this.aspect * size.height;
// height = size.height;
//
// ; } else {
// /**
// if (requiredAspect < this.aspect) { * The required aspect is also more wide than high - so we have another two possibilities:
// this.width = requiredAspect * this.height; * a) The required aspect is greater than the current aspect - this means the required aspect is less high
// } else { * than the current aspect - we can use the full width
// this.height = this.minHeight; *
// this.width = this.aspect * this.height; * b) The required aspect is less than the current aspect - this means the required aspect is higher than
// } * the current aspect - we need to determine a new width based on the current height
// */
// if (this.aspect > currentAspect) {
// } else { /**
// * a)
// /** */
// * Try to fit our game into the window width = size.width;
// * @type {number} height = width / this.aspect;
// */ } else {
// // var requiredAspect = this.minWidth / this.minHeight; /**
// // this.width = requiredAspect * this.height; * b)
// } */
height = size.height;
width = this.aspect * height;
}
}
} else { } else {
/** /**
* Make width dependend on height * The height is greater than the width (portrait)
*/ */
this.height = this.minHeight; if (this.aspect > 1) {
this.width = this.aspect * this.minHeight;
// /**
// if (this.width < this.minWidth) { * The required aspect is landscape in a portrait mode - use the full width and calculate the new height
// /** */
// * We have a problem - our new width is less than our minimum width width = size.width;
// */ height = width / this.aspect;
// this.width = this.minWidth;
// this.height = this.width / this.aspect; } else {
// }
/**
* The required aspect is also more high than wide (portrait) - we have again, two possibilities
* a) The required aspect is greater than the current aspect - this means the required aspect does not fit
* the full width of the current aspect - use the full width of the current size and determine a new height
*
* b) The required aspect is less than the current aspect - this means that the required aspect is less wide
* than the current aspect, so we can use the full height of the current size and determine a new width
*/
if (this.aspect > currentAspect) {
width = size.width;
height = width / this.aspect;
} else {
height = size.height;
width = this.aspect * height;
}
}
} }
this.left = this.width / -2; /**
this.right = this.width / 2; * We now have the correct width and height of of the camera
*/
this.top = this.height / 2; return {
this.bottom = this.height / -2; left : width / -2,
right : width / 2,
this.instance.left = this.left; top : height / 2,
this.instance.right = this.right; bottom : height / -2
this.instance.top = this.top; }
this.instance.bottom = this.bottom;
this.instance.updateProjectionMatrix();
}; };
R3.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

@ -0,0 +1,88 @@
/**
* R3.D3.Camera.Orthographic.ScaledAspect
* @param parent
* @param apiComponent
* @constructor
*/
R3.D3.Camera.Orthographic.ScaledAspect = function(
parent,
apiComponent
) {
__RUNTIME_COMPONENT_MACRO__;
R3.D3.API.Camera.Orthographic.ScaledAspect.call(
this,
apiComponent,
apiComponent.left,
apiComponent.right,
apiComponent.top,
apiComponent.bottom
);
var linkedObjects = {};
R3.D3.Camera.Orthographic.call(
this,
parent,
linkedObjects
);
};
R3.D3.Camera.Orthographic.ScaledAspect.prototype = Object.create(R3.D3.Camera.Orthographic.prototype);
R3.D3.Camera.Orthographic.ScaledAspect.prototype.constructor = R3.D3.Camera.Orthographic.ScaledAspect;
/**
* Creates a camera instance
* @returns {*}
*/
R3.D3.Camera.Orthographic.ScaledAspect.prototype.createInstance = function() {
this.instance = new this.graphics.OrthographicCamera(
this.left,
this.right,
this.top,
this.bottom,
this.near,
this.far
);
R3.Component.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.D3.Camera.Orthographic.ScaledAspect.prototype.updateInstance = function(property) {
if (property === 'left') {
this.instance.left = this.left;
this.instance.updateProjectionMatrix();
this.aspect = (this.right - this.left) / (this.top - this.bottom);
return;
}
if (property === 'right') {
this.instance.right = this.right;
this.instance.updateProjectionMatrix();
this.aspect = (this.right - this.left) / (this.top - this.bottom);
return;
}
if (property === 'top') {
this.instance.top = this.top;
this.instance.updateProjectionMatrix();
this.aspect = (this.right - this.left) / (this.top - this.bottom);
return;
}
if (property === 'bottom') {
this.instance.bottom = this.bottom;
this.instance.updateProjectionMatrix();
this.aspect = (this.right - this.left) / (this.top - this.bottom);
return;
}
R3.D3.Camera.Orthographic.prototype.updateInstance.call(this, property);
};

View File

@ -1,289 +0,0 @@
/**
* R3.D3.Camera.Orthographic
* @param graphics R3.Runtime.Graphics
* @param apiD3OBjectOrthographicCamera
* @constructor
*/
R3.D3.Camera.Orthographic.FixedAspect = function(
graphics,
apiD3OBjectOrthographicCamera
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiD3OBjectOrthographicCamera)) {
apiD3OBjectOrthographicCamera = {
objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC,
position : R3.API.Vector3(0,0,10),
lookAt: R3.API.Vector3(0,0,-10)
};
}
R3.D3.API.Camera.Orthographic.call(
this,
apiD3OBjectOrthographicCamera,
apiD3OBjectOrthographicCamera.aspectRatioMode,
apiD3OBjectOrthographicCamera.minWidth,
apiD3OBjectOrthographicCamera.minHeight,
apiD3OBjectOrthographicCamera.width,
apiD3OBjectOrthographicCamera.height,
apiD3OBjectOrthographicCamera.near,
apiD3OBjectOrthographicCamera.far,
apiD3OBjectOrthographicCamera.left,
apiD3OBjectOrthographicCamera.right,
apiD3OBjectOrthographicCamera.top,
apiD3OBjectOrthographicCamera.bottom,
apiD3OBjectOrthographicCamera.zoom
);
R3.D3.Camera.call(
this,
this.graphics,
this
);
};
R3.D3.Camera.Orthographic.prototype = Object.create(R3.D3.Camera.prototype);
R3.D3.Camera.Orthographic.prototype.constructor = R3.D3.Camera.Orthographic;
/**
* Creates a camera instance
* @returns {*}
*/
R3.D3.Camera.Orthographic.prototype.createInstance = function() {
this.instance = new THREE.OrthographicCamera(
this.left,
this.right,
this.top,
this.bottom,
this.near,
this.far
);
if (
this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED ||
this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT
) {
if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) {
var size = R3.Utils.GetWindowSize();
this.aspect = size.width / size.height;
}
this.updateFromAspectRatio();
}
R3.D3.Camera.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.D3.Camera.Orthographic.prototype.updateInstance = function(property) {
var size;
if (property === 'aspectRatioMode') {
if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE) {
this.updateFromDimensions();
return;
}
if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED) {
this.updateFromAspectRatio();
return;
}
if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) {
size = R3.Utils.GetWindowSize();
this.aspect = size.width / size.height;
this.updateFromAspectRatio();
return;
}
}
if (
property === 'width' ||
property === 'height' ||
property === 'minWidth' ||
property === 'minHeight' ||
property === 'aspect'
) {
if (
this.aspectRatioMode !== R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED &&
this.aspectRatioMode !== R3.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 === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) {
size = R3.Utils.GetWindowSize();
this.aspect = size.width / size.height;
}
this.updateFromAspectRatio();
return;
}
if (
property === 'left' ||
property === 'right' ||
property === 'top' ||
property === 'bottom'
) {
if (
this.aspectRatioMode === R3.D3.API.Camera.ASPECT_RATIO_MODE_FIXED ||
this.aspectRatioMode === R3.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();
return;
}
if (property === 'zoom') {
this.instance.zoom = this.zoom;
this.instance.updateProjectionMatrix();
}
R3.D3.Camera.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.D3.Camera to a R3.D3.API.Camera
* @returns {R3.D3.API.Camera}
*/
R3.D3.Camera.Orthographic.prototype.toApiObject = function() {
var apiCamera = R3.D3.Camera.prototype.toApiObject.call(this);
var apiOrthographicCamera = new R3.D3.API.Camera.Orthographic(
apiCamera,
this.aspectRatioMode,
this.minWidth,
this.minHeight,
this.width,
this.height,
this.near,
this.far,
this.left,
this.right,
this.top,
this.bottom,
this.zoom
);
return apiOrthographicCamera;
};
R3.D3.Camera.Orthographic.prototype.updateFromInstance = function() {
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;
R3.D3.Camera.prototype.updateFromInstance.call(this);
};
R3.D3.Camera.Orthographic.prototype.updateFromAspectRatio = function() {
var requiredAspect = this.minWidth / this.minHeight;
if (this.aspect < requiredAspect) {
/**
* 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
// */
//
//
// ;
//
// if (requiredAspect < this.aspect) {
// this.width = requiredAspect * this.height;
// } else {
// this.height = this.minHeight;
// this.width = this.aspect * this.height;
// }
//
//
// } else {
//
// /**
// * Try to fit our game into the window
// * @type {number}
// */
// // var requiredAspect = this.minWidth / this.minHeight;
// // this.width = requiredAspect * 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();
};
R3.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

@ -1,46 +1,21 @@
/** /**
* R3.D3.Camera.Orthographic * R3.D3.Camera.Orthographic
* @param graphics R3.Runtime.Graphics *
* @param apiD3OBjectOrthographicCamera * - This is an abstract class - should not be instantiated directly
*
* @param parent
* @param linkedObjects
* @constructor * @constructor
*/ */
R3.D3.Camera.Orthographic = function( R3.D3.Camera.Orthographic = function(
graphics, parent,
apiD3OBjectOrthographicCamera linkedObjects
) { ) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiD3OBjectOrthographicCamera)) {
apiD3OBjectOrthographicCamera = {
objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC,
position : R3.API.Vector3(0,0,10),
lookAt: R3.API.Vector3(0,0,-10)
};
}
R3.D3.API.Camera.Orthographic.call(
this,
apiD3OBjectOrthographicCamera,
apiD3OBjectOrthographicCamera.aspectRatioMode,
apiD3OBjectOrthographicCamera.minWidth,
apiD3OBjectOrthographicCamera.minHeight,
apiD3OBjectOrthographicCamera.width,
apiD3OBjectOrthographicCamera.height,
apiD3OBjectOrthographicCamera.near,
apiD3OBjectOrthographicCamera.far,
apiD3OBjectOrthographicCamera.left,
apiD3OBjectOrthographicCamera.right,
apiD3OBjectOrthographicCamera.top,
apiD3OBjectOrthographicCamera.bottom,
apiD3OBjectOrthographicCamera.zoom
);
R3.D3.Camera.call( R3.D3.Camera.call(
this, this,
this.graphics, parent,
this linkedObjects
); );
}; };
@ -48,162 +23,28 @@ R3.D3.Camera.Orthographic = function(
R3.D3.Camera.Orthographic.prototype = Object.create(R3.D3.Camera.prototype); R3.D3.Camera.Orthographic.prototype = Object.create(R3.D3.Camera.prototype);
R3.D3.Camera.Orthographic.prototype.constructor = R3.D3.Camera.Orthographic; R3.D3.Camera.Orthographic.prototype.constructor = R3.D3.Camera.Orthographic;
/**
* Creates a camera instance
* @returns {*}
*/
R3.D3.Camera.Orthographic.prototype.createInstance = function() {
this.instance = new THREE.OrthographicCamera(
this.left,
this.right,
this.top,
this.bottom,
this.near,
this.far
);
if (
this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED ||
this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT
) {
if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) {
var size = R3.Utils.GetWindowSize();
this.aspect = size.width / size.height;
}
this.updateFromAspectRatio();
}
R3.D3.Camera.prototype.createInstance.call(this);
};
/** /**
* Updates the instance with the current state * Updates the instance with the current state
*/ */
R3.D3.Camera.Orthographic.prototype.updateInstance = function(property) { R3.D3.Camera.Orthographic.prototype.updateInstance = function(property) {
var size; if (property === 'near') {
this.instance.near = this.near;
if (property === 'aspectRatioMode') {
if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE) {
this.updateFromDimensions();
return;
}
if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED) {
this.updateFromAspectRatio();
return;
}
if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) {
size = R3.Utils.GetWindowSize();
this.aspect = size.width / size.height;
this.updateFromAspectRatio();
return;
}
}
if (
property === 'width' ||
property === 'height' ||
property === 'minWidth' ||
property === 'minHeight' ||
property === 'aspect'
) {
if (
this.aspectRatioMode !== R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED &&
this.aspectRatioMode !== R3.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 === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) {
size = R3.Utils.GetWindowSize();
this.aspect = size.width / size.height;
}
this.updateFromAspectRatio();
return; return;
} }
if ( if (property === 'far') {
property === 'left' || this.instance.far = this.far;
property === 'right' ||
property === 'top' ||
property === 'bottom'
) {
if (
this.aspectRatioMode === R3.D3.API.Camera.ASPECT_RATIO_MODE_FIXED ||
this.aspectRatioMode === R3.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();
return;
} }
if (property === 'zoom') { if (property === 'zoom') {
this.instance.zoom = this.zoom; this.instance.zoom = this.zoom;
this.instance.updateProjectionMatrix(); this.instance.updateProjectionMatrix()
} }
R3.D3.Camera.prototype.updateInstance.call(this, property); R3.D3.Camera.prototype.updateInstance.call(this, property);
}; };
/**
* Converts a R3.D3.Camera to a R3.D3.API.Camera
* @returns {R3.D3.API.Camera}
*/
R3.D3.Camera.Orthographic.prototype.toApiObject = function() {
var apiCamera = R3.D3.Camera.prototype.toApiObject.call(this);
var apiOrthographicCamera = new R3.D3.API.Camera.Orthographic(
apiCamera,
this.aspectRatioMode,
this.minWidth,
this.minHeight,
this.width,
this.height,
this.near,
this.far,
this.left,
this.right,
this.top,
this.bottom,
this.zoom
);
return apiOrthographicCamera;
};
R3.D3.Camera.Orthographic.prototype.updateFromInstance = function() {
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;
R3.D3.Camera.prototype.updateFromInstance.call(this);
};
R3.D3.Camera.Orthographic.prototype.updateFromAspectRatio = function() { R3.D3.Camera.Orthographic.prototype.updateFromAspectRatio = function() {

View File

@ -1,33 +1,28 @@
/** /**
* R3.D3.Camera.Perspective.Stereo * R3.D3.Camera.Perspective.Stereo
* @param graphics R3.Runtime.Graphics * @param parent
* @param apiD3ObjectPerspectiveStereoCamera * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Camera.Perspective.Stereo = function( R3.D3.Camera.Perspective.Stereo = function(
graphics, parent,
apiD3ObjectPerspectiveStereoCamera apiComponent
) { ) {
this.graphics = graphics; __RUNTIME_COMPONENT_MACRO__;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiD3ObjectPerspectiveStereoCamera)) {
apiD3ObjectPerspectiveStereoCamera = {
objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE_STEREO
};
}
linkedObjects.effect = R3.D3.Effect;
R3.D3.API.Camera.Perspective.Stereo.call( R3.D3.API.Camera.Perspective.Stereo.call(
this, this,
apiD3ObjectPerspectiveStereoCamera, apiComponent,
apiD3ObjectPerspectiveStereoCamera.stereoMode apiComponent.stereoMode
); );
var linkedObjects = {};
R3.D3.Camera.call( R3.D3.Camera.call(
this, this,
this.graphics, parent,
this linkedObjects
); );
}; };
@ -41,20 +36,15 @@ R3.D3.Camera.Perspective.Stereo.prototype.constructor = R3.D3.Camera.Perspective
*/ */
R3.D3.Camera.Perspective.Stereo.prototype.createInstance = function() { R3.D3.Camera.Perspective.Stereo.prototype.createInstance = function() {
this.instance = new THREE.PerspectiveCamera(); this.instance = this.graphics.StereoCamera(
this.fov,
this.aspect,
this.near,
this.far,
this.stereoMode
);
var instance = new THREE.StereoCamera(); R3.Component.prototype.createInstance.call(this);
for (var property in instance) {
if (
instance.hasOwnProperty(property) ||
typeof instance[property] === 'function'
) {
this.instance[property] = instance[property];
}
}
R3.D3.Camera.prototype.createInstance.call(this);
}; };
/** /**
@ -67,21 +57,5 @@ R3.D3.Camera.Perspective.Stereo.prototype.updateInstance = function(property) {
return; return;
} }
R3.D3.Camera.prototype.updateInstance.call(this, property); R3.D3.Camera.Perspective.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.D3.Camera to a R3.D3.API.Camera
* @returns {R3.D3.API.Camera}
*/
R3.D3.Camera.Perspective.Stereo.prototype.toApiObject = function() {
var apiCamera = R3.D3.Camera.prototype.toApiObject.call(this);
var apiStereoCamera = new R3.D3.API.Camera.Perspective.Stereo(
apiCamera,
this.stereoMode
);
return apiStereoCamera;
}; };

View File

@ -1,39 +1,34 @@
/** /**
* R3.D3.Camera.Perspective * R3.D3.Camera.Perspective
* @param graphics R3.Runtime.Graphics * @param parent
* @param apiD3ObjectPerspectiveCamera * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Camera.Perspective = function( R3.D3.Camera.Perspective = function(
graphics, parent,
apiD3ObjectPerspectiveCamera apiComponent
) { ) {
this.graphics = graphics; __RUNTIME_COMPONENT_MACRO__;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiD3ObjectPerspectiveCamera)) {
apiD3ObjectPerspectiveCamera = {
objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE
};
}
R3.D3.API.Camera.Perspective.call( R3.D3.API.Camera.Perspective.call(
this, this,
apiD3ObjectPerspectiveCamera, apiComponent,
apiD3ObjectPerspectiveCamera.near, apiComponent.near,
apiD3ObjectPerspectiveCamera.far, apiComponent.far,
apiD3ObjectPerspectiveCamera.fov, apiComponent.fov,
apiD3ObjectPerspectiveCamera.filmGauge, apiComponent.filmGauge,
apiD3ObjectPerspectiveCamera.filmOffset, apiComponent.filmOffset,
apiD3ObjectPerspectiveCamera.focus, apiComponent.focus,
apiD3ObjectPerspectiveCamera.zoom apiComponent.zoom
); );
var linkedObjects = {};
R3.D3.Camera.call( R3.D3.Camera.call(
this, this,
this.graphics, parent,
this linkedObjects
); );
}; };
@ -47,7 +42,7 @@ R3.D3.Camera.Perspective.prototype.constructor = R3.D3.Camera.Perspective;
*/ */
R3.D3.Camera.Perspective.prototype.createInstance = function() { R3.D3.Camera.Perspective.prototype.createInstance = function() {
this.instance = new THREE.PerspectiveCamera( this.instance = this.graphics.PerspectiveCamera(
this.fov, this.fov,
this.aspect, this.aspect,
this.near, this.near,
@ -59,7 +54,9 @@ R3.D3.Camera.Perspective.prototype.createInstance = function() {
this.instance.focus = this.focus; this.instance.focus = this.focus;
this.instance.zoom = this.zoom; this.instance.zoom = this.zoom;
R3.D3.Camera.prototype.createInstance.call(this); this.instance.updateProjectionMatrix();
R3.Component.prototype.createInstance.call(this);
}; };
/** /**
@ -111,36 +108,3 @@ R3.D3.Camera.Perspective.prototype.updateInstance = function(property) {
R3.D3.Camera.prototype.updateInstance.call(this, property); R3.D3.Camera.prototype.updateInstance.call(this, property);
}; };
/**
* Converts a R3.D3.Camera to a R3.D3.API.Camera
* @returns {R3.D3.API.Camera}
*/
R3.D3.Camera.Perspective.prototype.toApiObject = function() {
var apiCamera = R3.D3.Camera.prototype.toApiObject.call(this);
var apiPerspectiveCamera = new R3.D3.API.Camera.Perspective(
apiCamera,
this.near,
this.far,
this.fov,
this.filmGauge,
this.filmOffset,
this.focus,
this.zoom
);
return apiPerspectiveCamera;
};
R3.D3.Camera.Perspective.prototype.updateFromInstance = function() {
this.near = this.instance.near;
this.far = this.instance.far;
this.fov = this.instance.fov;
this.filmGauge = this.instance.filmGauge;
this.filmOffset = this.instance.filmOffset;
this.focus = this.instance.focus;
this.zoom = this.instance.zoom;
R3.D3.Camera.prototype.updateFromInstance.call(this);
};

View File

@ -0,0 +1,98 @@
/**
* R3.D3.Composer.RenderTarget
* @param parent
* @param apiComponent
* @constructor
*/
R3.D3.Composer.RenderTarget = function(
parent,
apiComponent
) {
__RUNTIME_COMPONENT_MACRO__;
R3.D3.API.Composer.RenderTarget.call(
this,
apiComponent,
apiComponent.renderTarget
);
if (this.renderTarget instanceof R3.D3.API.RenderTarget) {
this.renderTarget = R3.Component.ConstructFromObject(this.renderTarget);
}
var linkedObjects = {
renderTarget : R3.D3.RenderTarget
};
R3.D3.Composer.call(
this,
parent,
linkedObjects
);
};
R3.D3.Composer.RenderTarget.prototype = Object.create(R3.D3.Composer.prototype);
R3.D3.Composer.RenderTarget.prototype.constructor = R3.D3.Composer.RenderTarget;
/**
* Creates a Composer instance
* @returns {*}
*/
R3.D3.Composer.RenderTarget.prototype.createInstance = function() {
if (R3.Utils.UndefinedOrNull(this.renderTarget)) {
throw new Error('Need at least a renderTarget to create this composer object instance')
}
this.width = this.renderTarget.width;
this.height = this.renderTarget.height;
/**
* Right - now we should have the right size of the composer - we can continue
*/
this.instance = this.graphics.Composer(
null,
this.renderTarget,
this.passes,
{
width : this.width,
height : this.height
}
);
R3.Component.prototype.createInstance.call(this);
};
/**
* Updates Composer instance
*/
R3.D3.Composer.RenderTarget.prototype.updateInstance = function(property) {
if (property === 'rendererTarget') {
console.warn('TODO: renderTarget update');
return;
}
R3.D3.Composer.prototype.updateInstance.call(this, property);
};
/**
* Returns true if this composer is ready
* @returns {boolean}
*/
R3.D3.Composer.RenderTarget.prototype.ready = function() {
if (R3.Utils.UndefinedOrNull(this.instance)) {
return false;
}
if (R3.Utils.UndefinedOrNull(this.renderTarget)) {
return false;
}
return R3.D3.Composer.prototype.ready.call(this);
};

View File

@ -0,0 +1,129 @@
/**
* R3.D3.Composer.Renderer
* @param parent
* @param apiComponent
* @constructor
*/
R3.D3.Composer.Renderer = function(
parent,
apiComponent
) {
__RUNTIME_COMPONENT_MACRO__;
R3.D3.API.Composer.Renderer.call(
this,
apiComponent,
apiComponent.renderer
);
if (this.renderer instanceof R3.API.Renderer.D3) {
this.renderer = R3.Component.ConstructFromObject(this.renderer);
}
var linkedObjects = {
renderer : R3.Renderer.D3
};
R3.D3.Composer.call(
this,
parent,
linkedObjects
);
};
R3.D3.Composer.Renderer.prototype = Object.create(R3.D3.Composer.prototype);
R3.D3.Composer.Renderer.prototype.constructor = R3.D3.Composer.Renderer;
/**
* Creates a Composer instance
* @returns {*}
*/
R3.D3.Composer.Renderer.prototype.createInstance = function() {
if (
R3.Utils.UndefinedOrNull(this.renderer)
) {
throw new Error('Need at least a renderer to create a composer renderer object')
}
if (
this.renderer instanceof R3.Renderer.D3.Target ||
this.renderer instanceof R3.Renderer.D3.Canvas.Target
) {
this.width = this.renderer.target.width;
this.height = this.renderer.target.height;
} else if (
this.renderer instanceof R3.Renderer.D3.Canvas
) {
/**
* This composer belongs to a scene which belongs to a viewport
*/
var viewport = this.getFirstParent(R3.D3.Viewport);
/**
* The canvas is associated to the renderer - it has the actual size of the canvas and we need the size
* of the viewport to determine the actual pixel size of this composer
*/
var canvas = this.renderer.canvas;
this.width = canvas.width * viewport.width;
this.height = canvas.height * viewport.height;
} else {
throw new Error('Unhandled renderer type : ' + this.renderer);
}
/**
* Right - now we should have the right size of the composer - we can continue
*/
this.instance = this.graphics.Composer(
renderer,
null,
this.passes,
{
width : this.width,
height : this.height
}
);
R3.Component.prototype.createInstance.call(this);
};
/**
* Updates Composer instance
*/
R3.D3.Composer.Renderer.prototype.updateInstance = function(property) {
if (property === 'renderer') {
console.warn('todo update composer renderer');
return;
}
R3.D3.Composer.prototype.updateInstance.call(this, property);
};
/**
* Checks if this composer is ready for rendering
* @returns {boolean}
*/
R3.D3.Composer.Renderer.prototype.ready = function() {
if (R3.Utils.UndefinedOrNull(this.instance)) {
return false;
}
if (R3.Utils.UndefinedOrNull(this.renderer)) {
return false;
}
return R3.D3.Composer.prototype.ready.call(this);
};

View File

@ -1,143 +1,61 @@
/** /**
* Renders a scene with a camera * R3.D3.Composer
* @param graphics R3.Runtime.Graphics *
* @param apiComposer R3.D3.API.Composer * - This is an abstract class, don't instatiate it directly
*
* @param parent
* @param linkedObjects
* @constructor * @constructor
*/ */
R3.D3.Composer = function( R3.D3.Composer = function(
graphics, parent,
apiComposer linkedObjects
) { ) {
this.graphics = graphics; if (R3.Utils.UndefinedOrNull(linkedObjects)) {
this.graphics.isNotThreeThrow(); linkedObjects = {};
if (R3.Utils.UndefinedOrNull(apiComposer)) {
apiComposer = {};
} }
R3.D3.API.Composer.call( this.passes = this.passes.reduce(
this, function(result, pass) {
apiComposer.id,
apiComposer.name, if (pass instanceof R3.API.Component) {
apiComposer.parent, pass = R3.Component.ConstructFromObject(pass);
apiComposer.autoUpdateSize, }
apiComposer.width,
apiComposer.height, result.push(pass);
apiComposer.renderer,
apiComposer.renderTarget, return result;
apiComposer.passes },
[]
); );
linkedObjects.passes = [R3.D3.Pass];
R3.Component.call( R3.Component.call(
this, this,
{ parent,
'renderer' : R3.Renderer, linkedObjects
'renderTarget' : R3.D3.RenderTarget,
'passes' : [R3.D3.Pass]
}
); );
}; };
R3.D3.Composer.prototype = Object.create(R3.Component.prototype); R3.D3.Composer.prototype = Object.create(R3.Component.prototype);
R3.D3.Composer.prototype.constructor = R3.D3.Composer; R3.D3.Composer.prototype.constructor = R3.D3.Composer;
/**
* Creates a Composer instance
* @returns {*}
*/
R3.D3.Composer.prototype.createInstance = function() {
if (
R3.Utils.UndefinedOrNull(this.renderer) ||
R3.Utils.UndefinedOrNull(this.renderer.instance)
) {
console.warn('renderer not ready');
return;
}
var renderTargetInstance = undefined;
if (
R3.Utils.Defined(this.renderTarget) &&
R3.Utils.Defined(this.renderTarget.instance)
) {
renderTargetInstance = this.renderTarget.instance;
}
this.instance = new THREE.EffectComposer(
this.renderer.instance,
renderTargetInstance
);
this.passes.map(
function(pass) {
if (R3.Utils.UndefinedOrNull(pass.instance)) {
console.warn('pass not ready');
return;
}
this.instance.addPass(pass.instance);
}.bind(this)
);
if (this.autoUpdateSize) {
var size = R3.Utils.GetWindowSize();
this.width = size.width;
this.height = size.height;
}
this.instance.setSize(
this.width,
this.height
);
console.log('Constructed a composer instance');
R3.Component.prototype.createInstance.call(this);
};
/** /**
* Updates Composer instance * Updates Composer instance
*/ */
R3.D3.Composer.prototype.updateInstance = function(property) { R3.D3.Composer.prototype.updateInstance = function(property) {
if (property === 'renderer') { if (property === 'width') {
this.instance.setSize(
if (R3.Utils.UndefinedOrNull(this.instance)) { this.width,
this.createInstance(); this.height
} );
return; return;
} }
if (property === 'renderTarget') { if (property === 'height') {
if (
R3.Utils.Defined(this.instance) &&
R3.Utils.Defined(this.renderTarget) &&
R3.Utils.Defined(this.renderTarget.instance)
) {
this.instance.reset(this.renderTarget.instance);
}
return;
}
if (
property === 'width' ||
property === 'height' ||
property === 'autoUpdateSize'
) {
if (this.autoUpdateSize) {
var size = R3.Utils.GetWindowSize();
this.width = size.width;
this.height = size.height;
}
this.instance.setSize( this.instance.setSize(
this.width, this.width,
this.height this.height
@ -159,10 +77,11 @@ R3.D3.Composer.prototype.updateInstance = function(property) {
this.instance.addPass(pass.instance); this.instance.addPass(pass.instance);
console.log('adding pass : ' + pass.name);
}.bind(this) }.bind(this)
) );
console.warn('TODO test composer passes update');
//this.instance.reset();
} }
R3.Component.prototype.updateInstance.call(this, property); R3.Component.prototype.updateInstance.call(this, property);
@ -186,6 +105,9 @@ R3.D3.Composer.prototype.render = function() {
this.instance.render(); this.instance.render();
}; };
/**
* True if ready
*/
R3.D3.Composer.prototype.ready = function() { R3.D3.Composer.prototype.ready = function() {
if (this.passes.length === 0) { if (this.passes.length === 0) {
@ -202,28 +124,3 @@ R3.D3.Composer.prototype.ready = function() {
true true
) )
}; };
/**
* R3.D3.Composer to R3.D3.API.Composer
* @returns {R3.D3.API.Composer}
*/
R3.D3.Composer.prototype.toApiObject = function() {
var apiComposer = new R3.D3.API.Composer(
this.id,
this.name,
R3.Utils.IdOrNull(this.parent),
this.autoUpdateSize,
this.width,
this.height,
R3.Utils.IdOrNull(this.renderer),
R3.Utils.IdOrNull(this.renderTarget),
this.passes.map(
function(pass) {
return R3.Utils.IdOrNull(pass);
}
)
);
return apiComposer;
};

View File

@ -1,55 +1,40 @@
/** /**
* R3.D3.Effect * R3.D3.Effect
* @param graphics R3.Runtime.Graphics * @param parent
* @param apiEffect R3.D3.API.Effect * @param linkedObjects
* @constructor * @constructor
*/ */
R3.D3.Effect = function( R3.D3.Effect = function(
graphics, parent,
apiEffect linkedObjects
) { ) {
this.graphics = graphics; if (R3.Utils.UndefinedOrNull(linkedObjects)) {
this.graphics.isNotThreeThrow(); linkedObjects = {};
if (R3.Utils.UndefinedOrNull(apiEffect)) {
apiEffect = {};
} }
R3.D3.API.Effect.call( if (this.renderer instanceof R3.API.Component) {
this, this.renderer = R3.Component.ConstructFromObject(this.renderer);
apiEffect.id, }
apiEffect.name,
apiEffect.effectType, linkedObjects.renderer = R3.Renderer.D3;
apiEffect.parent,
apiEffect.renderer, R3.Event.Subscribe(
apiEffect.width, R3.Event.RENDERER_SIZE_CHANGE,
apiEffect.height function(renderer) {
var size = renderer.getSize();
this.width = size.width;
this.height = size.height;
this.updateInstance('size');
}.bind(this)
); );
if (R3.Utils.UndefinedOrNull(this.render)) {
/**
* We don't have a renderer - get a handle on the project and initialize the renderer from there
*/
R3.Event.Emit(
R3.Event.GET_PROJECT,
function(project) {
/**
* Assign the last created renderer to this effect
*/
this.renderer = project.renderers[project.renderers.length - 1];
}.bind(this)
);
}
var linkedObjects = {
renderer : R3.Renderer
};
R3.Component.call( R3.Component.call(
this, this,
parent,
linkedObjects linkedObjects
); );
}; };
@ -59,26 +44,10 @@ R3.D3.Effect.prototype.constructor = R3.D3.Effect;
R3.D3.Effect.prototype.createInstance = function() { R3.D3.Effect.prototype.createInstance = function() {
if (!this.instance) { this.updateInstance('size');
console.warn('call this child create instance first');
return;
}
var width = this.width;
var height = this.height;
if (this.renderer && this.renderer.instance) {
var size = this.renderer.getSize();
width = size.width;
height = size.height;
}
this.setSize(
width,
height
);
R3.Component.prototype.createInstance.call(this); R3.Component.prototype.createInstance.call(this);
}; };
/** /**
@ -86,110 +55,43 @@ R3.D3.Effect.prototype.createInstance = function() {
*/ */
R3.D3.Effect.prototype.updateInstance = function(property) { R3.D3.Effect.prototype.updateInstance = function(property) {
if (R3.Utils.UndefinedOrNull(property)) { if (property === 'size' ||
console.warn('no camera property specified for : ' + this.name); property === 'width' ||
}
if (property === 'effectType') {
console.warn('todo: update effect type');
return;
}
if (
property === 'width' ||
property === 'height' property === 'height'
) { ) {
this.setSize( this.instance.setSize(
this.width, this.width,
this.height this.height
) )
} }
if (property === 'renderer') { if (property === 'renderer') {
if (property === 'renderer') {
if ( console.warn('TODO: renderer update');
R3.Utils.Defined(this.renderer) &&
R3.Utils.Defined(this.renderer.instance)
) {
if (R3.Utils.UndefinedOrNull(this.instance)) { if (
this.createInstance(); R3.Utils.Defined(this.renderer) &&
} else { R3.Utils.Defined(this.renderer.instance)
this.instance.dispose(); ) {
this.createInstance();
} var size = this.renderer.getSize();
this.width = size.width;
this.height = size.height;
if (R3.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
} else {
this.instance.dispose();
this.createInstance();
} }
} else {
console.warn('The renderer was unassigned - this wil break things - do not save now');
} }
return; return;
} }
R3.Component.prototype.updateInstance.call(this, property); R3.Component.prototype.updateInstance.call(this, property);
}; };
/**
* Convenience function to set effect size
* @param width
* @param height
*/
R3.D3.Effect.prototype.setSize = function(width, height) {
this.instance.setSize(
width,
height
);
};
/**
* Convenience function to render a scene / camera with this effect
* @param scene
* @param camera
*/
R3.D3.Effect.prototype.render = function(scene, camera) {
this.instance.render(
scene.instance,
camera.instance
);
};
/**
*
* @param scene
* @param camera
* @returns {boolean}
*/
R3.D3.Effect.prototype.ready = function(scene, camera) {
if (!this.instance) {
return false;
}
if (!scene.instance) {
return false;
}
if (!camera.instance) {
return false;
}
return true;
};
/**
* Converts a R3.D3.Effect to a new R3.D3.API.Effect
* @returns {R3.D3.API.Effect}
*/
R3.D3.Effect.prototype.toApiObject = function() {
return new R3.D3.API.Effect(
this.id,
this.name,
this.effectType,
R3.Utils.IdOrNull(this.parent),
R3.Utils.IdOrNull(this.renderer),
this.width,
this.height
);
};

View File

@ -1,32 +1,24 @@
/** /**
* R3.D3.Effect.Anaglyph * R3.D3.Effect.Anaglyph
* @param graphics R3.Runtime.Graphics * @param parent
* @param apiAnaglyphEffect * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Effect.Anaglyph = function( R3.D3.Effect.Anaglyph = function(
graphics, parent,
apiAnaglyphEffect apiComponent
) { ) {
this.graphics = graphics; __RUNTIME_COMPONENT_MACRO__;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiAnaglyphEffect)) {
apiAnaglyphEffect = {
effectType : R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH
};
}
R3.D3.API.Effect.Anaglyph.call( R3.D3.API.Effect.Anaglyph.call(
this, this,
apiAnaglyphEffect apiComponent
); );
R3.D3.Effect.call( R3.D3.Effect.call(
this, this,
this.graphics, parent
this
); );
}; };
@ -48,11 +40,7 @@ R3.D3.Effect.Anaglyph.prototype.createInstance = function() {
return; return;
} }
this.instance = new THREE.AnaglyphEffect( this.instance = this.graphics.AnaglyphEffect(this.renderer);
this.renderer.instance
);
console.log('anaglyph effect instance created');
R3.D3.Effect.prototype.createInstance.call(this); R3.D3.Effect.prototype.createInstance.call(this);
}; };
@ -63,18 +51,3 @@ R3.D3.Effect.Anaglyph.prototype.createInstance = function() {
R3.D3.Effect.Anaglyph.prototype.updateInstance = function(property) { R3.D3.Effect.Anaglyph.prototype.updateInstance = function(property) {
R3.D3.Effect.prototype.updateInstance.call(this, property); R3.D3.Effect.prototype.updateInstance.call(this, property);
}; };
/**
* Converts a R3.D3.Effect to a R3.D3.API.Effect
* @returns {R3.D3.API.Effect}
*/
R3.D3.Effect.Anaglyph.prototype.toApiObject = function() {
var apiEffect = R3.D3.Effect.prototype.toApiObject.call(this);
var apiAnaglyphEffect = new R3.D3.API.Effect.Anaglyph(
apiEffect
);
return apiAnaglyphEffect;
};

View File

@ -1,32 +1,24 @@
/** /**
* R3.D3.Effect.Parallax * R3.D3.Effect.Parallax
* @param graphics R3.Runtime.Graphics * @param parent
* @param apiParallaxEffect * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Effect.Parallax = function( R3.D3.Effect.Parallax = function(
graphics, parent,
apiParallaxEffect apiComponent
) { ) {
this.graphics = graphics; __RUNTIME_COMPONENT_MACRO__;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiParallaxEffect)) {
apiParallaxEffect = {
effectType : R3.D3.API.Effect.EFFECT_TYPE_PARALLAX
};
}
R3.D3.API.Effect.Parallax.call( R3.D3.API.Effect.Parallax.call(
this, this,
apiParallaxEffect apiComponent
); );
R3.D3.Effect.call( R3.D3.Effect.call(
this, this,
this.graphics, parent
this
); );
}; };
@ -48,11 +40,7 @@ R3.D3.Effect.Parallax.prototype.createInstance = function() {
return; return;
} }
this.instance = new THREE.ParallaxBarrierEffect( this.instance = this.graphics.ParallaxEffect(this.renderer);
this.renderer.instance
);
console.log('parallax effect instance created');
R3.D3.Effect.prototype.createInstance.call(this); R3.D3.Effect.prototype.createInstance.call(this);
}; };
@ -63,18 +51,3 @@ R3.D3.Effect.Parallax.prototype.createInstance = function() {
R3.D3.Effect.Parallax.prototype.updateInstance = function(property) { R3.D3.Effect.Parallax.prototype.updateInstance = function(property) {
R3.D3.Effect.prototype.updateInstance.call(this, property); R3.D3.Effect.prototype.updateInstance.call(this, property);
}; };
/**
* Converts a R3.D3.Effect to a R3.D3.API.Effect
* @returns {R3.D3.API.Effect}
*/
R3.D3.Effect.Parallax.prototype.toApiObject = function() {
var apiEffect = R3.D3.Effect.prototype.toApiObject.call(this);
var apiParallaxEffect = new R3.D3.API.Effect.Parallax(
apiEffect
);
return apiParallaxEffect;
};

View File

@ -1,33 +1,24 @@
/** /**
* R3.D3.Effect.Stereo * R3.D3.Effect.Stereo
* @param graphics R3.Runtime.Graphics * @param parent
* @param apiStereoEffect * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Effect.Stereo = function( R3.D3.Effect.Stereo = function(
graphics, parent,
apiStereoEffect apiComponent
) { ) {
this.graphics = graphics; __RUNTIME_COMPONENT_MACRO__;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiStereoEffect)) {
apiStereoEffect = {
effectType : R3.D3.API.Effect.EFFECT_TYPE_STEREO
};
}
R3.D3.API.Effect.Stereo.call( R3.D3.API.Effect.Stereo.call(
this, this,
apiStereoEffect, apiComponent
apiStereoEffect.eyeSeperation
); );
R3.D3.Effect.call( R3.D3.Effect.call(
this, this,
this.graphics, parent
this
); );
}; };
@ -49,14 +40,10 @@ R3.D3.Effect.Stereo.prototype.createInstance = function() {
return; return;
} }
this.instance = new THREE.StereoEffect( this.instance = this.graphics.StereoEffect(this.renderer);
this.renderer.instance
);
this.instance.setEyeSeparation(this.eyeSeperation); this.instance.setEyeSeparation(this.eyeSeperation);
console.log('stereo effect instance created');
R3.D3.Effect.prototype.createInstance.call(this); R3.D3.Effect.prototype.createInstance.call(this);
}; };
@ -72,19 +59,3 @@ R3.D3.Effect.Stereo.prototype.updateInstance = function(property) {
R3.D3.Effect.prototype.updateInstance.call(this, property); R3.D3.Effect.prototype.updateInstance.call(this, property);
}; };
/**
* Converts a R3.D3.Effect to a R3.D3.API.Effect
* @returns {R3.D3.API.Effect}
*/
R3.D3.Effect.Stereo.prototype.toApiObject = function() {
var apiEffect = R3.D3.Effect.prototype.toApiObject.call(this);
var apiStereoEffect = new R3.D3.API.Effect.Stereo(
apiEffect,
this.eyeSeperation
);
return apiStereoEffect;
};

287
src/r3-d3-face-graphics.js Normal file
View File

@ -0,0 +1,287 @@
/**
* R3.D3.Face
* @param parent
* @param apiComponent
* @constructor
*/
R3.D3.Face.Graphics = function(
parent,
apiComponent
) {
__RUNTIME_COMPONENT_MACRO__;
R3.D3.Face.call(
this,
parent,
apiComponent,
linkedObjects
);
R3.D3.API.Face.call(
this,
apiComponent,
apiComponent.v0index,
apiComponent.v1index,
apiComponent.v2index,
apiComponent.materialIndex,
apiComponent.uvs,
apiComponent.color,
apiComponent.vertexColors,
apiComponent.vertexNormals,
apiComponent.normal,
apiComponent.selected
);
this.componentRuntime = R3.Component.GetComponentRuntime(this.parent);
switch (this.componentRuntime) {
case R3.Component.GRAPHICS_RUNTIME :
break;
case R3.Component.PHYSICS_RUNTIME :
break;
}
R3.Component.call(
this,
parent
);
if (this.implementation instanceof R3.Runtime.Graphics) {
/**
* physics faces have no color... a little sad right?
*/
this.color = new R3.Color(
this.implementation,
this.color,
this
);
this.vertexColors = this.vertexColors.map(function(vertexColor){
return new R3.Color(
this.implementation,
vertexColor,
this
);
/*
if (vertexColor instanceof R3.Color) {
return vertexColor;
}
if (vertexColor instanceof R3.API.Color) {
}
console.warn('unknown vertex color type', vertexColor);*/
}.bind(this));
}
this.vertexNormals = this.vertexNormals.map(
function(vertexNormal) {
return new R3.Vector3(
this.implementation,
vertexNormal,
this
);
}.bind(this)
);
this.uvs = this.uvs.reduce(
function(result, uvs, uvSet) {
result[uvSet] = uvs.reduce(
function(uvResult, uv) {
uvResult.push(
new R3.Vector2(
this.implementation,
uv,
this
)
);
return uvResult;
}.bind(this),
[]
);
return result;
}.bind(this),
[]
);
this.normal = new R3.Vector3(
this.implementation,
this.normal,
this
);
};
R3.D3.Face.Graphics.prototype = Object.create(R3.D3.Face.prototype);
R3.D3.Face.Graphics.prototype.constructor = R3.D3.Face.Graphics;
/**
* We don't follow the standard procedure for Faces - We don't want them in the EntityManager registry - so
* they don't call component createinstance
* @param parentGeometry
*/
R3.D3.Face.Graphics.prototype.createInstance = function(parentGeometry) {
this.instance = new THREE.Face3(
this.v0index,
this.v1index,
this.v2index
);
if (this.normal) {
this.instance.normal = new THREE.Vector3(
this.normal.x,
this.normal.y,
this.normal.z
);
}
if (this.color) {
this.instance.color = new THREE.Color(
this.color.r,
this.color.g,
this.color.b
)
}
this.instance.materialIndex = this.materialIndex;
if (R3.Utils.UndefinedOrNull(parentGeometry)) {
console.warn('please pass a parentmesh to face createInstance()');
}
this.parentGeometry = parentGeometry;
};
R3.D3.Face.Graphics.prototype.updateInstance = function(property, uvSet, uvIndex) {
if (property === 'materialIndex') {
this.instance.materialIndex = this.materialIndex;
this.parentGeometry.instance.groupsNeedUpdate = true;
return;
}
if (property === 'uvs') {
this.uvs[uvSet][uvIndex].instance.x = this.uvs[uvSet][uvIndex].x;
this.uvs[uvSet][uvIndex].instance.y = this.uvs[uvSet][uvIndex].y;
this.parentGeometry.instance.uvsNeedUpdate = true;
return;
}
console.warn('todo: update face property: ' + property);
};
R3.D3.Face.prototype.toApiObject = function() {
return new R3.D3.API.Face(
this.id,
this.name,
this.v0index,
this.v1index,
this.v2index,
this.materialIndex,
this.uvs.reduce(
function(result, uvArray, index) {
result[index] = uvArray.reduce(
function(uvResult, uv) {
if (uv instanceof R3.Vector2) {
uvResult.push(uv.toApiObject());
} else {
console.warn('unknown uv type - cannot commit to API');
}
return uvResult;
}.bind(this),
[]
);
return result;
}.bind(this),
[]
),
this.color.toApiObject(),
this.vertexColors.map(function(vertexColor){
return vertexColor.toApiObject();
}),
this.vertexNormals.map(function(vertexNormal){
return vertexNormal.toApiObject();
}),
this.normal.toApiObject(),
this.selected
);
};
R3.D3.Face.prototype.createHelper = function(mesh) {
this.backupProperties = {
color : {
r: this.color.r,
g: this.color.g,
b: this.color.b
},
material : {
emissive : {
r: mesh.materials[this.materialIndex].emissive.r,
g: mesh.materials[this.materialIndex].emissive.g,
b: mesh.materials[this.materialIndex].emissive.b
}
},
vertexColors : mesh.materials[this.materialIndex].vertexColors
};
this.instance.vertexColors = [
new THREE.Color(1,0,0),
new THREE.Color(0,1,0),
new THREE.Color(0,0,1)
];
// this.instance.color.r = 1;
// this.instance.color.g = 0;
// this.instance.color.b = 0;
//
// mesh.materials[this.materialIndex].emissive.r = 0.5;
// mesh.materials[this.materialIndex].emissive.g = 0.5;
// mesh.materials[this.materialIndex].emissive.b = 0.5;
// mesh.materials[this.materialIndex].updateInstance('emissive');
mesh.materials[this.materialIndex].vertexColors = R3.D3.API.Material.TYPE_VERTEX_COLORS;
mesh.materials[this.materialIndex].updateInstance('vertexColors');
mesh.instance.geometry.elementsNeedUpdate = true;
};
R3.D3.Face.prototype.removeHelper = function(mesh) {
this.instance.color.r = this.backupProperties.color.r;
this.instance.color.g = this.backupProperties.color.g;
this.instance.color.b = this.backupProperties.color.b;
mesh.instance.geometry.colorsNeedUpdate = true;
// mesh.materials[this.materialIndex].emissive.r = this.backupProperties.material.emissive.r;
// mesh.materials[this.materialIndex].emissive.g = this.backupProperties.material.emissive.g;
// mesh.materials[this.materialIndex].emissive.b = this.backupProperties.material.emissive.b;
// mesh.materials[this.materialIndex].updateInstance('emissive');
mesh.materials[this.materialIndex].vertexColors = this.backupProperties.vertexColors;
mesh.materials[this.materialIndex].updateInstance('vertexColors');
};

View File

@ -1,117 +1,55 @@
/** /**
* R3.D3.Face * R3.D3.Face
* @param parent
* @param apiComponent
* @param linkedObjects
* @constructor * @constructor
* @param implementation
* @param apiFace
*/ */
R3.D3.Face = function( R3.D3.Face = function(
implementation, parent,
apiFace apiComponent,
linkedObjects
) { ) {
this.implementation = implementation; __RUNTIME_COMPONENT_MACRO__;
if (implementation instanceof R3.Runtime.Graphics) {
this.implementation.isNotThreeThrow();
} else if (implementation instanceof R3.Runtime.Physics) {
this.implementation.isNotCannonThrow();
} else {
throw new Error('Unhandled implementation : ' + implementation);
}
if (R3.Utils.UndefinedOrNull(apiFace)) {
apiFace = {};
}
R3.D3.API.Face.call( R3.D3.API.Face.call(
this, this,
apiFace.id, apiComponent,
apiFace.name, apiComponent.v0index,
apiFace.v0index, apiComponent.v1index,
apiFace.v1index, apiComponent.v2index,
apiFace.v2index, apiComponent.vertexNormals,
apiFace.materialIndex, apiComponent.normal,
apiFace.uvs, apiComponent.selected
apiFace.color,
apiFace.vertexColors,
apiFace.vertexNormals,
apiFace.normal,
apiFace.selected,
apiFace.parentGeometry,
apiFace.parent
); );
if (this.implementation instanceof R3.Runtime.Graphics) { this.componentRuntime = R3.Component.GetComponentRuntime(this.parent);
/**
* physics faces have no color... a little sad right?
*/
this.color = new R3.Color(
this.implementation,
this.color,
this
);
this.vertexColors = this.vertexColors.map(function(vertexColor){ this.vertexNormals = this.vertexNormals.reduce(
function(result, vertexNormal) {
return new R3.Color( result.push(
this.implementation, new R3.Vector3(
vertexColor, parent,
this vertexNormal
); )
/*
if (vertexColor instanceof R3.Color) {
return vertexColor;
}
if (vertexColor instanceof R3.API.Color) {
}
console.warn('unknown vertex color type', vertexColor);*/
}.bind(this));
}
this.vertexNormals = this.vertexNormals.map(
function(vertexNormal) {
return new R3.Vector3(
this.implementation,
vertexNormal,
this
);
}.bind(this)
);
this.uvs = this.uvs.reduce(
function(result, uvs, uvSet) {
result[uvSet] = uvs.reduce(
function(uvResult, uv) {
uvResult.push(
new R3.Vector2(
this.implementation,
uv,
this
)
);
return uvResult;
}.bind(this),
[]
); );
return result; return result;
},
}.bind(this),
[] []
); );
this.normal = new R3.Vector3( this.normal = new R3.Vector3(
this.implementation, parent,
this.normal, this.normal
this );
R3.Component.call(
this,
parent,
linkedObjects
); );
}; };
@ -126,6 +64,14 @@ R3.D3.Face.prototype.constructor = R3.D3.Face;
*/ */
R3.D3.Face.prototype.createInstance = function(parentGeometry) { R3.D3.Face.prototype.createInstance = function(parentGeometry) {
switch (this.componentRuntime) {
case R3.Component.GRAPHICS_RUNTIME :
break;
case R3.Component.PHYSICS_RUNTIME :
break;
}
this.instance = new THREE.Face3( this.instance = new THREE.Face3(
this.v0index, this.v0index,
this.v1index, this.v1index,

View File

@ -1,45 +1,18 @@
/** /**
* R3.Renderer * R3.Renderer
* @param graphics * @param parent
* @param apiRenderer R3.API.Renderer * @param linkedObjects
* @property rendererType
* @constructor * @constructor
*/ */
R3.Renderer = function( R3.Renderer = function(
graphics, parent,
apiRenderer linkedObjects
) { ) {
if (R3.Utils.UndefinedOrNull(graphics)) {
graphics = null;
}
this.graphics = graphics;
if (R3.Utils.UndefinedOrNull(apiRenderer)) {
apiRenderer = {
rendererType : R3.API.Renderer.RENDERER_TYPE_NONE
};
}
R3.API.Renderer.call(
this,
apiRenderer.id,
apiRenderer.name,
apiRenderer.parent,
apiRenderer.rendererType,
apiRenderer.canvas
);
if (this.canvas instanceof R3.API.Canvas) {
this.canvas = new R3.Canvas(
this.graphics,
this.canvas
);
}
R3.Component.call( R3.Component.call(
this, this,
R3.Renderer.GetLinkedObjects(this.rendererType) parent,
linkedObjects
); );
}; };
@ -47,34 +20,6 @@ R3.Renderer = function(
R3.Renderer.prototype = Object.create(R3.Component.prototype); R3.Renderer.prototype = Object.create(R3.Component.prototype);
R3.Renderer.prototype.constructor = R3.Renderer; R3.Renderer.prototype.constructor = R3.Renderer;
R3.Renderer.GetLinkedObjects = function(rendererType) {
var linkedObjects = {
'canvas' : R3.Canvas
};
switch (rendererType) {
case R3.API.Renderer.RENDERER_TYPE_3D :
linkedObjects.renderTarget = R3.D3.RenderTarget;
linkedObjects.clippingPlanes = [R3.Plane];
linkedObjects.viewports = [R3.D3.Viewport];
linkedObjects.composer = R3.D3.Composer;
linkedObjects.effect = R3.D3.Effect;
break;
}
return linkedObjects;
};
/**
* Create Renderer Instance
* @returns {*}
*/
R3.Renderer.prototype.createInstance = function() {
R3.Component.prototype.createInstance.call(this);
};
/** /**
* Update Renderer Instance * Update Renderer Instance
*/ */
@ -88,36 +33,24 @@ R3.Renderer.prototype.updateInstance = function(property) {
throw new Error('no renderer instance'); throw new Error('no renderer instance');
} }
if (property === 'rendererType') { if (property === 'size') {
var componentType = R3.API.Renderer.GetComponentType(this.rendererType); this.width = this.target.width;
this.height = this.target.height;
this.replace(componentType); /**
* Emit a resize event so other objects like effects and composers can update their sizes
return; */
} R3.Event.Emit(
R3.Event.RENDERER_SIZE_CHANGE,
if (property === 'canvas') { this
console.log('todo: canvas update'); );
return; /**
* TODO: Allow other objects like effects and composers to update their size if it was using this render target
*/
console.warn('TODO: Allow other objects like effects and composers to update their size if it was using this render target');
//R3.Event.Emit(R3.Event.RENDER_TARGET_CHANGE, this.renderTarget);
} }
R3.Component.prototype.updateInstance.call(this, property); R3.Component.prototype.updateInstance.call(this, property);
}; };
/**
*
* @returns {R3.API.Renderer}
*/
R3.Renderer.prototype.toApiObject = function() {
var apiRenderer = new R3.API.Renderer(
this.id,
this.name,
R3.Utils.IdOrNull(this.parent),
this.rendererType,
R3.Utils.IdOrNull(this.canvas)
);
return apiRenderer;
};

View File

@ -71,18 +71,3 @@ R3.Renderer.D2.prototype.updateInstance = function(property) {
R3.Renderer.prototype.updateInstance.call(this, property); R3.Renderer.prototype.updateInstance.call(this, property);
}; };
/**
*
* @returns {R3.API.Renderer.D2}
*/
R3.Renderer.D2.prototype.toApiObject = function() {
var apiRenderer = R3.Renderer.prototype.toApiObject.call(this);
var apiRendererD2 = new R3.API.Renderer.D2(
apiRenderer
);
return apiRendererD2;
};

View File

@ -1,533 +1,122 @@
/** /**
* R3.Renderer.D3.Canvas.Target * R3.Renderer.D3.Canvas.Target
* @param graphics R3.Runtime.Graphics * @param parent
* @param apiRendererD3 R3.API.Renderer.D3 * @param apiComponent
* @constructor * @constructor
*/ */
R3.Renderer.D3.Canvas.Target = function( R3.Renderer.D3.Canvas.Target = function(
graphics, parent,
apiRendererD3 apiComponent
) { ) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiRendererD3)) { __RUNTIME_COMPONENT_MACRO__;
apiRendererD3 = {
rendererType : R3.API.Renderer.RENDERER_TYPE_3D
};
}
R3.API.Renderer.D3.call( R3.API.Renderer.D3.Canvas.Target.call(
this, this,
apiRendererD3, apiComponent,
apiRendererD3.renderMode, apiComponent.target
apiRendererD3.autoClear,
apiRendererD3.autoClearColor,
apiRendererD3.autoClearDepth,
apiRendererD3.autoClearStencil,
apiRendererD3.gammaFactor,
apiRendererD3.gammaInput,
apiRendererD3.gammaOutput,
apiRendererD3.maxMorphTargets,
apiRendererD3.maxMorphNormals,
apiRendererD3.physicallyCorrectLights,
apiRendererD3.shadowMapEnabled,
apiRendererD3.shadowMapAutoUpdate,
apiRendererD3.shadowMapNeedsUpdate,
apiRendererD3.shadowMapType,
apiRendererD3.shadowMapRenderReverseSided,
apiRendererD3.shadowMapRenderSingleSided,
apiRendererD3.sortObjects,
apiRendererD3.toneMapping,
apiRendererD3.toneMappingExposure,
apiRendererD3.toneMappingWhitePoint,
apiRendererD3.premultipliedAlpha,
apiRendererD3.antialias,
apiRendererD3.stencil,
apiRendererD3.preserveDrawingBuffer,
apiRendererD3.depth,
apiRendererD3.logarithmicDepthBuffer,
apiRendererD3.localClippingEnabled,
apiRendererD3.renderTarget,
apiRendererD3.clippingPlanes,
apiRendererD3.clearColor,
apiRendererD3.viewports,
apiRendererD3.alpha,
apiRendererD3.opacity,
apiRendererD3.composer,
apiRendererD3.effect,
apiRendererD3.enableComposer,
apiRendererD3.enableEffect
); );
if (this.renderTarget instanceof R3.D3.API.RenderTarget) { if (this.target instanceof R3.D3.API.RenderTarget) {
this.renderTarget = R3.Component.ConstructFromObject(this.renderTarget); this.target = R3.Component.ConstructFromObject(this.target);
} }
this.clippingPlanes = this.clippingPlanes.reduce( var linkedObjects = {
function(result, clippingPlane) { target : R3.D3.RenderTarget
};
if (clippingPlane instanceof R3.API.Plane) { R3.Renderer.D3.Canvas.call(
clippingPlane = R3.Component.ConstructFromObject(clippingPlane);
}
result.push(clippingPlane);
return result;
},
[]
);
this.clearColor = new R3.Color(
this.graphics,
this.clearColor,
this
);
this.viewports = this.viewports.reduce(
function(result, viewport) {
if (viewport instanceof R3.D3.API.Viewport) {
viewport = R3.Component.ConstructFromObject(viewport);
}
result.push(viewport);
return result;
},
[]
);
if (this.composer instanceof R3.D3.API.Composer) {
this.composer = R3.Component.ConstructFromObject(this.composer);
}
if (this.effect instanceof R3.D3.API.Effect) {
this.effect = R3.Component.ConstructFromObject(this.effect);
}
R3.Renderer.call(
this, this,
this.graphics, parent,
this apiComponent,
linkedObjects
); );
}; };
R3.Renderer.D3.prototype = Object.create(R3.Renderer.prototype); R3.Renderer.D3.Canvas.Target.prototype = Object.create(R3.Renderer.D3.Canvas.prototype);
R3.Renderer.D3.prototype.constructor = R3.Renderer.D3; R3.Renderer.D3.Canvas.Target.prototype.constructor = R3.Renderer.D3.Canvas.Target;
/** /**
* Create R3.Renderer.D3 Instance * Create R3.Renderer.D3 Instance
* @returns {*} * @returns {*}
*/ */
R3.Renderer.D3.prototype.createInstance = function() { R3.Renderer.D3.Canvas.Target.prototype.createInstance = function() {
if (
R3.Utils.UndefinedOrNull(this.target) ||
R3.Utils.UndefinedOrNull(this.target.instance)
) {
throw new Error('target not ready');
}
/**
* We can't call the canvas createInstance because it will call component create instance before being able
* to assign the render target
*/
if ( if (
R3.Utils.UndefinedOrNull(this.canvas) || R3.Utils.UndefinedOrNull(this.canvas) ||
R3.Utils.UndefinedOrNull(this.canvas.instance) R3.Utils.UndefinedOrNull(this.canvas.instance)
) { ) {
console.warn('no canvas instance'); console.warn('no canvas instance or canvas not ready');
return; return;
} }
this.instance = new THREE.WebGLRenderer( this.instance = this.graphics.Renderer3D(
{ this.canvas,
canvas : this.canvas.instance, this.alpha,
alpha : this.alpha,
premultipliedAlpha : this.premultipliedAlpha,
antialias : this.antialias,
stencil : this.stencil,
preserveDrawingBuffer : this.preserveDrawingBuffer,
depth : this.depth,
logarithmicDepthBuffer : this.logarithmicDepthBuffer
}
);
this.instance.setPixelRatio(window.devicePixelRatio);
this.instance.autoClear = this.autoClear;
this.instance.autoClearColor = this.autoClearColor;
this.instance.autoClearDepth = this.autoClearDepth;
this.instance.autoClearStencil = this.autoClearStencil;
this.instance.gammaFactor = this.gammaFactor;
this.instance.gammaInput = this.gammaInput;
this.instance.gammaOutput = this.gammaOutput;
this.instance.maxMorphTargets = this.maxMorphTargets;
this.instance.maxMorphNormals = this.maxMorphNormals;
this.instance.physicallyCorrectLights = this.physicallyCorrectLights;
this.instance.shadowMap.enabled = this.shadowMapEnabled;
this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate;
this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate;
this.instance.shadowMap.type = this.shadowMapType;
this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided;
this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided;
this.instance.sortObjects = this.sortObjects;
this.instance.toneMapping = this.toneMapping;
this.instance.toneMappingExposure = this.toneMappingExposure;
this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint;
this.instance.premultipliedAlpha = this.premultipliedAlpha;
this.instance.localClippingEnabled = this.localClippingEnabled;
if (this.renderTarget) {
this.instance.setRenderTarget(this.renderTarget.instance);
}
if (this.clippingPlanes.length > 0) {
this.instance.clippingPlanes = this.clippingPlanes.map(
function(clippingPlane) {
return clippingPlane.instance;
}
)
}
this.instance.setClearColor(
new THREE.Color(
this.clearColor.r,
this.clearColor.g,
this.clearColor.b
),
this.opacity
);
R3.Renderer.prototype.createInstance.call(this);
};
/**
* Update Renderer.D3 Instance
*/
R3.Renderer.D3.prototype.updateInstance = function(property) {
if (!property) {
throw new Error('no renderer property');
}
if (!this.instance) {
throw new Error('no renderer instance');
}
if (property === 'renderMode') {
console.log('render mode change');
return;
}
if (property === 'autoClear') {
this.instance.autoClear = this.autoClear;
return;
}
if (property === 'autoClearColor') {
this.instance.autoClearColor = this.autoClearColor;
return;
}
if (property === 'autoClearDepth') {
this.instance.autoClearDepth = this.autoClearDepth;
return;
}
if (property === 'autoClearStencil') {
this.instance.autoClearStencil = this.autoClearStencil;
return;
}
if (property === 'gammaFactor') {
this.instance.gammaFactor = this.gammaFactor;
return;
}
if (property === 'gammaInput') {
this.instance.gammaInput = this.gammaInput;
return;
}
if (property === 'gammaOutput') {
this.instance.gammaOutput = this.gammaOutput;
return;
}
if (property === 'maxMorphTargets') {
this.instance.maxMorphTargets = this.maxMorphTargets;
return;
}
if (property === 'maxMorphNormals') {
this.instance.maxMorphNormals = this.maxMorphNormals;
return;
}
if (property === 'physicallyCorrectLights') {
this.instance.physicallyCorrectLights = this.physicallyCorrectLights;
return;
}
if (property === 'shadowMapEnabled') {
this.instance.shadowMap.enabled = this.shadowMapEnabled;
return;
}
if (property === 'shadowMapAutoUpdate') {
this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate;
return;
}
if (property === 'shadowMapNeedsUpdate') {
this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate;
return;
}
if (property === 'shadowMapType') {
this.instance.shadowMap.type = this.shadowMapType;
return;
}
if (property === 'shadowMapRenderReverseSided') {
this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided;
return;
}
if (property === 'shadowMapRenderSingleSided') {
this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided;
return;
}
if (property === 'sortObjects') {
this.instance.sortObjects = this.sortObjects;
return;
}
if (property === 'toneMapping') {
this.instance.toneMapping = this.toneMapping;
return;
}
if (property === 'toneMappingExposure') {
this.instance.toneMappingExposure = this.toneMappingExposure;
return;
}
if (property === 'toneMappingWhitePoint') {
this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint;
return;
}
if (property === 'premultipliedAlpha') {
this.instance.premultipliedAlpha = this.premultipliedAlpha;
return;
}
if (property === 'premultipliedAlpha') {
this.instance.premultipliedAlpha = this.premultipliedAlpha;
return;
}
if (property === 'antialias') {
this.instance.antialias = this.antialias;
return;
}
if (property === 'stencil') {
this.instance.stencil = this.stencil;
return;
}
if (property === 'preserveDrawingBuffer') {
this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
return;
}
if (property === 'depth') {
this.instance.depth = this.depth;
return;
}
if (property === 'logarithmicDepthBuffer') {
this.instance.logarithmicDepthBuffer = this.logarithmicDepthBuffer;
return;
}
if (property === 'localClippingEnabled') {
this.instance.localClippingEnabled = this.localClippingEnabled;
return;
}
if (property === 'canvas') {
if (R3.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
} else {
console.warn('experimental canvas change for renderer');
this.instance.dispose();
this.createInstance();
}
return;
}
if (property === 'renderTarget') {
if (
R3.Utils.Defined(this.instance) &&
R3.Utils.Defined(this.renderTarget) &&
R3.Utils.Defined(this.renderTarget.instance)
) {
this.instance.setRenderTarget(this.renderTarget.instance);
console.log('updated render target on render instance');
}
return;
}
if (property === 'clippingPlanes') {
console.warn('todo: clipping planes change');
return;
}
if (
property === 'clearColor' ||
property === 'opacity'
) {
this.instance.setClearColor(
new THREE.Color(
this.clearColor.r,
this.clearColor.g,
this.clearColor.b
),
this.opacity
);
return;
}
if (property === 'viewports') {
console.warn('todo: viewports change');
}
if (property === 'alpha') {
this.instance.alpha = this.alpha;
return;
}
R3.Renderer.prototype.updateInstance.call(this, property);
};
/**
* Wrapper for clear()
*/
R3.Renderer.D3.prototype.clear = function() {
return this.instance.clear();
};
/**
* Convenience function to set viewport
* @param x
* @param y
* @param width
* @param height
*/
R3.Renderer.D3.prototype.setViewport = function(
x,
y,
width,
height
) {
this.instance.setViewport(
x,
y,
width,
height
);
};
/**
* Renders to this.renderTarget
* @param scene
* @param camera
*/
R3.Renderer.D3.prototype.renderToTarget = function(scene, camera) {
this.instance.render(
scene.instance,
camera.instance,
this.renderTarget.instance
);
};
/**
* Renders normally
* @param scene
* @param camera
*/
R3.Renderer.D3.prototype.render = function(scene, camera) {
this.instance.render(
scene.instance,
camera.instance
)
};
/**
*
* @returns {R3.API.Renderer.D3}
*/
R3.Renderer.D3.prototype.toApiObject = function() {
var apiRenderer = R3.Renderer.prototype.toApiObject.call(this);
var apiRendererD3 = new R3.API.Renderer.D3(
apiRenderer,
this.renderMode,
this.autoClear,
this.autoClearColor,
this.autoClearDepth,
this.autoClearStencil,
this.gammaFactor,
this.gammaInput,
this.gammaOutput,
this.maxMorphTargets,
this.maxMorphNormals,
this.physicallyCorrectLights,
this.shadowMapEnabled,
this.shadowMapAutoUpdate,
this.shadowMapNeedsUpdate,
this.shadowMapType,
this.shadowMapRenderReverseSided,
this.shadowMapRenderSingleSided,
this.sortObjects,
this.toneMapping,
this.toneMappingExposure,
this.toneMappingWhitePoint,
this.premultipliedAlpha, this.premultipliedAlpha,
this.antialias, this.antialias,
this.stencil, this.stencil,
this.preserveDrawingBuffer, this.preserveDrawingBuffer,
this.depth, this.depth,
this.logarithmicDepthBuffer, this.logarithmicDepthBuffer
this.localClippingEnabled,
R3.Utils.IdOrNull(this.renderTarget),
this.clippingPlanes.map(
function(clippingPlane){
return R3.Utils.IdOrNull(clippingPlane);
}
),
this.clearColor.toApiObject(),
this.viewports.map(
function(viewport){
return R3.Utils.IdOrNull(viewport);
}
),
this.alpha,
this.opacity
); );
return apiRendererD3; this.instance.setRenderTarget(this.target.instance);
/**
* So we skip the canvas createInstance but call the rest of the parent class createInstances
*/
R3.Renderer.D3.prototype.createInstance.call(this);
}; };
/**
* Update Renderer.D3 Instance
*/
R3.Renderer.D3.Canvas.Target.prototype.updateInstance = function(property) {
if (property === 'target') {
console.warn('todo also check for target being set to null or unassigned');
if (
R3.Utils.Defined(this.instance) &&
R3.Utils.Defined(this.target) &&
R3.Utils.Defined(this.target.instance)
) {
this.instance.setRenderTarget(this.target.instance);
/**
* The size probably changed
*/
R3.Event.Emit(
R3.Event.RENDERER_SIZE_CHANGE,
this
)
}
return;
}
R3.Renderer.D3.Canvas.prototype.updateInstance.call(this, property);
};
/**
* Return the size of the target instead of the canvas
* @returns {{width: *, height: *}}
*/
R3.Renderer.D3.Canvas.Target.prototype.getSize = function() {
return R3.API.Renderer.D3.Canvas.Target.prototype.getSize.call(this);
};

View File

@ -1,533 +1,107 @@
/** /**
* R3.Renderer.D3.Canvas * R3.Renderer.D3.Canvas
* @param graphics R3.Runtime.Graphics * @param parent
* @param apiRendererD3 R3.API.Renderer.D3 * @param apiComponent
* @param linkedObjects
* @constructor * @constructor
*/ */
R3.Renderer.D3.Canvas = function( R3.Renderer.D3.Canvas = function(
graphics, parent,
apiRendererD3 apiComponent,
linkedObjects
) { ) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiRendererD3)) { if (R3.Utils.UndefinedOrNull(linkedObjects)) {
apiRendererD3 = {
rendererType : R3.API.Renderer.RENDERER_TYPE_3D linkedObjects = {};
};
__RUNTIME_COMPONENT_MACRO__;
R3.API.Renderer.D3.Canvas.call(
this,
apiComponent,
apiComponent.canvas
);
} }
R3.API.Renderer.D3.call( if (this.canvas instanceof R3.API.Canvas) {
this.canvas = R3.Component.ConstructFromObject(this.canvas);
}
linkedObjects.canvas = R3.Canvas;
R3.Component.call(
this, this,
apiRendererD3, parent,
apiRendererD3.renderMode, linkedObjects
apiRendererD3.autoClear,
apiRendererD3.autoClearColor,
apiRendererD3.autoClearDepth,
apiRendererD3.autoClearStencil,
apiRendererD3.gammaFactor,
apiRendererD3.gammaInput,
apiRendererD3.gammaOutput,
apiRendererD3.maxMorphTargets,
apiRendererD3.maxMorphNormals,
apiRendererD3.physicallyCorrectLights,
apiRendererD3.shadowMapEnabled,
apiRendererD3.shadowMapAutoUpdate,
apiRendererD3.shadowMapNeedsUpdate,
apiRendererD3.shadowMapType,
apiRendererD3.shadowMapRenderReverseSided,
apiRendererD3.shadowMapRenderSingleSided,
apiRendererD3.sortObjects,
apiRendererD3.toneMapping,
apiRendererD3.toneMappingExposure,
apiRendererD3.toneMappingWhitePoint,
apiRendererD3.premultipliedAlpha,
apiRendererD3.antialias,
apiRendererD3.stencil,
apiRendererD3.preserveDrawingBuffer,
apiRendererD3.depth,
apiRendererD3.logarithmicDepthBuffer,
apiRendererD3.localClippingEnabled,
apiRendererD3.renderTarget,
apiRendererD3.clippingPlanes,
apiRendererD3.clearColor,
apiRendererD3.viewports,
apiRendererD3.alpha,
apiRendererD3.opacity,
apiRendererD3.composer,
apiRendererD3.effect,
apiRendererD3.enableComposer,
apiRendererD3.enableEffect
);
if (this.renderTarget instanceof R3.D3.API.RenderTarget) {
this.renderTarget = R3.Component.ConstructFromObject(this.renderTarget);
}
this.clippingPlanes = this.clippingPlanes.reduce(
function(result, clippingPlane) {
if (clippingPlane instanceof R3.API.Plane) {
clippingPlane = R3.Component.ConstructFromObject(clippingPlane);
}
result.push(clippingPlane);
return result;
},
[]
);
this.clearColor = new R3.Color(
this.graphics,
this.clearColor,
this
);
this.viewports = this.viewports.reduce(
function(result, viewport) {
if (viewport instanceof R3.D3.API.Viewport) {
viewport = R3.Component.ConstructFromObject(viewport);
}
result.push(viewport);
return result;
},
[]
);
if (this.composer instanceof R3.D3.API.Composer) {
this.composer = R3.Component.ConstructFromObject(this.composer);
}
if (this.effect instanceof R3.D3.API.Effect) {
this.effect = R3.Component.ConstructFromObject(this.effect);
}
R3.Renderer.call(
this,
this.graphics,
this
); );
}; };
R3.Renderer.D3.prototype = Object.create(R3.Renderer.prototype); R3.Renderer.D3.Canvas.prototype = Object.create(R3.Renderer.D3.prototype);
R3.Renderer.D3.prototype.constructor = R3.Renderer.D3; R3.Renderer.D3.Canvas.prototype.constructor = R3.Renderer.D3.Canvas;
/** /**
* Create R3.Renderer.D3 Instance * Create R3.Renderer.D3 Instance
* @returns {*} * @returns {*}
*/ */
R3.Renderer.D3.prototype.createInstance = function() { R3.Renderer.D3.Canvas.prototype.createInstance = function() {
if ( if (
R3.Utils.UndefinedOrNull(this.canvas) || R3.Utils.UndefinedOrNull(this.canvas) ||
R3.Utils.UndefinedOrNull(this.canvas.instance) R3.Utils.UndefinedOrNull(this.canvas.instance)
) { ) {
console.warn('no canvas instance'); console.warn('no canvas instance or canvas not ready');
return; return;
} }
this.instance = new THREE.WebGLRenderer( this.instance = this.graphics.Renderer3D(
{ this.canvas,
canvas : this.canvas.instance, this.alpha,
alpha : this.alpha, this.premultipliedAlpha,
premultipliedAlpha : this.premultipliedAlpha, this.antialias,
antialias : this.antialias, this.stencil,
stencil : this.stencil, this.preserveDrawingBuffer,
preserveDrawingBuffer : this.preserveDrawingBuffer, this.depth,
depth : this.depth, this.logarithmicDepthBuffer
logarithmicDepthBuffer : this.logarithmicDepthBuffer
}
); );
this.instance.setPixelRatio(window.devicePixelRatio); R3.Renderer.D3.prototype.createInstance.call(this);
this.instance.autoClear = this.autoClear;
this.instance.autoClearColor = this.autoClearColor;
this.instance.autoClearDepth = this.autoClearDepth;
this.instance.autoClearStencil = this.autoClearStencil;
this.instance.gammaFactor = this.gammaFactor;
this.instance.gammaInput = this.gammaInput;
this.instance.gammaOutput = this.gammaOutput;
this.instance.maxMorphTargets = this.maxMorphTargets;
this.instance.maxMorphNormals = this.maxMorphNormals;
this.instance.physicallyCorrectLights = this.physicallyCorrectLights;
this.instance.shadowMap.enabled = this.shadowMapEnabled;
this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate;
this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate;
this.instance.shadowMap.type = this.shadowMapType;
this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided;
this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided;
this.instance.sortObjects = this.sortObjects;
this.instance.toneMapping = this.toneMapping;
this.instance.toneMappingExposure = this.toneMappingExposure;
this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint;
this.instance.premultipliedAlpha = this.premultipliedAlpha;
this.instance.localClippingEnabled = this.localClippingEnabled;
if (this.renderTarget) {
this.instance.setRenderTarget(this.renderTarget.instance);
}
if (this.clippingPlanes.length > 0) {
this.instance.clippingPlanes = this.clippingPlanes.map(
function(clippingPlane) {
return clippingPlane.instance;
}
)
}
this.instance.setClearColor(
new THREE.Color(
this.clearColor.r,
this.clearColor.g,
this.clearColor.b
),
this.opacity
);
R3.Renderer.prototype.createInstance.call(this);
}; };
/** /**
* Update Renderer.D3 Instance * Update Renderer.D3 Instance
*/ */
R3.Renderer.D3.prototype.updateInstance = function(property) { R3.Renderer.D3.Canvas.prototype.updateInstance = function(property) {
if (!property) {
throw new Error('no renderer property');
}
if (!this.instance) {
throw new Error('no renderer instance');
}
if (property === 'renderMode') {
console.log('render mode change');
return;
}
if (property === 'autoClear') {
this.instance.autoClear = this.autoClear;
return;
}
if (property === 'autoClearColor') {
this.instance.autoClearColor = this.autoClearColor;
return;
}
if (property === 'autoClearDepth') {
this.instance.autoClearDepth = this.autoClearDepth;
return;
}
if (property === 'autoClearStencil') {
this.instance.autoClearStencil = this.autoClearStencil;
return;
}
if (property === 'gammaFactor') {
this.instance.gammaFactor = this.gammaFactor;
return;
}
if (property === 'gammaInput') {
this.instance.gammaInput = this.gammaInput;
return;
}
if (property === 'gammaOutput') {
this.instance.gammaOutput = this.gammaOutput;
return;
}
if (property === 'maxMorphTargets') {
this.instance.maxMorphTargets = this.maxMorphTargets;
return;
}
if (property === 'maxMorphNormals') {
this.instance.maxMorphNormals = this.maxMorphNormals;
return;
}
if (property === 'physicallyCorrectLights') {
this.instance.physicallyCorrectLights = this.physicallyCorrectLights;
return;
}
if (property === 'shadowMapEnabled') {
this.instance.shadowMap.enabled = this.shadowMapEnabled;
return;
}
if (property === 'shadowMapAutoUpdate') {
this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate;
return;
}
if (property === 'shadowMapNeedsUpdate') {
this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate;
return;
}
if (property === 'shadowMapType') {
this.instance.shadowMap.type = this.shadowMapType;
return;
}
if (property === 'shadowMapRenderReverseSided') {
this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided;
return;
}
if (property === 'shadowMapRenderSingleSided') {
this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided;
return;
}
if (property === 'sortObjects') {
this.instance.sortObjects = this.sortObjects;
return;
}
if (property === 'toneMapping') {
this.instance.toneMapping = this.toneMapping;
return;
}
if (property === 'toneMappingExposure') {
this.instance.toneMappingExposure = this.toneMappingExposure;
return;
}
if (property === 'toneMappingWhitePoint') {
this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint;
return;
}
if (property === 'premultipliedAlpha') {
this.instance.premultipliedAlpha = this.premultipliedAlpha;
return;
}
if (property === 'premultipliedAlpha') {
this.instance.premultipliedAlpha = this.premultipliedAlpha;
return;
}
if (property === 'antialias') {
this.instance.antialias = this.antialias;
return;
}
if (property === 'stencil') {
this.instance.stencil = this.stencil;
return;
}
if (property === 'preserveDrawingBuffer') {
this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
return;
}
if (property === 'depth') {
this.instance.depth = this.depth;
return;
}
if (property === 'logarithmicDepthBuffer') {
this.instance.logarithmicDepthBuffer = this.logarithmicDepthBuffer;
return;
}
if (property === 'localClippingEnabled') {
this.instance.localClippingEnabled = this.localClippingEnabled;
return;
}
if (property === 'canvas') { if (property === 'canvas') {
if (R3.Utils.UndefinedOrNull(this.instance)) { if (this.canvas && this.canvas.instance) {
this.createInstance();
} else {
console.warn('experimental canvas change for renderer');
this.instance.dispose(); this.instance.dispose();
this.createInstance(); this.createInstance();
R3.Event.Emit(
R3.Event.RENDERER_SIZE_CHANGE,
this
)
} else {
/**
* The canvas object was unassigned
*/
console.warn('The canvas object was unassigned - this will break something - do not save now')
} }
return; return;
} }
if (property === 'renderTarget') { R3.Renderer.D3.prototype.updateInstance.call(this, property);
if (
R3.Utils.Defined(this.instance) &&
R3.Utils.Defined(this.renderTarget) &&
R3.Utils.Defined(this.renderTarget.instance)
) {
this.instance.setRenderTarget(this.renderTarget.instance);
console.log('updated render target on render instance');
}
return;
}
if (property === 'clippingPlanes') {
console.warn('todo: clipping planes change');
return;
}
if (
property === 'clearColor' ||
property === 'opacity'
) {
this.instance.setClearColor(
new THREE.Color(
this.clearColor.r,
this.clearColor.g,
this.clearColor.b
),
this.opacity
);
return;
}
if (property === 'viewports') {
console.warn('todo: viewports change');
}
if (property === 'alpha') {
this.instance.alpha = this.alpha;
return;
}
R3.Renderer.prototype.updateInstance.call(this, property);
}; };
/** /**
* Wrapper for clear() * Return the size of the canvas
* @returns {{width: *, height: *}}
*/ */
R3.Renderer.D3.prototype.clear = function() { R3.Renderer.D3.Canvas.prototype.getSize = function() {
return this.instance.clear(); return R3.API.Renderer.D3.Canvas.prototype.getSize.call(this);
}; };
/**
* Convenience function to set viewport
* @param x
* @param y
* @param width
* @param height
*/
R3.Renderer.D3.prototype.setViewport = function(
x,
y,
width,
height
) {
this.instance.setViewport(
x,
y,
width,
height
);
};
/**
* Renders to this.renderTarget
* @param scene
* @param camera
*/
R3.Renderer.D3.prototype.renderToTarget = function(scene, camera) {
this.instance.render(
scene.instance,
camera.instance,
this.renderTarget.instance
);
};
/**
* Renders normally
* @param scene
* @param camera
*/
R3.Renderer.D3.prototype.render = function(scene, camera) {
this.instance.render(
scene.instance,
camera.instance
)
};
/**
*
* @returns {R3.API.Renderer.D3}
*/
R3.Renderer.D3.prototype.toApiObject = function() {
var apiRenderer = R3.Renderer.prototype.toApiObject.call(this);
var apiRendererD3 = new R3.API.Renderer.D3(
apiRenderer,
this.renderMode,
this.autoClear,
this.autoClearColor,
this.autoClearDepth,
this.autoClearStencil,
this.gammaFactor,
this.gammaInput,
this.gammaOutput,
this.maxMorphTargets,
this.maxMorphNormals,
this.physicallyCorrectLights,
this.shadowMapEnabled,
this.shadowMapAutoUpdate,
this.shadowMapNeedsUpdate,
this.shadowMapType,
this.shadowMapRenderReverseSided,
this.shadowMapRenderSingleSided,
this.sortObjects,
this.toneMapping,
this.toneMappingExposure,
this.toneMappingWhitePoint,
this.premultipliedAlpha,
this.antialias,
this.stencil,
this.preserveDrawingBuffer,
this.depth,
this.logarithmicDepthBuffer,
this.localClippingEnabled,
R3.Utils.IdOrNull(this.renderTarget),
this.clippingPlanes.map(
function(clippingPlane){
return R3.Utils.IdOrNull(clippingPlane);
}
),
this.clearColor.toApiObject(),
this.viewports.map(
function(viewport){
return R3.Utils.IdOrNull(viewport);
}
),
this.alpha,
this.opacity
);
return apiRendererD3;
};

View File

@ -1,67 +1,16 @@
/** /**
* R3.Renderer.D3 * R3.Renderer.D3
* @param graphics R3.Runtime.Graphics * @param parent
* @param apiRendererD3 R3.API.Renderer.D3 * @param linkedObjects
* @constructor * @constructor
*/ */
R3.Renderer.D3 = function( R3.Renderer.D3 = function(
graphics, parent,
apiRendererD3 linkedObjects
) { ) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiRendererD3)) { if (R3.Utils.UndefinedOrNull(linkedObjects)) {
apiRendererD3 = { linkedObjects = {}
rendererType : R3.API.Renderer.RENDERER_TYPE_3D
};
}
R3.API.Renderer.D3.call(
this,
apiRendererD3,
apiRendererD3.renderMode,
apiRendererD3.autoClear,
apiRendererD3.autoClearColor,
apiRendererD3.autoClearDepth,
apiRendererD3.autoClearStencil,
apiRendererD3.gammaFactor,
apiRendererD3.gammaInput,
apiRendererD3.gammaOutput,
apiRendererD3.maxMorphTargets,
apiRendererD3.maxMorphNormals,
apiRendererD3.physicallyCorrectLights,
apiRendererD3.shadowMapEnabled,
apiRendererD3.shadowMapAutoUpdate,
apiRendererD3.shadowMapNeedsUpdate,
apiRendererD3.shadowMapType,
apiRendererD3.shadowMapRenderReverseSided,
apiRendererD3.shadowMapRenderSingleSided,
apiRendererD3.sortObjects,
apiRendererD3.toneMapping,
apiRendererD3.toneMappingExposure,
apiRendererD3.toneMappingWhitePoint,
apiRendererD3.premultipliedAlpha,
apiRendererD3.antialias,
apiRendererD3.stencil,
apiRendererD3.preserveDrawingBuffer,
apiRendererD3.depth,
apiRendererD3.logarithmicDepthBuffer,
apiRendererD3.localClippingEnabled,
apiRendererD3.renderTarget,
apiRendererD3.clippingPlanes,
apiRendererD3.clearColor,
apiRendererD3.viewports,
apiRendererD3.alpha,
apiRendererD3.opacity,
apiRendererD3.composer,
apiRendererD3.effect,
apiRendererD3.enableComposer,
apiRendererD3.enableEffect
);
if (this.renderTarget instanceof R3.D3.API.RenderTarget) {
this.renderTarget = R3.Component.ConstructFromObject(this.renderTarget);
} }
this.clippingPlanes = this.clippingPlanes.reduce( this.clippingPlanes = this.clippingPlanes.reduce(
@ -72,18 +21,11 @@ R3.Renderer.D3 = function(
} }
result.push(clippingPlane); result.push(clippingPlane);
return result; return result;
}, },
[] []
); );
this.clearColor = new R3.Color(
this.graphics,
this.clearColor,
this
);
this.viewports = this.viewports.reduce( this.viewports = this.viewports.reduce(
function(result, viewport) { function(result, viewport) {
@ -92,24 +34,23 @@ R3.Renderer.D3 = function(
} }
result.push(viewport); result.push(viewport);
return result; return result;
}, },
[] []
); );
if (this.composer instanceof R3.D3.API.Composer) { linkedObjects.clippingPlanes = [R3.Plane];
this.composer = R3.Component.ConstructFromObject(this.composer); linkedObjects.viewports = [R3.D3.Viewport];
}
if (this.effect instanceof R3.D3.API.Effect) { this.clearColor = new R3.Color(
this.effect = R3.Component.ConstructFromObject(this.effect); parent,
} this.clearColor
);
R3.Renderer.call( R3.Renderer.call(
this, this,
this.graphics, parent,
this linkedObjects
); );
}; };
@ -123,82 +64,39 @@ R3.Renderer.D3.prototype.constructor = R3.Renderer.D3;
*/ */
R3.Renderer.D3.prototype.createInstance = function() { R3.Renderer.D3.prototype.createInstance = function() {
if ( if (!this.instance) {
R3.Utils.UndefinedOrNull(this.canvas) || throw new Error('R3.Renderer.D3 createInstance called out of order');
R3.Utils.UndefinedOrNull(this.canvas.instance)
) {
console.warn('no canvas instance');
return;
} }
this.instance = new THREE.WebGLRenderer( this.updateInstance('autoClear');
{ this.updateInstance('autoClearColor');
canvas : this.canvas.instance, this.updateInstance('autoClearDepth');
alpha : this.alpha, this.updateInstance('autoClearStencil');
premultipliedAlpha : this.premultipliedAlpha, this.updateInstance('gammaFactor');
antialias : this.antialias, this.updateInstance('gammaInput');
stencil : this.stencil, this.updateInstance('gammaOutput');
preserveDrawingBuffer : this.preserveDrawingBuffer, this.updateInstance('maxMorphTargets');
depth : this.depth, this.updateInstance('maxMorphNormals');
logarithmicDepthBuffer : this.logarithmicDepthBuffer this.updateInstance('physicallyCorrectLights');
} this.updateInstance('shadowMapEnabled');
); this.updateInstance('shadowMapAutoUpdate');
this.updateInstance('shadowMapNeedsUpdate');
this.updateInstance('shadowMapType');
this.updateInstance('shadowMapRenderReverseSided');
this.updateInstance('shadowMapRenderSingleSided');
this.updateInstance('sortObjects');
this.updateInstance('toneMapping');
this.updateInstance('toneMappingExposure');
this.updateInstance('toneMappingWhitePoint');
this.updateInstance('localClippingEnabled');
this.updateInstance('clippingPlanes');
this.updateInstance('clearColor');
this.updateInstance('viewports');
this.updateInstance('opacity');
this.updateInstance('pixelRatio');
this.instance.setPixelRatio(window.devicePixelRatio); R3.Component.prototype.createInstance.call(this);
this.instance.autoClear = this.autoClear;
this.instance.autoClearColor = this.autoClearColor;
this.instance.autoClearDepth = this.autoClearDepth;
this.instance.autoClearStencil = this.autoClearStencil;
this.instance.gammaFactor = this.gammaFactor;
this.instance.gammaInput = this.gammaInput;
this.instance.gammaOutput = this.gammaOutput;
this.instance.maxMorphTargets = this.maxMorphTargets;
this.instance.maxMorphNormals = this.maxMorphNormals;
this.instance.physicallyCorrectLights = this.physicallyCorrectLights;
this.instance.shadowMap.enabled = this.shadowMapEnabled;
this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate;
this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate;
this.instance.shadowMap.type = this.shadowMapType;
this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided;
this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided;
this.instance.sortObjects = this.sortObjects;
this.instance.toneMapping = this.toneMapping;
this.instance.toneMappingExposure = this.toneMappingExposure;
this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint;
this.instance.premultipliedAlpha = this.premultipliedAlpha;
this.instance.localClippingEnabled = this.localClippingEnabled;
if (this.renderTarget) {
this.instance.setRenderTarget(this.renderTarget.instance);
}
if (this.clippingPlanes.length > 0) {
this.instance.clippingPlanes = this.clippingPlanes.map(
function(clippingPlane) {
return clippingPlane.instance;
}
)
}
this.instance.setClearColor(
new THREE.Color(
this.clearColor.r,
this.clearColor.g,
this.clearColor.b
),
this.opacity
);
R3.Renderer.prototype.createInstance.call(this);
}; };
/** /**
@ -214,11 +112,6 @@ R3.Renderer.D3.prototype.updateInstance = function(property) {
throw new Error('no renderer instance'); throw new Error('no renderer instance');
} }
if (property === 'renderMode') {
console.log('render mode change');
return;
}
if (property === 'autoClear') { if (property === 'autoClear') {
this.instance.autoClear = this.autoClear; this.instance.autoClear = this.autoClear;
return; return;
@ -324,11 +217,6 @@ R3.Renderer.D3.prototype.updateInstance = function(property) {
return; return;
} }
if (property === 'premultipliedAlpha') {
this.instance.premultipliedAlpha = this.premultipliedAlpha;
return;
}
if (property === 'antialias') { if (property === 'antialias') {
this.instance.antialias = this.antialias; this.instance.antialias = this.antialias;
return; return;
@ -359,33 +247,6 @@ R3.Renderer.D3.prototype.updateInstance = function(property) {
return; return;
} }
if (property === 'canvas') {
if (R3.Utils.UndefinedOrNull(this.instance)) {
this.createInstance();
} else {
console.warn('experimental canvas change for renderer');
this.instance.dispose();
this.createInstance();
}
return;
}
if (property === 'renderTarget') {
if (
R3.Utils.Defined(this.instance) &&
R3.Utils.Defined(this.renderTarget) &&
R3.Utils.Defined(this.renderTarget.instance)
) {
this.instance.setRenderTarget(this.renderTarget.instance);
console.log('updated render target on render instance');
}
return;
}
if (property === 'clippingPlanes') { if (property === 'clippingPlanes') {
console.warn('todo: clipping planes change'); console.warn('todo: clipping planes change');
return; return;
@ -415,119 +276,11 @@ R3.Renderer.D3.prototype.updateInstance = function(property) {
return; return;
} }
if (property === 'pixelRatio') {
this.instance.setPixelRatio(this.pixelRatio);
return;
}
R3.Renderer.prototype.updateInstance.call(this, property); R3.Renderer.prototype.updateInstance.call(this, property);
}; };
/**
* Wrapper for clear()
*/
R3.Renderer.D3.prototype.clear = function() {
return this.instance.clear();
};
/**
* Convenience function to set viewport
* @param x
* @param y
* @param width
* @param height
*/
R3.Renderer.D3.prototype.setViewport = function(
x,
y,
width,
height
) {
this.instance.setViewport(
x,
y,
width,
height
);
};
/**
* Renders to this.renderTarget
* @param scene
* @param camera
*/
R3.Renderer.D3.prototype.renderToTarget = function(scene, camera) {
this.instance.render(
scene.instance,
camera.instance,
this.renderTarget.instance
);
};
/**
* Renders normally
* @param scene
* @param camera
*/
R3.Renderer.D3.prototype.render = function(scene, camera) {
this.instance.render(
scene.instance,
camera.instance
)
};
/**
*
* @returns {R3.API.Renderer.D3}
*/
R3.Renderer.D3.prototype.toApiObject = function() {
var apiRenderer = R3.Renderer.prototype.toApiObject.call(this);
var apiRendererD3 = new R3.API.Renderer.D3(
apiRenderer,
this.renderMode,
this.autoClear,
this.autoClearColor,
this.autoClearDepth,
this.autoClearStencil,
this.gammaFactor,
this.gammaInput,
this.gammaOutput,
this.maxMorphTargets,
this.maxMorphNormals,
this.physicallyCorrectLights,
this.shadowMapEnabled,
this.shadowMapAutoUpdate,
this.shadowMapNeedsUpdate,
this.shadowMapType,
this.shadowMapRenderReverseSided,
this.shadowMapRenderSingleSided,
this.sortObjects,
this.toneMapping,
this.toneMappingExposure,
this.toneMappingWhitePoint,
this.premultipliedAlpha,
this.antialias,
this.stencil,
this.preserveDrawingBuffer,
this.depth,
this.logarithmicDepthBuffer,
this.localClippingEnabled,
R3.Utils.IdOrNull(this.renderTarget),
this.clippingPlanes.map(
function(clippingPlane){
return R3.Utils.IdOrNull(clippingPlane);
}
),
this.clearColor.toApiObject(),
this.viewports.map(
function(viewport){
return R3.Utils.IdOrNull(viewport);
}
),
this.alpha,
this.opacity
);
return apiRendererD3;
};

View File

@ -375,6 +375,70 @@ R3.Runtime.Graphics.Three.prototype.CubeCamera = function(near, far, cubeResolut
}; };
R3.Runtime.Graphics.Three.prototype.OrthographicCamera = function(
left,
right,
top,
bottom,
near,
far
) {
return new THREE.OrthographicCamera(
left,
right,
top,
bottom,
near,
far
);
};
R3.Runtime.Graphics.Three.prototype.PerspectiveCamera = function(
fov,
aspect,
near,
far
) {
return new THREE.PerspectiveCamera(
this.fov,
this.aspect,
this.near,
this.far
);
};
R3.Runtime.Graphics.Three.prototype.StereoCamera = function(
fov,
aspect,
near,
far,
stereoMode
) {
console.warn('TODO: implement stereo camera again');
var camera = new THREE.PerspectiveCamera(
fov,
aspect,
near,
far
);
var instance = new THREE.StereoCamera();
for (var property in instance) {
if (
instance.hasOwnProperty(property) ||
typeof instance[property] === 'function'
) {
camera[property] = instance[property];
}
}
return camera;
};
R3.Runtime.Graphics.Three.prototype.RenderTarget = function( R3.Runtime.Graphics.Three.prototype.RenderTarget = function(
width, width,
height, height,
@ -405,4 +469,92 @@ R3.Runtime.Graphics.Three.prototype.RenderTarget = function(
stencilBuffer : stencilBuffer, stencilBuffer : stencilBuffer,
} }
); );
};
R3.Runtime.Graphics.Three.prototype.Composer = function(
renderer,
renderTarget,
passes,
size
) {
if (!renderer.instance) {
throw new Error('no renderer instance');
}
var renderTargetInstance = undefined;
if (renderTarget && renderTarget.instance) {
renderTargetInstance;
}
var composer = new THREE.EffectComposer(
renderer.instance,
renderTargetInstance
);
passes.map(
function(pass) {
if (!pass.instance) {
throw new Error('Pass instance not set');
}
composer.addPass(pass.instance);
}
);
composer.setSize(
size.width,
size.height
);
};
R3.Runtime.Graphics.Three.prototype.Renderer3D = function(
canvas,
alpha,
premultipliedAlpha,
antialias,
stencil,
preserveDrawingBuffer,
depth,
logarithmicDepthBuffer
) {
return new THREE.WebGLRenderer(
{
canvas : canvas.instance,
alpha : alpha,
premultipliedAlpha : premultipliedAlpha,
antialias : antialias,
stencil : stencil,
preserveDrawingBuffer : preserveDrawingBuffer,
depth : depth,
logarithmicDepthBuffer : logarithmicDepthBuffer
}
);
};
R3.Runtime.Graphics.Three.prototype.AnaglyphEffect = function(
renderer
) {
return new THREE.AnaglyphEffect(
renderer.instance
);
};
R3.Runtime.Graphics.Three.prototype.ParallaxEffect = function(
renderer
) {
return new THREE.ParallaxBarrierEffect(
renderer.instance
);
};
R3.Runtime.Graphics.Three.prototype.StereoEffect = function(
renderer
) {
new THREE.StereoEffect(
renderer.instance
);
}; };

View File

@ -78,15 +78,45 @@ R3.Runtime.Graphics.prototype.Audio = function(
volume, volume,
cameraIndex cameraIndex
) { ) {
console.warn('override Shape in child class'); console.warn('override Audio in child class');
}; };
R3.Runtime.Graphics.prototype.Bone = function() { R3.Runtime.Graphics.prototype.Bone = function() {
console.warn('override Shape in child class'); console.warn('override Bone in child class');
}; };
R3.Runtime.Graphics.prototype.CubeCamera = function(near, far, cubeResolution) { R3.Runtime.Graphics.prototype.CubeCamera = function(near, far, cubeResolution) {
console.warn('override Shape in child class'); console.warn('override CubeCamera in child class');
};
R3.Runtime.Graphics.prototype.OrthographicCamera = function(
left,
right,
top,
bottom,
near,
far
) {
console.warn('override OrthographicCamera in child class');
};
R3.Runtime.Graphics.prototype.PerspectiveCamera = function(
fov,
aspect,
near,
far
) {
console.warn('override PerspectiveCamera in child class');
};
R3.Runtime.Graphics.prototype.StereoCamera = function(
fov,
aspect,
near,
far,
stereoMode
) {
console.warn('override StereoCamera in child class');
}; };
R3.Runtime.Graphics.prototype.RenderTarget = function( R3.Runtime.Graphics.prototype.RenderTarget = function(
@ -103,5 +133,45 @@ R3.Runtime.Graphics.prototype.RenderTarget = function(
depthBuffer, depthBuffer,
stencilBuffer stencilBuffer
) { ) {
console.warn('override Shape in child class'); console.warn('override RenderTarget in child class');
}; };
R3.Runtime.Graphics.prototype.Composer = function(
renderer,
renderTarget,
passes,
size
) {
console.warn('override Composer in child class');
};
R3.Runtime.Graphics.prototype.Renderer3D = function(
canvas,
alpha,
premultipliedAlpha,
antialias,
stencil,
preserveDrawingBuffer,
depth,
logarithmicDepthBuffer
) {
console.warn('override Renderer3D in child class');
};
R3.Runtime.Graphics.prototype.AnaglyphEffect = function(
renderer
) {
console.warn('override AnaglyphEffect in child class');
};
R3.Runtime.Graphics.prototype.ParallaxEffect = function(
renderer
) {
console.warn('override ParallaxEffect in child class');
};
R3.Runtime.Graphics.prototype.StereoEffect = function(
renderer
) {
console.warn('override StereoEffect in child class');
};

View File

@ -65,8 +65,6 @@ R3.System.Render = function(
this.windowResizeSubscription = null; this.windowResizeSubscription = null;
this.statistics = []; this.statistics = [];
this.projects = [];
}; };
R3.System.Render.prototype = Object.create(R3.System.prototype); R3.System.Render.prototype = Object.create(R3.System.prototype);
@ -474,42 +472,38 @@ R3.System.Render.prototype.render = function(data) {
* TODO: implement 2D rendering * TODO: implement 2D rendering
*/ */
if (renderer instanceof R3.Renderer.D2) { if (renderer instanceof R3.Renderer.D2) {
console.log('TODO: implement 2D rendering') console.log('TODO: implement 2D rendering');
return; return;
} }
this.projects.map( this.project.renderers.map(
function(project) {
project.renderers.map( function(renderer) {
function(renderer) {
var scenes = project.scenes; if (!renderer.instance) {
console.warn('renderer not ready');
return;
}
var camera = project.cameras[project.cameraIndex]; var size = renderer.getSize();
var effect = renderer.effect; renderer.viewports.map(
function (viewport) {
if ( if (!viewport.instance) {
renderer.renderMode === R3.API.Renderer.MODE_TARGET || console.warn('viewport not ready');
renderer.renderMode === R3.API.Renderer.MODE_CANVAS_AND_TARGET return;
) {
if (!renderer.renderTarget) {
console.warn('no renderTarget');
renderer.clear();
return;
}
} }
/** renderer.setViewport(
* If this renderer has autoClear set but multiple scenes, we want to render the all the scenes viewport.x * size.width,
* first and then restore the autoClear setting, otherwise rendering multiple scenes will result in viewport.y * size.height,
* only one scene being rendered. Setting the autoClear setting to false is not an option because viewport.width * size.width,
* in this situation all scenes will be renderered continuously (with no clearing in between at all) viewport.height * size.height
* @type {boolean} );
*/
var resetAutoClear = false; var resetAutoClear = false;
if (scenes.length > 1) { if (viewport.scenes.length > 1) {
if (renderer.autoClear) { if (renderer.autoClear) {
resetAutoClear = true; resetAutoClear = true;
@ -521,37 +515,32 @@ R3.System.Render.prototype.render = function(data) {
renderer.clear(); renderer.clear();
} }
/** viewport.scenes.map(
* Do the rendering
*/
var size = renderer.getSize();
renderer.viewports.map(
function(viewport) { function (scene) {
renderer.setViewport( if (!scene.instance) {
viewport.x * size.width, console.warn('scene not ready');
viewport.y * size.height, return;
viewport.width * size.width, }
viewport.height * size.height
);
var cubeCameras = project.cameras.reduce(
function(result, camera){
if (camera instanceof R3.D3.Camera.Cube) {
result.push(camera);
}
return result;
},
[]
);
/** /**
* Update any cube camera's based on the scene * Render textures first
*/ */
cubeCameras.map( scene.cubeCameras.map(
function(cubeCamera) { function(cubeCamera) {
if (!cubeCamera.instance) {
console.warn('cube camera not ready');
return;
}
/**
* TODO: optimize this to add / remove meshes via Events to prevent looping through
* TODO: all of them to inspect their excludeFromEnvironmentMapMap settings
* @type {T | Array}
*/
var meshesExcluded = scene.meshes.reduce( var meshesExcluded = scene.meshes.reduce(
function(result, mesh){ function(result, mesh){
if (mesh.excludeFromEnvironmentMapMap) { if (mesh.excludeFromEnvironmentMapMap) {
@ -569,10 +558,9 @@ R3.System.Render.prototype.render = function(data) {
} }
); );
scenes.map( cubeCamera.instance.update(
function(scene) { renderer.instance,
cubeCamera.update(renderer, scene); scene.instance
}
); );
meshesExcluded.map( meshesExcluded.map(
@ -583,64 +571,106 @@ R3.System.Render.prototype.render = function(data) {
); );
}.bind(this) }.bind(this)
); );
if (renderer.enableComposer) { var camera = null;
if (renderer.composer && renderer.composer.ready()) { if (this.applicationMode === R3.API.Project.APPLICATION_MODE_EDIT) {
renderer.composer.render(); camera = this.project.cameras[scene.cameraIndexEdit];
} else { } else {
console.log('composer not ready'); camera = this.project.cameras[scene.cameraIndexRun];
} }
if (!camera || !camera.instance) {
console.warn('camera not ready');
return; return;
} }
scenes.map( if (scene.enableEffect) {
function(scene) { if (!scene.effect) {
console.warn('enabling an effect when no effect is specified on the scene has no effect');
return;
}
var backupCamera = camera; if (scene.enableComposer) {
console.warn('only an effect or composer can be active at any given time');
return;
}
/** if (!scene.effect.ready()) {
* Scene camera overrides normal camera console.warn('the effect is not ready yet: ' + scene.effect.name);
*/ }
if (scene.camera) {
camera = scene.camera; if (renderer.target) {
console.warn('todo: test if rendering effect to target works');
if (!scene.effect.instance) {
return;
} }
if (renderer.renderMode === R3.API.Renderer.MODE_TARGET || scene.effect.instance.render(
renderer.renderMode === R3.API.Renderer.MODE_CANVAS_AND_TARGET) { scene.instance,
camera.instance,
renderer.target.instance
);
}
renderer.renderToTarget( if (!scene.effect.instance) {
scene, return;
camera }
)
} scene.effect.instance.render(
scene.instance,
camera.instance
);
if (renderer.renderMode === R3.API.Renderer.MODE_CANVAS || console.warn('todo: check if have to return from effect render here');
renderer.renderMode === R3.API.Renderer.MODE_CANVAS_AND_TARGET) { //return;
if (renderer.enableEffect) { }
if (renderer.effect && renderer.effect.ready(scene, camera)) { if (scene.enableComposer) {
effect.render(scene, camera);
} else {
console.log('effect not ready');
}
return; if (!scene.composer) {
} console.warn('enabling a composer when no composer is specified on the scene has no effect');
return;
}
renderer.render(scene, camera); if (!scene.composer.ready()) {
} console.warn('the composer is not ready yet: ' + scene.composer.name);
}
camera = backupCamera; scene.composer.render();
}.bind(this) console.warn('todo: check if have to return from composer render here');
//return;
}
if (renderer.target) {
if (!render.target.instance) {
console.warn('render target instance not ready');
}
renderer.instance.render(
scene.instance,
camera.instance,
renderer.target.instance
)
}
renderer.instance.render(
scene.instance,
camera.instance
); );
/**
* end of scene
*/
}.bind(this) }.bind(this)
); );
/** /**
@ -650,9 +680,18 @@ R3.System.Render.prototype.render = function(data) {
renderer.autoClear = true; renderer.autoClear = true;
renderer.updateInstance('autoClear'); renderer.updateInstance('autoClear');
} }
}
/**
* end of viewport
*/
}.bind(this)
); );
}
/**
* end of renderer
*/
}.bind(this)
); );
R3.Event.Emit( R3.Event.Emit(