beta.r3js.org
cybafelo 2019-08-10 19:48:08 +02:00
parent 7106e3368a
commit 7611567b2c
54 changed files with 833 additions and 977 deletions

View File

@ -16,7 +16,9 @@ code += '\tR3.API.Component.call(\n';
code += '\t\tthis,\n'; code += '\t\tthis,\n';
code += '\t\tthis.apiComponent.parent,\n'; code += '\t\tthis.apiComponent.parent,\n';
code += '\t\tthis.apiComponent.id,\n'; code += '\t\tthis.apiComponent.id,\n';
code += '\t\tthis.apiComponent.name\n'; code += '\t\tthis.apiComponent.name,\n';
code += '\t\tthis.apiComponent.register,\n';
code += '\t\tthis.apiComponent.selected\n';
code += '\t)'; code += '\t)';
var code2 = 'if (R3.Utils.UndefinedOrNull(apiGeometryBuffer)) {\n'; var code2 = 'if (R3.Utils.UndefinedOrNull(apiGeometryBuffer)) {\n';

View File

@ -2,11 +2,7 @@
* Event Core * Event Core
* @constructor * @constructor
*/ */
R3.Event = function(parent) { R3.Event = function() {
if (!parent) {
parent = null;
}
this.parent = parent;
}; };
/** /**
@ -143,6 +139,7 @@ R3.Event.GET_WEBSOCKET_CONFIG = 0x79;
R3.Event.GET_PROJECT = 0x7a; R3.Event.GET_PROJECT = 0x7a;
R3.Event.GET_APPLICATION_MODE = 0x80; R3.Event.GET_APPLICATION_MODE = 0x80;
R3.Event.RENDERER_SIZE_CHANGE = 0x81; R3.Event.RENDERER_SIZE_CHANGE = 0x81;
R3.Event.GET_REGISTER_FACES = 0x82;
/** /**
* Returns string name of event ID * Returns string name of event ID
@ -277,6 +274,7 @@ R3.Event.GetEventName = function(number) {
case 0x7a : return 'get_project'; case 0x7a : return 'get_project';
case 0x80 : return 'get_application_mode'; case 0x80 : return 'get_application_mode';
case 0x81 : return 'renderer_size_change'; case 0x81 : return 'renderer_size_change';
case 0x82 : return 'get_register_faces';
break; break;
} }

View File

@ -3,12 +3,16 @@
* @param parent * @param parent
* @param id * @param id
* @param name * @param name
* @param register
* @param selected
* @constructor * @constructor
*/ */
R3.API.Component = function( R3.API.Component = function(
parent, parent,
id, id,
name name,
register,
selected
) { ) {
if (R3.Utils.UndefinedOrNull(parent)) { if (R3.Utils.UndefinedOrNull(parent)) {
@ -27,6 +31,16 @@ R3.API.Component = function(
name = R3.Component.GetComponentFriendlyName(this.componentType) + ' (' + this.id + ')'; name = R3.Component.GetComponentFriendlyName(this.componentType) + ' (' + this.id + ')';
} }
this.name = name; this.name = name;
if (R3.Utils.UndefinedOrNull(register)) {
register = true;
}
this.register = register;
if (R3.Utils.UndefinedOrNull(selected)) {
selected = false;
}
this.selected = selected;
}; };
R3.API.Component.prototype.constructor = R3.API.Component; R3.API.Component.prototype.constructor = R3.API.Component;

View File

@ -1,17 +1,11 @@
/** /**
* R3.Component is an R3.Event * R3.Component is an R3.Event
* @param parent
* @param linkedObjects * @param linkedObjects
* @constructor * @constructor
*/ */
R3.Component = function( R3.Component = function(
parent,
linkedObjects linkedObjects
) { ) {
if (R3.Utils.UndefinedOrNull(parent)) {
parent = null;
}
this.parent = parent;
if (R3.Utils.UndefinedOrNull(linkedObjects)) { if (R3.Utils.UndefinedOrNull(linkedObjects)) {
linkedObjects = {}; linkedObjects = {};
@ -21,17 +15,12 @@ R3.Component = function(
/** /**
* Call the Event constructor first so we can set the parent right away * Call the Event constructor first so we can set the parent right away
*/ */
R3.Event.call( R3.Event.call(this);
this,
this.parent
);
this.componentType = this.getComponentType(); this.componentType = this.getComponentType();
this.idToObject = {}; this.idToObject = {};
this.selected = false;
this.building = false; this.building = false;
this.loaded = false; this.loaded = false;
@ -46,12 +35,14 @@ R3.Component = function(
this.dependencies = this.getDependencies(); this.dependencies = this.getDependencies();
this.emit( if (this.register) {
R3.Event.COMPONENT_REGISTER, this.emit(
{ R3.Event.COMPONENT_REGISTER,
component : this {
} component : this
); }
);
}
if (this.dependencies.length === 0) { if (this.dependencies.length === 0) {

View File

@ -10,17 +10,7 @@ R3.API.Box3 = function(
min, min,
max max
) { ) {
if (R3.Utils.UndefinedOrNull(apiComponent)) { __API_COMPONENT_MACRO__;
apiComponent = {};
}
this.apiComponent = apiComponent;
R3.API.Component.call(
this,
this.apiComponent.parent,
this.apiComponent.id,
this.apiComponent.name
);
if (R3.Utils.UndefinedOrNull(min)) { if (R3.Utils.UndefinedOrNull(min)) {
min = new R3.API.Vector3(); min = new R3.API.Vector3();

View File

@ -21,17 +21,7 @@ R3.API.Canvas = function(
textBaseline textBaseline
) { ) {
if (R3.Utils.UndefinedOrNull(apiComponent)) { __API_COMPONENT_MACRO__;
apiComponent = {};
}
this.apiComponent = apiComponent;
R3.API.Component.call(
this,
this.apiComponent.parent,
this.apiComponent.id,
this.apiComponent.name
);
if (R3.Utils.UndefinedOrNull(autoUpdateSize)) { if (R3.Utils.UndefinedOrNull(autoUpdateSize)) {
autoUpdateSize = true; autoUpdateSize = true;

View File

@ -16,7 +16,7 @@ R3.API.Controls = function(
* Try to attach the controls to the parent canvas * Try to attach the controls to the parent canvas
* @type {null} * @type {null}
*/ */
canvas = this.getParent('canvas'); canvas = this.getFirstParent(R3.API.Canvas);
} }
this.canvas = canvas; this.canvas = canvas;
}; };

View File

@ -18,15 +18,8 @@ R3.API.Controls.D3 = function(
); );
if (R3.Utils.UndefinedOrNull(camera)) { if (R3.Utils.UndefinedOrNull(camera)) {
/** var project = this.getFirstParent(R3.API.Project);
* Get the cameraIndexEdit of the scene which is responsible for these controls camera = project.cameras[R3.API.Project.CAMERA_INDEX_EDIT];
*/
var cameraIndex = this.getParent('cameraIndexEdit');
/**
* Now get the camera with this index from our project cameras
*/
camera = this.getParent('cameras', cameraIndex);
} }
this.camera = camera; this.camera = camera;
}; };

View File

@ -4,7 +4,7 @@
* @param path - Relative to API URL * @param path - Relative to API URL
* @constructor * @constructor
*/ */
R3.D3.API.Font = function( R3.API.Font = function(
apiComponent, apiComponent,
path path
) { ) {
@ -18,5 +18,5 @@ R3.D3.API.Font = function(
}; };
R3.D3.API.Font.prototype = Object.create(R3.API.Component.prototype); R3.API.Font.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Font.prototype.constructor = R3.D3.API.Font; R3.API.Font.prototype.constructor = R3.API.Font;

View File

@ -1,11 +1,9 @@
/** /**
* R3.Box3 * R3.Box3
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.Box3 = function( R3.Box3 = function(
parent,
apiComponent apiComponent
) { ) {
@ -30,10 +28,7 @@ R3.Box3 = function(
this.componentRuntime = R3.Component.GetComponentRuntime(this.parent); this.componentRuntime = R3.Component.GetComponentRuntime(this.parent);
R3.Component.call( R3.Component.call(this);
this,
parent
);
}; };
R3.Box3.prototype = Object.create(R3.Component.prototype); R3.Box3.prototype = Object.create(R3.Component.prototype);

View File

@ -32,7 +32,6 @@ R3.Canvas = function(
R3.Component.call( R3.Component.call(
this, this,
parent,
{ {
'texts' : [R3.D3.Text] 'texts' : [R3.D3.Text]
} }

View File

@ -26,11 +26,6 @@ R3.Curve = function(
apiComponent.arcLenghDivisions apiComponent.arcLenghDivisions
); );
R3.Component.call(
this,
parent
);
} else { } else {
/** /**
@ -38,15 +33,13 @@ R3.Curve = function(
* Add any more linking information to the linkedObjects object here * Add any more linking information to the linkedObjects object here
*/ */
R3.Component.call(
this,
parent,
linkedObjects
);
} }
R3.Component.call(
this,
parent,
linkedObjects
);
}; };

View File

@ -22,25 +22,9 @@ R3.D3.API.Face.Graphics = function(
apiFace.v1index, apiFace.v1index,
apiFace.v2index, apiFace.v2index,
apiFace.vertexNormals, apiFace.vertexNormals,
apiFace.normal, 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)) { if (R3.Utils.UndefinedOrNull(materialIndex)) {
materialIndex = -1; materialIndex = -1;
} }
@ -65,46 +49,26 @@ R3.D3.API.Face.Graphics = function(
} }
this.vertexColors = vertexColors; 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;
}; };
/** R3.D3.API.Face.Graphics.prototype = Object.create(R3.D3.API.Face.prototype);
* 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; R3.D3.API.Face.Graphics.prototype.constructor = R3.D3.API.Face.Graphics;
/** /**
* Clone a Face * Clone
* @returns {R3.D3.API.Face} * @returns {R3.D3.API.Face.Graphics}
*/ */
R3.D3.API.Face.Graphics.prototype.clone = function(){ R3.D3.API.Face.Graphics.prototype.clone = function(){
return new R3.D3.API.Face(
null, var apiFace = R3.D3.API.Face.prototype.clone.call(
this.v0index, this
this.v1index, );
this.v2index,
return new R3.D3.API.Face.Graphics(
apiFace,
this.materialIndex, this.materialIndex,
this.uvs, this.uvs,
this.color, this.color,
this.vertexColors, this.vertexColors
this.vertexNormals,
this.normal,
this.selected
); );
}; };

View File

@ -6,7 +6,6 @@
* @param v2index * @param v2index
* @param vertexNormals * @param vertexNormals
* @param normal * @param normal
* @param selected
* @constructor * @constructor
*/ */
R3.D3.API.Face = function( R3.D3.API.Face = function(
@ -15,10 +14,32 @@ R3.D3.API.Face = function(
v1index, v1index,
v2index, v2index,
vertexNormals, vertexNormals,
normal, normal
selected
) { ) {
/**
* By default, we want to avoid registering faces as components
*/
if (R3.Utils.UndefinedOrNull(apiComponent)) {
apiComponent = {};
}
apiComponent.register = false;
/**
* Check whether we need to register the faces
* @type {boolean}
*/
R3.Event.Emit(
R3.Event.GET_REGISTER_FACES,
null,
function(register) {
if (register) {
apiComponent.register = true;
}
}
);
__API_COMPONENT_MACRO__; __API_COMPONENT_MACRO__;
if (R3.Utils.UndefinedOrNull(v0index)) { if (R3.Utils.UndefinedOrNull(v0index)) {
@ -46,17 +67,8 @@ R3.D3.API.Face = function(
} }
this.normal = normal; 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.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.Face.prototype = Object.create(R3.API.Component.prototype);
R3.D3.API.Face.prototype.constructor = R3.D3.API.Face; R3.D3.API.Face.prototype.constructor = R3.D3.API.Face;
@ -71,8 +83,7 @@ R3.D3.API.Face.prototype.clone = function(){
this.v1index, this.v1index,
this.v2index, this.v2index,
this.vertexNormals, this.vertexNormals,
this.normal, this.normal
this.selected
); );
}; };

28
src/r3-d3-api-fog-exp.js Normal file
View File

@ -0,0 +1,28 @@
/**
* R3.D3.API.Fog.Exp
* @param apiFog
* @param density
* @constructor
*/
R3.D3.API.Fog.Exp = function(
apiFog,
density
) {
__API_COMPONENT_MACRO__;
R3.D3.API.Fog.call(
this,
apiFog,
apiFog.color
);
if (R3.Utils.UndefinedOrNull(density)) {
density = 0.00025;
}
this.density = density;
};
R3.D3.API.Fog.Exp.prototype = Object.create(R3.D3.API.Fog.prototype);
R3.D3.API.Fog.Exp.prototype.constructor = R3.D3.API.Fog.Exp;

View File

@ -0,0 +1,35 @@
/**
* R3.D3.API.Fog.Normal
* @param apiFog
* @param near
* @param far
* @constructor
*/
R3.D3.API.Fog.Normal = function(
apiFog,
near,
far,
) {
__API_COMPONENT_MACRO__;
R3.D3.API.Fog.call(
this,
apiFog,
apiFog.color
);
if (R3.Utils.UndefinedOrNull(near)) {
near = 1;
}
this.near = near;
if (R3.Utils.UndefinedOrNull(far)) {
far = 1000;
}
this.far = far;
};
R3.D3.API.Fog.Normal.prototype = Object.create(R3.D3.API.Fog.prototype);
R3.D3.API.Fog.Normal.prototype.constructor = R3.D3.API.Fog.Normal;

View File

@ -1,49 +1,21 @@
/** /**
* R3.D3.API.Fog * R3.D3.API.Fog
* @param apiComponent * @param apiComponent
* @param exponential
* @param color * @param color
* @param near
* @param far
* @param density
* @constructor * @constructor
*/ */
R3.D3.API.Fog = function( R3.D3.API.Fog = function(
apiComponent, apiComponent,
exponential, color
color,
near,
far,
density
) { ) {
__API_COMPONENT_MACRO__; __API_COMPONENT_MACRO__;
if (R3.Utils.UndefinedOrNull(exponential)) {
exponential = false;
}
this.exponential = exponential;
if (R3.Utils.UndefinedOrNull(color)) { if (R3.Utils.UndefinedOrNull(color)) {
color = new R3.API.Color(this, 1, 1, 1, 1) color = new R3.API.Color(this, 1, 1, 1, 1)
} }
this.color = color; this.color = color;
if (R3.Utils.UndefinedOrNull(near)) {
near = 1;
}
this.near = near;
if (R3.Utils.UndefinedOrNull(far)) {
far = 1000;
}
this.far = far;
if (R3.Utils.UndefinedOrNull(density)) {
density = 0.00025;
}
this.density = density;
}; };
R3.D3.API.Fog.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.Fog.prototype = Object.create(R3.API.Component.prototype);

View File

@ -18,22 +18,41 @@ R3.D3.API.Geometry = function(
__API_COMPONENT_MACRO__; __API_COMPONENT_MACRO__;
if (R3.Utils.UndefinedOrNull(boundingBox)) { if (R3.Utils.UndefinedOrNull(boundingBox)) {
boundingBox = new R3.API.Box3(); boundingBox = new R3.API.Box3(
{
parent : this
}
);
} }
this.boundingBox = boundingBox; this.boundingBox = boundingBox;
if (R3.Utils.UndefinedOrNull(boundingSphere)) { if (R3.Utils.UndefinedOrNull(boundingSphere)) {
boundingSphere = new R3.API.Sphere(); boundingSphere = new R3.API.Sphere(
{
parent : this
}
);
} }
this.boundingSphere = boundingSphere; this.boundingSphere = boundingSphere;
if (R3.Utils.UndefinedOrNull(faces)) { if (R3.Utils.UndefinedOrNull(faces)) {
faces = []; faces = [
new R3.D3.API.Face(
{
parent : this
},
0,
1,
2
)
];
} }
this.faces = faces; this.faces = faces;
if (R3.Utils.UndefinedOrNull(vertices)) { if (R3.Utils.UndefinedOrNull(vertices)) {
vertices = []; vertices = [
new R3.API.Vector3()
];
} }
this.vertices = vertices; this.vertices = vertices;
}; };

View File

@ -1,9 +1,6 @@
/** /**
* R3.D3.API.Material * R3.D3.API.Material
* @param id * @param apiComponent
* @param name
* @param materialType
* @param parent
* @param parentMeshes * @param parentMeshes
* @param alphaTest * @param alphaTest
* @param blendDst * @param blendDst

View File

@ -4,12 +4,10 @@
* - This class should not be instantiated - it is inherited by some objects to define common properties for 3D objects, * - This class should not be instantiated - it is inherited by some objects to define common properties for 3D objects,
* for example position, rotation, scale etc * for example position, rotation, scale etc
* *
* @param parent
* @param linkedObjects * @param linkedObjects
* @constructor * @constructor
*/ */
R3.D3.Object = function( R3.D3.Object = function(
parent,
linkedObjects linkedObjects
) { ) {

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Animation * R3.D3.Animation
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Animation = function( R3.D3.Animation = function(
parent,
apiComponent apiComponent
) { ) {

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Audio * R3.D3.Audio
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Audio = function( R3.D3.Audio = function(
parent,
apiComponent apiComponent
) { ) {

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.BoneWeight * R3.D3.BoneWeight
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.BoneWeight = function( R3.D3.BoneWeight = function(
parent,
apiComponent apiComponent
) { ) {
@ -19,8 +17,7 @@ R3.D3.BoneWeight = function(
); );
R3.Component.call( R3.Component.call(
this, this
parent
); );
}; };

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Bone * R3.D3.Bone
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Bone = function( R3.D3.Bone = function(
parent,
apiComponent apiComponent
) { ) {
@ -19,8 +17,7 @@ R3.D3.Bone = function(
); );
R3.D3.Object.call( R3.D3.Object.call(
this, this
parent
); );
}; };

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Broadphase * R3.D3.Broadphase
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Broadphase = function( R3.D3.Broadphase = function(
parent,
apiComponent apiComponent
) { ) {
@ -18,8 +16,7 @@ R3.D3.Broadphase = function(
); );
R3.Component.call( R3.Component.call(
this, this
parent
); );
}; };

View File

@ -3,18 +3,15 @@
* *
* - This class cannot be instantiated - simply pass it all through to R3.D3.Object * - This class cannot be instantiated - simply pass it all through to R3.D3.Object
* *
* @param parent
* @param linkedObjects * @param linkedObjects
* @constructor * @constructor
*/ */
R3.D3.Camera = function( R3.D3.Camera = function(
parent,
linkedObjects linkedObjects
) { ) {
R3.D3.Object.call( R3.D3.Object.call(
this, this,
parent,
linkedObjects linkedObjects
); );

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Camera.Cube * R3.D3.Camera.Cube
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Camera.Cube = function( R3.D3.Camera.Cube = function(
parent,
apiComponent apiComponent
) { ) {
@ -30,7 +28,6 @@ R3.D3.Camera.Cube = function(
R3.D3.Camera.call( R3.D3.Camera.call(
this, this,
parent,
linkedObjects linkedObjects
); );

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Camera.Orthographic.FixedAspect * R3.D3.Camera.Orthographic.FixedAspect
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Camera.Orthographic.FixedAspect = function( R3.D3.Camera.Orthographic.FixedAspect = function(
parent,
apiComponent apiComponent
) { ) {
@ -20,7 +18,6 @@ R3.D3.Camera.Orthographic.FixedAspect = function(
R3.D3.Camera.Orthographic.call( R3.D3.Camera.Orthographic.call(
this, this,
parent,
linkedObjects linkedObjects
); );

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Camera.Orthographic.ScaledAspect * R3.D3.Camera.Orthographic.ScaledAspect
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Camera.Orthographic.ScaledAspect = function( R3.D3.Camera.Orthographic.ScaledAspect = function(
parent,
apiComponent apiComponent
) { ) {
@ -24,7 +22,6 @@ R3.D3.Camera.Orthographic.ScaledAspect = function(
R3.D3.Camera.Orthographic.call( R3.D3.Camera.Orthographic.call(
this, this,
parent,
linkedObjects linkedObjects
); );

View File

@ -3,18 +3,15 @@
* *
* - This is an abstract class - should not be instantiated directly * - This is an abstract class - should not be instantiated directly
* *
* @param parent
* @param linkedObjects * @param linkedObjects
* @constructor * @constructor
*/ */
R3.D3.Camera.Orthographic = function( R3.D3.Camera.Orthographic = function(
parent,
linkedObjects linkedObjects
) { ) {
R3.D3.Camera.call( R3.D3.Camera.call(
this, this,
parent,
linkedObjects linkedObjects
); );

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Camera.Perspective.Stereo * R3.D3.Camera.Perspective.Stereo
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Camera.Perspective.Stereo = function( R3.D3.Camera.Perspective.Stereo = function(
parent,
apiComponent apiComponent
) { ) {
@ -21,7 +19,6 @@ R3.D3.Camera.Perspective.Stereo = function(
R3.D3.Camera.call( R3.D3.Camera.call(
this, this,
parent,
linkedObjects linkedObjects
); );

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Camera.Perspective * R3.D3.Camera.Perspective
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Camera.Perspective = function( R3.D3.Camera.Perspective = function(
parent,
apiComponent apiComponent
) { ) {
@ -27,7 +25,6 @@ R3.D3.Camera.Perspective = function(
R3.D3.Camera.call( R3.D3.Camera.call(
this, this,
parent,
linkedObjects linkedObjects
); );

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Composer.RenderTarget * R3.D3.Composer.RenderTarget
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Composer.RenderTarget = function( R3.D3.Composer.RenderTarget = function(
parent,
apiComponent apiComponent
) { ) {
@ -27,7 +25,6 @@ R3.D3.Composer.RenderTarget = function(
R3.D3.Composer.call( R3.D3.Composer.call(
this, this,
parent,
linkedObjects linkedObjects
); );
}; };

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Composer.Renderer * R3.D3.Composer.Renderer
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Composer.Renderer = function( R3.D3.Composer.Renderer = function(
parent,
apiComponent apiComponent
) { ) {
@ -27,7 +25,6 @@ R3.D3.Composer.Renderer = function(
R3.D3.Composer.call( R3.D3.Composer.call(
this, this,
parent,
linkedObjects linkedObjects
); );
}; };

View File

@ -3,12 +3,10 @@
* *
* - This is an abstract class, don't instatiate it directly * - This is an abstract class, don't instatiate it directly
* *
* @param parent
* @param linkedObjects * @param linkedObjects
* @constructor * @constructor
*/ */
R3.D3.Composer = function( R3.D3.Composer = function(
parent,
linkedObjects linkedObjects
) { ) {
@ -34,7 +32,6 @@ R3.D3.Composer = function(
R3.Component.call( R3.Component.call(
this, this,
parent,
linkedObjects linkedObjects
); );
}; };

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Effect * R3.D3.Effect
* @param parent
* @param linkedObjects * @param linkedObjects
* @constructor * @constructor
*/ */
R3.D3.Effect = function( R3.D3.Effect = function(
parent,
linkedObjects linkedObjects
) { ) {
@ -34,7 +32,6 @@ R3.D3.Effect = function(
R3.Component.call( R3.Component.call(
this, this,
parent,
linkedObjects linkedObjects
); );
}; };

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Effect.Anaglyph * R3.D3.Effect.Anaglyph
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Effect.Anaglyph = function( R3.D3.Effect.Anaglyph = function(
parent,
apiComponent apiComponent
) { ) {
@ -17,8 +15,7 @@ R3.D3.Effect.Anaglyph = function(
); );
R3.D3.Effect.call( R3.D3.Effect.call(
this, this
parent
); );
}; };

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Effect.Parallax * R3.D3.Effect.Parallax
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Effect.Parallax = function( R3.D3.Effect.Parallax = function(
parent,
apiComponent apiComponent
) { ) {
@ -17,8 +15,7 @@ R3.D3.Effect.Parallax = function(
); );
R3.D3.Effect.call( R3.D3.Effect.call(
this, this
parent
); );
}; };

View File

@ -1,11 +1,9 @@
/** /**
* R3.D3.Effect.Stereo * R3.D3.Effect.Stereo
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Effect.Stereo = function( R3.D3.Effect.Stereo = function(
parent,
apiComponent apiComponent
) { ) {
@ -17,8 +15,7 @@ R3.D3.Effect.Stereo = function(
); );
R3.D3.Effect.call( R3.D3.Effect.call(
this, this
parent
); );
}; };

View File

@ -1,91 +1,21 @@
/** /**
* R3.D3.Face * R3.D3.Face.Graphics
* @param parent
* @param apiComponent * @param apiComponent
* @constructor * @constructor
*/ */
R3.D3.Face.Graphics = function( R3.D3.Face.Graphics = function(
parent,
apiComponent apiComponent
) { ) {
__RUNTIME_COMPONENT_MACRO__; __RUNTIME_COMPONENT_MACRO__;
R3.D3.Face.call( R3.D3.API.Face.Graphics.call(
this, this,
parent,
apiComponent, apiComponent,
linkedObjects
);
R3.D3.API.Face.call(
this,
apiComponent,
apiComponent.v0index,
apiComponent.v1index,
apiComponent.v2index,
apiComponent.materialIndex, apiComponent.materialIndex,
apiComponent.uvs, apiComponent.uvs,
apiComponent.color, apiComponent.color,
apiComponent.vertexColors, 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( this.uvs = this.uvs.reduce(
@ -93,13 +23,13 @@ R3.D3.Face.Graphics = function(
function(result, uvs, uvSet) { function(result, uvs, uvSet) {
result[uvSet] = uvs.reduce( result[uvSet] = uvs.reduce(
function(uvResult, uv) { function(uvResult, uv) {
uvResult.push( uvResult.push(
new R3.Vector2( new R3.Vector2(
this.implementation, this,
uv, uv
this
) )
); );
@ -115,10 +45,31 @@ R3.D3.Face.Graphics = function(
[] []
); );
this.normal = new R3.Vector3( this.color = new R3.Color(
this.implementation, this,
this.normal, this.color
this );
this.vertexColors = this.vertexColors.reduce(
function(result, vertexColor) {
result.push(
new R3.Color(
this,
vertexColor
)
);
return result;
}.bind(this),
[]
);
R3.D3.Face.call(
this,
apiComponent,
{}
); );
}; };
@ -126,107 +77,68 @@ R3.D3.Face.Graphics = function(
R3.D3.Face.Graphics.prototype = Object.create(R3.D3.Face.prototype); R3.D3.Face.Graphics.prototype = Object.create(R3.D3.Face.prototype);
R3.D3.Face.Graphics.prototype.constructor = R3.D3.Face.Graphics; R3.D3.Face.Graphics.prototype.constructor = R3.D3.Face.Graphics;
/** R3.D3.Face.Graphics.prototype.createInstance = function() {
* 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.instance = this.graphics.Face(
this.v0index, this.v0index,
this.v1index, this.v1index,
this.v2index this.v2index,
this.normal,
this.color,
this.materialIndex,
this.vertexColors
); );
if (this.normal) { R3.Component.prototype.createInstance.call(this);
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) { R3.D3.Face.Graphics.prototype.updateInstance = function(property) {
if (property === 'materialIndex') { if (property === 'materialIndex') {
this.instance.materialIndex = this.materialIndex; this.instance.materialIndex = this.materialIndex;
this.parentGeometry.instance.groupsNeedUpdate = true; this.parent.instance.groupsNeedUpdate = true;
return; return;
} }
if (property === 'uvs') { if (property === 'uvs') {
this.uvs[uvSet][uvIndex].instance.x = this.uvs[uvSet][uvIndex].x; this.uvs[uvSet][uvIndex].instance.x = this.uvs[uvSet][uvIndex].x;
this.uvs[uvSet][uvIndex].instance.y = this.uvs[uvSet][uvIndex].y; this.uvs[uvSet][uvIndex].instance.y = this.uvs[uvSet][uvIndex].y;
this.parentGeometry.instance.uvsNeedUpdate = true; this.parent.instance.uvsNeedUpdate = true;
return; return;
} }
console.warn('todo: update face property: ' + property); if (property === 'color') {
}; this.instance.color.r = this.color.r;
this.instance.color.g = this.color.g;
this.instance.color.b = this.color.b;
return;
}
R3.D3.Face.prototype.toApiObject = function() { if (property === 'vertexColors') {
this.instance.vertexColors = this.vertexColors.reduce(
return new R3.D3.API.Face( function(result, vertexColor) {
this.id, result.push(
this.name, this.graphics.Color(
this.v0index, vertexColor.r,
this.v1index, vertexColor.g,
this.v2index, vertexColor.b
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; return result;
}.bind(this), }.bind(this),
[] []
), );
this.color.toApiObject(), return;
this.vertexColors.map(function(vertexColor){ }
return vertexColor.toApiObject();
}), R3.D3.Face.prototype.updateInstance.call(this, property);
this.vertexNormals.map(function(vertexNormal){
return vertexNormal.toApiObject();
}),
this.normal.toApiObject(),
this.selected
);
}; };
R3.D3.Face.prototype.createHelper = function(mesh) { R3.D3.Face.Graphics.prototype.createHelper = function() {
console.warn('todo: createHelper needs work');
return;
this.backupProperties = { this.backupProperties = {
color : { color : {
@ -242,6 +154,7 @@ R3.D3.Face.prototype.createHelper = function(mesh) {
b: mesh.materials[this.materialIndex].emissive.b b: mesh.materials[this.materialIndex].emissive.b
} }
}, },
vertexColors : mesh.materials[this.materialIndex].vertexColors vertexColors : mesh.materials[this.materialIndex].vertexColors
}; };
@ -251,16 +164,6 @@ R3.D3.Face.prototype.createHelper = function(mesh) {
new THREE.Color(0,0,1) 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].vertexColors = R3.D3.API.Material.TYPE_VERTEX_COLORS;
mesh.materials[this.materialIndex].updateInstance('vertexColors'); mesh.materials[this.materialIndex].updateInstance('vertexColors');
@ -268,7 +171,10 @@ R3.D3.Face.prototype.createHelper = function(mesh) {
}; };
R3.D3.Face.prototype.removeHelper = function(mesh) { R3.D3.Face.Graphics.prototype.removeHelper = function() {
console.warn('todo: removeHelper needs work');
return;
this.instance.color.r = this.backupProperties.color.r; this.instance.color.r = this.backupProperties.color.r;
this.instance.color.g = this.backupProperties.color.g; this.instance.color.g = this.backupProperties.color.g;
@ -276,11 +182,6 @@ R3.D3.Face.prototype.removeHelper = function(mesh) {
mesh.instance.geometry.colorsNeedUpdate = true; 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].vertexColors = this.backupProperties.vertexColors;
mesh.materials[this.materialIndex].updateInstance('vertexColors'); mesh.materials[this.materialIndex].updateInstance('vertexColors');

View File

@ -1,28 +1,29 @@
/** /**
* R3.D3.Face * R3.D3.Face
* @param parent
* @param apiComponent * @param apiComponent
* @param linkedObjects * @param linkedObjects
* @constructor * @constructor
*/ */
R3.D3.Face = function( R3.D3.Face = function(
parent,
apiComponent, apiComponent,
linkedObjects linkedObjects
) { ) {
__RUNTIME_COMPONENT_MACRO__; if (R3.Utils.UndefinedOrNull(linkedObjects)) {
R3.D3.API.Face.call( __RUNTIME_COMPONENT_MACRO__;
this,
apiComponent, R3.D3.API.Face.call(
apiComponent.v0index, this,
apiComponent.v1index, apiComponent,
apiComponent.v2index, apiComponent.v0index,
apiComponent.vertexNormals, apiComponent.v1index,
apiComponent.normal, apiComponent.v2index,
apiComponent.selected apiComponent.vertexNormals,
); apiComponent.normal
);
}
this.componentRuntime = R3.Component.GetComponentRuntime(this.parent); this.componentRuntime = R3.Component.GetComponentRuntime(this.parent);
@ -31,7 +32,7 @@ R3.D3.Face = function(
result.push( result.push(
new R3.Vector3( new R3.Vector3(
parent, this,
vertexNormal vertexNormal
) )
); );
@ -42,13 +43,12 @@ R3.D3.Face = function(
); );
this.normal = new R3.Vector3( this.normal = new R3.Vector3(
parent, this,
this.normal this.normal
); );
R3.Component.call( R3.Component.call(
this, this,
parent,
linkedObjects linkedObjects
); );
@ -62,165 +62,90 @@ R3.D3.Face.prototype.constructor = R3.D3.Face;
* they don't call component createinstance * they don't call component createinstance
* @param parentGeometry * @param parentGeometry
*/ */
R3.D3.Face.prototype.createInstance = function(parentGeometry) { /**
*
*/
R3.D3.Face.prototype.createInstance = function() {
switch (this.componentRuntime) { switch (this.componentRuntime) {
case R3.Component.GRAPHICS_RUNTIME : case R3.Component.GRAPHICS_RUNTIME :
this.instance = this.graphics.Face(
this.v0index,
this.v1index,
this.v2index,
this.normal,
);
break; break;
case R3.Component.PHYSICS_RUNTIME : case R3.Component.PHYSICS_RUNTIME :
this.instance = this.physics.Face(
this.v0index,
this.v1index,
this.v2index,
this.normal,
);
break; break;
} }
R3.Component.prototype.createInstance.call(this);
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.prototype.updateInstance = function(property, uvSet, uvIndex) { R3.D3.Face.prototype.updateInstance = function(property) {
if (property === 'materialIndex') { if (property === 'v0index') {
this.instance.materialIndex = this.materialIndex; this.instance.a = this.v0index;
this.parentGeometry.instance.groupsNeedUpdate = true;
return; return;
} }
if (property === 'uvs') { if (property === 'v1index') {
this.instance.b = this.v1index;
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; return;
} }
console.warn('todo: update face property: ' + property); if (property === 'v2index') {
}; this.instance.c = this.v2index;
return;
}
R3.D3.Face.prototype.toApiObject = function() { if (property === 'vertexNormals') {
return new R3.D3.API.Face( this.instance.vertexNormals = this.vertexNormals.reduce(
this.id, function(result, vertexNormal) {
this.name,
this.v0index,
this.v1index,
this.v2index,
this.materialIndex,
this.uvs.reduce(
function(result, uvArray, index) {
result[index] = uvArray.reduce( result.push(
function(uvResult, uv) { new R3.Vector3(
this,
if (uv instanceof R3.Vector2) { vertexNormal
uvResult.push(uv.toApiObject()); )
} else {
console.warn('unknown uv type - cannot commit to API');
}
return uvResult;
}.bind(this),
[]
); );
return result; return result;
}.bind(this), }.bind(this),
[] []
), );
this.color.toApiObject(), return;
this.vertexColors.map(function(vertexColor){ }
return vertexColor.toApiObject();
}), if (property === 'normal') {
this.vertexNormals.map(function(vertexNormal){ this.instance.normal = new R3.Vector3(
return vertexNormal.toApiObject(); this,
}), this.normal
this.normal.toApiObject(), );
this.selected return;
); }
R3.Component.prototype.updateInstance.call(this, property);
}; };
R3.D3.Face.prototype.createHelper = function() {
R3.D3.Face.prototype.createHelper = function(mesh) { console.warn('todo: implement R3.D3.Face.prototype.createHelper()');
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) { R3.D3.Face.prototype.removeHelper = function() {
console.warn('todo: implement R3.D3.Face.prototype.removeHelper()');
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');
};

42
src/r3-d3-fog-exp.js Normal file
View File

@ -0,0 +1,42 @@
/**
* R3.D3.Fog.Exp
* @param apiComponent
* @constructor
*/
R3.D3.Fog.Exp = function(
apiComponent
) {
__RUNTIME_COMPONENT_MACRO__;
R3.D3.API.Fog.Exp.call(
this,
apiComponent,
apiComponent.density
);
R3.D3.Fog.call(this);
};
R3.D3.Fog.Exp.prototype = Object.create(R3.D3.Fog.prototype);
R3.D3.Fog.Exp.prototype.constructor = R3.D3.Fog.Exp;
R3.D3.Fog.Exp.prototype.createInstance = function() {
this.instance = this.graphics.FogExp(
this.color,
this.density
);
R3.Component.prototype.createInstance.call(this);
};
R3.D3.Fog.Exp.prototype.updateInstance = function(property) {
if (property === 'density') {
this.graphics.updateInstance(this, property);
return;
}
R3.D3.Fog.prototype.updateInstance.call(this, property);
};

47
src/r3-d3-fog-normal.js Normal file
View File

@ -0,0 +1,47 @@
/**
* R3.D3.Fog.Normal
* @param apiComponent
* @constructor
*/
R3.D3.Fog.Normal = function(
apiComponent
) {
__RUNTIME_COMPONENT_MACRO__;
R3.D3.API.Fog.Normal.call(
this,
apiComponent,
apiComponent.near,
apiComponent.far
);
R3.D3.Fog.call(this);
};
R3.D3.Fog.Normal.prototype = Object.create(R3.D3.Fog.prototype);
R3.D3.Fog.Normal.prototype.constructor = R3.D3.Fog.Normal;
R3.D3.Fog.Normal.prototype.createInstance = function() {
this.instance = this.graphics.Fog(
this.color,
this.near,
this.far
);
R3.Component.prototype.createInstance.call(this);
};
R3.D3.Fog.Normal.prototype.updateInstance = function(property) {
if (
property === 'near' ||
property === 'far'
) {
this.graphics.updateInstance(this, property);
return;
}
R3.D3.Fog.prototype.updateInstance.call(this, property);
};

View File

@ -1,37 +1,12 @@
/** /**
* Fog Superset - The apiFog properties get moved into the Fog object itself, and then the instance is * R3.D3.Fog
* created
* @param graphics
* @param apiFog R3.D3.API.Fog
* @constructor * @constructor
*/ */
R3.D3.Fog = function( R3.D3.Fog = function() {
graphics,
apiFog
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiFog)) {
apiFog = {};
}
R3.D3.API.Fog.call(
this,
apiFog.id,
apiFog.name,
apiFog.exponential,
apiFog.color,
apiFog.near,
apiFog.far,
apiFog.density,
apiFog.parent
);
this.color = new R3.Color( this.color = new R3.Color(
this.graphics, this,
this.color, this.color
this
); );
R3.Component.call(this); R3.Component.call(this);
@ -40,55 +15,14 @@ R3.D3.Fog = function(
R3.D3.Fog.prototype = Object.create(R3.Component.prototype); R3.D3.Fog.prototype = Object.create(R3.Component.prototype);
R3.D3.Fog.prototype.constructor = R3.D3.Fog; R3.D3.Fog.prototype.constructor = R3.D3.Fog;
/**
* Creates an instance scene
* @returns {THREE.Fog}
*/
R3.D3.Fog.prototype.createInstance = function() { R3.D3.Fog.prototype.createInstance = function() {
if (this.exponential) { console.warn('This class should not be instantiated directly');
this.instance = new THREE.FogExp2(
this.color.instance,
this.density
);
} else {
this.instance = new THREE.Fog(
this.color.instance,
this.near,
this.far
);
}
this.instance.name = this.name;
R3.Component.prototype.createInstance.call(this);
}; };
R3.D3.Fog.prototype.updateInstance = function(property) { R3.D3.Fog.prototype.updateInstance = function(property) {
if (property === 'exponential') {
if (
this.exponential &&
!(this.instance instanceof THREE.FogExp2)
) {
this.createInstance();
return;
}
if (
!this.exponential &&
!(this.instance instanceof THREE.Fog)
) {
this.createInstance();
return;
}
}
if (property === 'color') { if (property === 'color') {
this.color.instance.setRGB( this.color.instance.setRGB(
this.color.r, this.color.r,
@ -96,39 +30,8 @@ R3.D3.Fog.prototype.updateInstance = function(property) {
this.color.b this.color.b
); );
this.instance.color = this.color.instance; this.instance.color = this.color.instance;
} return;
if (property === 'near' || property === 'far') {
if (this.instance instanceof THREE.Fog) {
this.instance.near = this.near;
this.instance.far = this.far;
}
}
if (property === 'density') {
if (this.instance instanceof THREE.FogExp2) {
this.instance.density = this.density;
}
} }
R3.Component.prototype.updateInstance.call(this, property); R3.Component.prototype.updateInstance.call(this, property);
}; };
/**
* Converts a R3.D3.Fog to a R3.D3.API.Fog
* @returns {R3.D3.API.Fog}
*/
R3.D3.Fog.prototype.toApiObject = function() {
return new R3.D3.API.Fog(
this.id,
this.name,
this.exponential,
this.color.toApiObject(),
this.near,
this.far,
this.density,
R3.Utils.IdOrNull(this.parent)
);
};

View File

@ -1,97 +0,0 @@
/**
* Font Superset - The apiFont properties get moved into the Font object itself, and then the instance is created
* @param graphics R3.Runtime.Graphics
* @param apiFont R3.D3.API.Font
* @constructor
*/
R3.D3.Font = function(
graphics,
apiFont
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiFont)) {
apiFont = {};
}
R3.D3.API.Font.call(
this,
apiFont.id,
apiFont.name,
apiFont.url,
apiFont.parent
);
R3.Component.call(this);
};
R3.D3.Font.prototype = Object.create(R3.Component.prototype);
R3.D3.Font.prototype.constructor = R3.D3.Font;
/**
* Creates a light instance
* @returns {*}
*/
R3.D3.Font.prototype.createInstance = function() {
R3.Event.Emit(
R3.Event.LOAD_FONT,
{
font : this
},
function(fontInstance) {
this.instance = fontInstance;
console.log('font instance loaded');
R3.Component.prototype.createInstance.call(this);
}.bind(this),
function(error) {
console.error(error);
this.instance = null;
R3.Component.prototype.createInstance.call(this);
}.bind(this)
);
};
/**
* Updates the instance with the current state
*/
R3.D3.Font.prototype.updateInstance = function(property) {
if (property === 'url') {
this.createInstance();
}
R3.Component.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.D3.Font to a R3.D3.API.Font
* @returns {R3.D3.API.Font}
*/
R3.D3.Font.prototype.toApiObject = function() {
return new R3.D3.API.Font(
this.id,
this.name,
this.url,
R3.Utils.IdOrNull(this.parent)
);
};
/**
* Returns a new R3.D3.Font from a R3.D3.API.Font
* @param graphics R3.Runtime.Graphics
* @param objectFont R3.D3.API.Font
* @returns {R3.D3.Font}
*/
R3.D3.Font.FromObject = function(graphics, objectFont) {
return new R3.D3.Font(
graphics,
R3.D3.API.Font.FromObject(objectFont)
);
};

View File

@ -1,33 +1,24 @@
/** /**
* FrictionContactMaterial Runtime * R3.D3.FrictionContactMaterial
* @param physics R3.Runtime.Graphics * @param apiComponent
* @param apiFrictionContactMaterial R3.D3.API.FrictionContactMaterial
* @constructor * @constructor
*/ */
R3.D3.FrictionContactMaterial = function( R3.D3.FrictionContactMaterial = function(
physics, apiComponent
apiFrictionContactMaterial
) { ) {
this.physics = physics; __RUNTIME_COMPONENT_MACRO__;
this.physics.isNotCannonThrow();
if (R3.Utils.UndefinedOrNull(apiFrictionContactMaterial)) {
apiFrictionContactMaterial = {};
}
R3.D3.API.FrictionContactMaterial.call( R3.D3.API.FrictionContactMaterial.call(
this, this,
apiFrictionContactMaterial.id, apiComponent,
apiFrictionContactMaterial.name, apiComponent.materials,
apiFrictionContactMaterial.materials, apiComponent.friction,
apiFrictionContactMaterial.friction, apiComponent.restitution,
apiFrictionContactMaterial.restitution, apiComponent.contactEquationStiffness,
apiFrictionContactMaterial.contactEquationStiffness, apiComponent.contactEquationRelaxation,
apiFrictionContactMaterial.contactEquationRelaxation, apiComponent.frictionEquationStiffness,
apiFrictionContactMaterial.frictionEquationStiffness, apiComponent.frictionEquationRelaxation
apiFrictionContactMaterial.frictionEquationRelaxation,
apiFrictionContactMaterial.parent
); );
R3.Component.call( R3.Component.call(
@ -47,20 +38,11 @@ R3.D3.FrictionContactMaterial.prototype.constructor = R3.D3.FrictionContactMater
*/ */
R3.D3.FrictionContactMaterial.prototype.createInstance = function() { R3.D3.FrictionContactMaterial.prototype.createInstance = function() {
this.instance = new CANNON.ContactMaterial( this.instance = this.physics.ContactMaterial(
null, this.friction,
null, this.restitution,
{ this.contactEquationStiffness,
friction: this.friction, this.materials
restitution: this.restitution,
contactEquationStiffness: this.contactEquationStiffness
}
);
this.instance.materials = this.materials.map(
function(material){
return material.instance;
}
); );
R3.Component.prototype.createInstance.call(this); R3.Component.prototype.createInstance.call(this);
@ -69,61 +51,43 @@ R3.D3.FrictionContactMaterial.prototype.createInstance = function() {
/** /**
* *
*/ */
R3.D3.FrictionContactMaterial.prototype.updateInstance = function() { R3.D3.FrictionContactMaterial.prototype.updateInstance = function(property) {
this.instance.materials = this.materials.map( if (property === 'materials') {
function(material) { this.physics.updateInstance(this, property);
return material.instance; return;
} }
);
this.instance.friction = this.friction; if (property === 'friction') {
this.instance.restitution = this.restitution; this.physics.updateInstance(this, property);
this.instance.contactEquationStiffness = this.contactEquationStiffness; return;
this.instance.contactEquationRelaxation = this.contactEquationRelaxation; }
this.instance.frictionEquationStiffness = this.frictionEquationStiffness;
this.instance.frictionEquationRelaxation = this.frictionEquationRelaxation; if (property === 'restitution') {
this.physics.updateInstance(this, property);
return;
}
if (property === 'contactEquationStiffness') {
this.physics.updateInstance(this, property);
return;
}
if (property === 'contactEquationRelaxation') {
this.physics.updateInstance(this, property);
return;
}
if (property === 'frictionEquationStiffness') {
this.physics.updateInstance(this, property);
return;
}
if (property === 'frictionEquationRelaxation') {
this.physics.updateInstance(this, property);
return;
}
R3.Component.prototype.updateInstance(property);
}; };
/**
* R3.D3.FrictionContactMaterial to R3.D3.API.FrictionContactMaterial
* @returns {R3.D3.API.FrictionContactMaterial}
*/
R3.D3.FrictionContactMaterial.prototype.toApiObject = function() {
var apiFrictionContactMaterial = new R3.D3.API.FrictionContactMaterial(
this.id,
this.name,
this.materials.map(
function(material) {
return R3.Utils.IdOrNull(material);
}
),
this.friction,
this.restitution,
this.contactEquationStiffness,
this.contactEquationRelaxation,
this.frictionEquationStiffness,
this.frictionEquationRelaxation,
R3.Utils.IdOrNull(this.parent)
);
return apiFrictionContactMaterial;
};
/**
* R3.D3.FrictionContactMaterial from Object FrictionContactMaterial
* @param physics
* @param objectComponent
* @returns {R3.D3.FrictionContactMaterial}
* @constructor
*/
R3.D3.FrictionContactMaterial.FromObject = function(physics, objectComponent) {
var apiFrictionContactMaterial = R3.D3.API.FrictionContactMaterial.FromObject(objectComponent);
return new R3.D3.FrictionContactMaterial(
physics,
apiFrictionContactMaterial
);
};

View File

@ -1,28 +1,19 @@
/** /**
* FrictionMaterial Runtime * R3.D3.FrictionMaterial
* @param physics R3.Runtime.Graphics * @param apiComponent
* @param apiFrictionMaterial R3.D3.API.FrictionMaterial
* @constructor * @constructor
*/ */
R3.D3.FrictionMaterial = function( R3.D3.FrictionMaterial = function(
physics, apiComponent
apiFrictionMaterial
) { ) {
this.physics = physics; __RUNTIME_COMPONENT_MACRO__;
this.physics.isNotCannonThrow();
if (R3.Utils.UndefinedOrNull(apiFrictionMaterial)) {
apiFrictionMaterial = {};
}
R3.D3.API.FrictionMaterial.call( R3.D3.API.FrictionMaterial.call(
this, this,
apiFrictionMaterial.id, apiComponent,
apiFrictionMaterial.name, apiComponent.friction,
apiFrictionMaterial.friction, apiComponent.restitution
apiFrictionMaterial.restitution,
apiFrictionMaterial.parent
); );
R3.Component.call(this); R3.Component.call(this);
@ -36,55 +27,30 @@ R3.D3.FrictionMaterial.prototype.constructor = R3.D3.FrictionMaterial;
*/ */
R3.D3.FrictionMaterial.prototype.createInstance = function() { R3.D3.FrictionMaterial.prototype.createInstance = function() {
this.instance = new CANNON.Material( this.instance = this.physics.Material(
this.name this.name,
this.friction,
this.restitution
); );
this.instance.friction = this.friction;
this.instance.restitution = this.restitution;
R3.Component.prototype.createInstance.call(this); R3.Component.prototype.createInstance.call(this);
}; };
/** /**
* *
*/ */
R3.D3.FrictionMaterial.prototype.updateInstance = function() { R3.D3.FrictionMaterial.prototype.updateInstance = function(property) {
this.instance.friction = this.friction;
this.instance.restitution = this.restitution; if (property === 'friction') {
this.instance.name = this.name; this.physics.updateInstance(this, property);
}; return;
}
/**
* R3.D3.FrictionMaterial to R3.D3.API.FrictionMaterial if (property === 'restitution') {
* @returns {R3.D3.API.FrictionMaterial} this.physics.updateInstance(this, property);
*/ return;
R3.D3.FrictionMaterial.prototype.toApiObject = function() { }
var apiFrictionMaterial = new R3.D3.API.FrictionMaterial( R3.Component.prototype.updateInstance.call(this, property);
this.id,
this.name,
this.friction,
this.restitution,
R3.Utils.IdOrNull(this.parent)
);
return apiFrictionMaterial;
};
/**
* R3.D3.FrictionMaterial from Object FrictionMaterial
* @param physics
* @param objectComponent
* @returns {R3.D3.FrictionMaterial}
* @constructor
*/
R3.D3.FrictionMaterial.FromObject = function(physics, objectComponent) {
var apiFrictionMaterial = R3.D3.API.FrictionMaterial.FromObject(objectComponent);
return new R3.D3.FrictionMaterial(
physics,
apiFrictionMaterial
);
}; };

View File

@ -1,93 +1,69 @@
/** /**
* R3.D3.Geometry * R3.D3.Geometry
* @param graphics * @param apiComponent
* @param apiGeometry * @param linkedObjects
* @property geometryType
* @constructor * @constructor
*/ */
R3.D3.Geometry = function( R3.D3.Geometry = function(
graphics, apiComponent,
apiGeometry linkedObjects
) { ) {
this.graphics = graphics; if (R3.Utils.UndefinedOrNull(linkedObjects)) {
this.graphics.isNotThreeThrow();
if (R3.Utils.UndefinedOrNull(apiGeometry)) { __RUNTIME_COMPONENT_MACRO__;
apiGeometry = {
geometryType : R3.D3.API.Geometry.GEOMETRY_TYPE_NONE R3.D3.API.Geometry.call(
}; this,
apiComponent,
apiComponent.boundingBox,
apiComponent.boundingSphere,
apiComponent.faces,
apiComponent.vertices
);
linkedObjects = {};
} }
R3.D3.API.Geometry.call(
this,
apiGeometry.id,
apiGeometry.name,
apiGeometry.geometryType,
apiGeometry.parent,
apiGeometry.parentMesh,
apiGeometry.boundingBox,
apiGeometry.boundingSphere,
apiGeometry.faces,
apiGeometry.vertices
);
this.boundingBox = new R3.Box3( this.boundingBox = new R3.Box3(
this.graphics,
this.boundingBox this.boundingBox
); );
this.boundingSphere = new R3.Sphere( this.boundingSphere = new R3.Sphere(
this.graphics,
this.boundingSphere this.boundingSphere
); );
this.faces = this.faces.map( linkedObjects.boundingBox = R3.Box3;
function(face) { linkedObjects.boundingSphere = R3.Sphere;
return new R3.D3.Face(
this.graphics, this.faces = this.faces.reduce(
face function(result, face) {
) if (face instanceof R3.D3.API.Face) {
}.bind(this) result.push(R3.Component.ConstructFromObject(face));
} else {
result.push(face);
}
return result;
},
[]
); );
this.vertices = this.vertices.map( this.vertices = this.vertices.map(
function(vertex) { function(result, vertex) {
return new R3.D3.Vertex( if (vertex instanceof R3.D3.API.Vertex) {
this.graphics, result.push(R3.Component.ConstructFromObject(vertex));
vertex } else {
) result.push(vertex);
}.bind(this) }
return result;
},
[]
); );
var linkedObjects = {}; linkedObjects.boundingBox = R3.Box3;
linkedObjects.boundingSphere = R3.Sphere;
switch (this.geometryType) { linkedObjects.faces = [R3.D3.Face];
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES : linkedObjects.vertices = [R3.D3.Vertex];
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME :
linkedObjects.geometry = R3.D3.Geometry;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE :
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE :
linkedObjects.shapes = [R3.Curve.Path.D2.Shape];
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT :
linkedObjects.font = R3.D3.Font;
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE:
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE :
linkedObjects.shapes = [R3.Curve.Path.D2.Shape];
break;
case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT :
linkedObjects.font = R3.D3.Font;
break;
default :
break;
}
if (this instanceof R3.D3.Geometry.Buffer) {
linkedObjects.groups = [R3.Group];
}
R3.Component.call( R3.Component.call(
this, this,

View File

@ -46,7 +46,6 @@ R3.EntityManager = function(apiEntityManager) {
this.entityLoaded.bind(this) this.entityLoaded.bind(this)
); );
R3.Component.call( R3.Component.call(
this, this,
{ {

62
src/r3-font.js Normal file
View File

@ -0,0 +1,62 @@
/**
* R3.Font
* @param apiComponent
* @constructor
*/
R3.Font = function(
apiComponent
) {
__RUNTIME_COMPONENT_MACRO__;
R3.D3.API.Font.call(
this,
apiComponent,
apiComponent.path
);
R3.Component.call(this);
};
R3.Font.prototype = Object.create(R3.Component.prototype);
R3.Font.prototype.constructor = R3.Font;
/**
* Creates a light instance
* @returns {*}
*/
R3.Font.prototype.createInstance = function() {
R3.Event.Emit(
R3.Event.LOAD_FONT,
{
font : this
},
function(fontInstance) {
this.instance = fontInstance;
console.log('font instance loaded');
R3.Component.prototype.createInstance.call(this);
}.bind(this),
function(error) {
console.error(error);
this.instance = null;
R3.Component.prototype.createInstance.call(this);
}.bind(this)
);
};
/**
* Updates the instance with the current state
*/
R3.Font.prototype.updateInstance = function(property) {
if (property === 'path') {
this.createInstance();
}
R3.Component.prototype.updateInstance.call(this, property);
};

View File

@ -35,7 +35,7 @@ R3.Runtime.Graphics.Three.prototype.Vector4 = function(x,y,z,w) {
}; };
R3.Runtime.Graphics.Three.prototype.Color = function(r,g,b,a) { R3.Runtime.Graphics.Three.prototype.Color = function(r,g,b,a) {
return new THREE.Color(r,g,b,a); return new THREE.Color(r,g,b);
}; };
R3.Runtime.Graphics.Three.prototype.Matrix4 = function(rows) { R3.Runtime.Graphics.Three.prototype.Matrix4 = function(rows) {
@ -557,4 +557,101 @@ R3.Runtime.Graphics.Three.prototype.StereoEffect = function(
new THREE.StereoEffect( new THREE.StereoEffect(
renderer.instance renderer.instance
); );
};
R3.Runtime.Graphics.Three.prototype.Face = function(
v0index,
v1index,
v2index,
normal,
color,
materialIndex,
vertexColors
) {
var face = new THREE.Face3(
v0index,
v1index,
v2index
);
if (normal) {
face.normal = new THREE.Vector3(
normal.x,
normal.y,
normal.z
);
}
if (color) {
face.color = new THREE.Color(
color.r,
color.g,
color.b
)
}
if (materialIndex > -1) {
face.materialIndex = materialIndex;
}
vertexColors.map(
function(vertexColor, index) {
face.vertexColors[index] = new THREE.Color(vertexColor.r, vertexColor.g, vertexColor.b);
}
);
};
R3.Runtime.Graphics.Three.prototype.FogExp = function(
color,
density
) {
return new THREE.FogExp2(
this.color.toHex(),
this.density
);
};
R3.Runtime.Graphics.Three.prototype.Fog = function(
color,
near,
far
) {
return new THREE.Fog(
this.color.toHex(),
this.near,
this.far
);
};
/**
* R3.Runtime.Graphics.Three.prototype.updateInstance
* @param runtimeObject
* @param property
*/
R3.Runtime.Graphics.Three.prototype.updateInstance = function (runtimeObject, property) {
var instance = runtimeObject.instance;
if (R3.Utils.UndefinedOrNull(instance)) {
throw new Error('no instance available for update');
}
if (instance instanceof THREE.FogExp2) {
if (property === 'density') {
instance[property] = runtimeObject[property];
return;
}
}
if (instance instanceof THREE.Fog) {
if (
property === 'near' ||
property === 'far'
) {
instance[property] = runtimeObject[property];
return;
}
}
}; };

View File

@ -174,4 +174,36 @@ R3.Runtime.Graphics.prototype.StereoEffect = function(
renderer renderer
) { ) {
console.warn('override StereoEffect in child class'); console.warn('override StereoEffect in child class');
}; };
R3.Runtime.Graphics.prototype.Face = function(
v0index,
v1index,
v2index,
normal,
color,
materialIndex,
vertexColors
) {
console.warn('override Face in child class');
};
R3.Runtime.Graphics.prototype.FogExp = function(
color,
density
) {
console.warn('override R3.Runtime.Graphics.prototype.FogExp in child class');
};
R3.Runtime.Graphics.prototype.Fog = function(
color,
near,
far
) {
console.warn('override R3.Runtime.Graphics.prototype.Fog in child class');
};
R3.Runtime.Graphics.prototype.updateInstance = function (runtimeObject, property) {
console.warn('override R3.Runtime.Graphics.prototype.updateInstance in child class');
};

View File

@ -57,4 +57,88 @@ R3.Runtime.Physics.Cannon.prototype.Broadphase = function(broadphaseType) {
throw new Error('Unknown broadphase type'); throw new Error('Unknown broadphase type');
} }
};
R3.Runtime.Physics.Cannon.prototype.ContactMaterial = function(
friction,
restitution,
contactEquationStiffness,
materials,
) {
var instance = new CANNON.ContactMaterial(
null,
null,
{
friction: this.friction,
restitution: this.restitution,
contactEquationStiffness: this.contactEquationStiffness
}
);
instance.materials = this.materials.map(
function(material){
return material.instance;
}
);
return instance;
};
R3.Runtime.Physics.Cannon.prototype.Material = function(
name,
friction,
restitution
) {
var instance = new CANNON.Material(
name
);
instance.friction = friction;
instance.restitution = restitution;
return instance;
};
R3.Runtime.Physics.Cannon.prototype.updateInstance = function(runtimeObject, property) {
var instance = runtimeObject.instance;
if (R3.Utils.UndefinedOrNull(instance)) {
throw new Error('no instance available for update');
}
if (instance instanceof CANNON.ContactMaterial) {
if (
property === 'friction' ||
property === 'restitution' ||
property === 'contactEquationStiffness' ||
property === 'contactEquationRelaxation' ||
property === 'frictionEquationStiffness' ||
property === 'frictionEquationRelaxation'
) {
instance[property] = runtimeObject[property];
return;
}
if (property === 'materials') {
instance.materials = runtimeObject.materials.map(
function(material) {
return material.instance;
}
);
return
}
}
if (instance instanceof CANNON.Material) {
if (
property === 'friction' ||
property === 'restitution'
) {
instance[property] = runtimeObject[property];
return;
}
}
}; };

View File

@ -38,3 +38,24 @@ R3.Runtime.Physics.prototype.Quaternion = function(x,y,z,w) {
R3.Runtime.Physics.prototype.Broadphase = function(broadphaseType) { R3.Runtime.Physics.prototype.Broadphase = function(broadphaseType) {
console.log('override Quaternion in child class') console.log('override Quaternion in child class')
}; };
R3.Runtime.Physics.prototype.ContactMaterial = function(
friction,
restitution,
contactEquationStiffness,
materials,
) {
console.log('override R3.Runtime.Physics.prototype.ContactMaterial in child class');
};
R3.Runtime.Physics.prototype.Material = function(
name,
friction,
restitution
) {
console.log('override R3.Runtime.Physics.prototype.Material in child class')
};
R3.Runtime.Physics.prototype.updateInstance = function(runtimeObject, property) {
console.log('override R3.Runtime.Physics.prototype.updateInstance in child class');
};