diff --git a/gulpfile.js b/gulpfile.js index 70b3336..4381a62 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -16,7 +16,9 @@ code += '\tR3.API.Component.call(\n'; code += '\t\tthis,\n'; code += '\t\tthis.apiComponent.parent,\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)'; var code2 = 'if (R3.Utils.UndefinedOrNull(apiGeometryBuffer)) {\n'; diff --git a/src/r3-a-1-event.js b/src/r3-a-1-event.js index 3bb2bc9..0e9f96e 100644 --- a/src/r3-a-1-event.js +++ b/src/r3-a-1-event.js @@ -2,11 +2,7 @@ * Event Core * @constructor */ -R3.Event = function(parent) { - if (!parent) { - parent = null; - } - this.parent = parent; +R3.Event = function() { }; /** @@ -143,6 +139,7 @@ R3.Event.GET_WEBSOCKET_CONFIG = 0x79; R3.Event.GET_PROJECT = 0x7a; R3.Event.GET_APPLICATION_MODE = 0x80; R3.Event.RENDERER_SIZE_CHANGE = 0x81; +R3.Event.GET_REGISTER_FACES = 0x82; /** * Returns string name of event ID @@ -277,6 +274,7 @@ R3.Event.GetEventName = function(number) { case 0x7a : return 'get_project'; case 0x80 : return 'get_application_mode'; case 0x81 : return 'renderer_size_change'; + case 0x82 : return 'get_register_faces'; break; } diff --git a/src/r3-a-3-api-component.js b/src/r3-a-3-api-component.js index d547418..e537a6b 100644 --- a/src/r3-a-3-api-component.js +++ b/src/r3-a-3-api-component.js @@ -3,12 +3,16 @@ * @param parent * @param id * @param name + * @param register + * @param selected * @constructor */ R3.API.Component = function( parent, id, - name + name, + register, + selected ) { if (R3.Utils.UndefinedOrNull(parent)) { @@ -27,6 +31,16 @@ R3.API.Component = function( name = R3.Component.GetComponentFriendlyName(this.componentType) + ' (' + this.id + ')'; } 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; diff --git a/src/r3-a-4-component.js b/src/r3-a-4-component.js index 7a423de..fc99e30 100644 --- a/src/r3-a-4-component.js +++ b/src/r3-a-4-component.js @@ -1,17 +1,11 @@ /** * R3.Component is an R3.Event - * @param parent * @param linkedObjects * @constructor */ R3.Component = function( - parent, linkedObjects ) { - if (R3.Utils.UndefinedOrNull(parent)) { - parent = null; - } - this.parent = parent; if (R3.Utils.UndefinedOrNull(linkedObjects)) { linkedObjects = {}; @@ -21,17 +15,12 @@ R3.Component = function( /** * Call the Event constructor first so we can set the parent right away */ - R3.Event.call( - this, - this.parent - ); + R3.Event.call(this); this.componentType = this.getComponentType(); this.idToObject = {}; - this.selected = false; - this.building = false; this.loaded = false; @@ -46,12 +35,14 @@ R3.Component = function( this.dependencies = this.getDependencies(); - this.emit( - R3.Event.COMPONENT_REGISTER, - { - component : this - } - ); + if (this.register) { + this.emit( + R3.Event.COMPONENT_REGISTER, + { + component : this + } + ); + } if (this.dependencies.length === 0) { diff --git a/src/r3-api-box3.js b/src/r3-api-box3.js index 2509dee..d067fec 100644 --- a/src/r3-api-box3.js +++ b/src/r3-api-box3.js @@ -10,17 +10,7 @@ R3.API.Box3 = function( min, max ) { - if (R3.Utils.UndefinedOrNull(apiComponent)) { - apiComponent = {}; - } - this.apiComponent = apiComponent; - - R3.API.Component.call( - this, - this.apiComponent.parent, - this.apiComponent.id, - this.apiComponent.name - ); + __API_COMPONENT_MACRO__; if (R3.Utils.UndefinedOrNull(min)) { min = new R3.API.Vector3(); diff --git a/src/r3-api-canvas.js b/src/r3-api-canvas.js index 4fcc67f..af4c665 100644 --- a/src/r3-api-canvas.js +++ b/src/r3-api-canvas.js @@ -21,17 +21,7 @@ R3.API.Canvas = function( textBaseline ) { - if (R3.Utils.UndefinedOrNull(apiComponent)) { - apiComponent = {}; - } - this.apiComponent = apiComponent; - - R3.API.Component.call( - this, - this.apiComponent.parent, - this.apiComponent.id, - this.apiComponent.name - ); + __API_COMPONENT_MACRO__; if (R3.Utils.UndefinedOrNull(autoUpdateSize)) { autoUpdateSize = true; diff --git a/src/r3-api-controls-0.js b/src/r3-api-controls-0.js index 063a1b5..73584ed 100644 --- a/src/r3-api-controls-0.js +++ b/src/r3-api-controls-0.js @@ -16,7 +16,7 @@ R3.API.Controls = function( * Try to attach the controls to the parent canvas * @type {null} */ - canvas = this.getParent('canvas'); + canvas = this.getFirstParent(R3.API.Canvas); } this.canvas = canvas; }; diff --git a/src/r3-api-controls-d3.js b/src/r3-api-controls-d3.js index 6904f47..dc27798 100644 --- a/src/r3-api-controls-d3.js +++ b/src/r3-api-controls-d3.js @@ -18,15 +18,8 @@ R3.API.Controls.D3 = function( ); if (R3.Utils.UndefinedOrNull(camera)) { - /** - * Get the cameraIndexEdit of the scene which is responsible for these controls - */ - var cameraIndex = this.getParent('cameraIndexEdit'); - - /** - * Now get the camera with this index from our project cameras - */ - camera = this.getParent('cameras', cameraIndex); + var project = this.getFirstParent(R3.API.Project); + camera = project.cameras[R3.API.Project.CAMERA_INDEX_EDIT]; } this.camera = camera; }; diff --git a/src/r3-d3-api-font.js b/src/r3-api-font.js similarity index 62% rename from src/r3-d3-api-font.js rename to src/r3-api-font.js index f10a36e..00dce5f 100644 --- a/src/r3-d3-api-font.js +++ b/src/r3-api-font.js @@ -4,7 +4,7 @@ * @param path - Relative to API URL * @constructor */ -R3.D3.API.Font = function( +R3.API.Font = function( apiComponent, path ) { @@ -18,5 +18,5 @@ R3.D3.API.Font = function( }; -R3.D3.API.Font.prototype = Object.create(R3.API.Component.prototype); -R3.D3.API.Font.prototype.constructor = R3.D3.API.Font; +R3.API.Font.prototype = Object.create(R3.API.Component.prototype); +R3.API.Font.prototype.constructor = R3.API.Font; diff --git a/src/r3-box3.js b/src/r3-box3.js index 5651f1f..68d7554 100644 --- a/src/r3-box3.js +++ b/src/r3-box3.js @@ -1,11 +1,9 @@ /** * R3.Box3 - * @param parent * @param apiComponent * @constructor */ R3.Box3 = function( - parent, apiComponent ) { @@ -30,10 +28,7 @@ R3.Box3 = function( this.componentRuntime = R3.Component.GetComponentRuntime(this.parent); - R3.Component.call( - this, - parent - ); + R3.Component.call(this); }; R3.Box3.prototype = Object.create(R3.Component.prototype); diff --git a/src/r3-canvas.js b/src/r3-canvas.js index 692492f..3d66b44 100644 --- a/src/r3-canvas.js +++ b/src/r3-canvas.js @@ -32,7 +32,6 @@ R3.Canvas = function( R3.Component.call( this, - parent, { 'texts' : [R3.D3.Text] } diff --git a/src/r3-curve-a.js b/src/r3-curve-a.js index f1df359..89ceffc 100644 --- a/src/r3-curve-a.js +++ b/src/r3-curve-a.js @@ -26,11 +26,6 @@ R3.Curve = function( apiComponent.arcLenghDivisions ); - R3.Component.call( - this, - parent - ); - } else { /** @@ -38,15 +33,13 @@ R3.Curve = function( * Add any more linking information to the linkedObjects object here */ - R3.Component.call( - this, - parent, - linkedObjects - ); - } - + R3.Component.call( + this, + parent, + linkedObjects + ); }; diff --git a/src/r3-d3-api-face-graphics.js b/src/r3-d3-api-face-graphics.js index 393a237..f25edcb 100644 --- a/src/r3-d3-api-face-graphics.js +++ b/src/r3-d3-api-face-graphics.js @@ -22,25 +22,9 @@ R3.D3.API.Face.Graphics = function( apiFace.v1index, apiFace.v2index, apiFace.vertexNormals, - apiFace.normal, - apiFace.selected + apiFace.normal ); - 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; } @@ -65,46 +49,26 @@ R3.D3.API.Face.Graphics = function( } 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 = Object.create(R3.D3.API.Face.prototype); R3.D3.API.Face.Graphics.prototype.constructor = R3.D3.API.Face.Graphics; /** - * Clone a Face - * @returns {R3.D3.API.Face} + * Clone + * @returns {R3.D3.API.Face.Graphics} */ R3.D3.API.Face.Graphics.prototype.clone = function(){ - return new R3.D3.API.Face( - null, - this.v0index, - this.v1index, - this.v2index, + + var apiFace = R3.D3.API.Face.prototype.clone.call( + this + ); + + return new R3.D3.API.Face.Graphics( + apiFace, this.materialIndex, this.uvs, this.color, - this.vertexColors, - this.vertexNormals, - this.normal, - this.selected + this.vertexColors ); }; diff --git a/src/r3-d3-api-face.js b/src/r3-d3-api-face.js index 5b75048..02542f8 100644 --- a/src/r3-d3-api-face.js +++ b/src/r3-d3-api-face.js @@ -6,7 +6,6 @@ * @param v2index * @param vertexNormals * @param normal - * @param selected * @constructor */ R3.D3.API.Face = function( @@ -15,10 +14,32 @@ R3.D3.API.Face = function( v1index, v2index, vertexNormals, - normal, - selected + normal ) { + /** + * 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__; if (R3.Utils.UndefinedOrNull(v0index)) { @@ -46,17 +67,8 @@ R3.D3.API.Face = function( } 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.constructor = R3.D3.API.Face; @@ -71,8 +83,7 @@ R3.D3.API.Face.prototype.clone = function(){ this.v1index, this.v2index, this.vertexNormals, - this.normal, - this.selected + this.normal ); }; diff --git a/src/r3-d3-api-fog-exp.js b/src/r3-d3-api-fog-exp.js new file mode 100644 index 0000000..b751d31 --- /dev/null +++ b/src/r3-d3-api-fog-exp.js @@ -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; diff --git a/src/r3-d3-api-fog-normal.js b/src/r3-d3-api-fog-normal.js new file mode 100644 index 0000000..67fc375 --- /dev/null +++ b/src/r3-d3-api-fog-normal.js @@ -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; diff --git a/src/r3-d3-api-fog.js b/src/r3-d3-api-fog.js index ea8189a..c01faa4 100644 --- a/src/r3-d3-api-fog.js +++ b/src/r3-d3-api-fog.js @@ -1,49 +1,21 @@ /** * R3.D3.API.Fog * @param apiComponent - * @param exponential * @param color - * @param near - * @param far - * @param density * @constructor */ R3.D3.API.Fog = function( apiComponent, - exponential, - color, - near, - far, - density + color ) { __API_COMPONENT_MACRO__; - if (R3.Utils.UndefinedOrNull(exponential)) { - exponential = false; - } - this.exponential = exponential; - if (R3.Utils.UndefinedOrNull(color)) { color = new R3.API.Color(this, 1, 1, 1, 1) } 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); diff --git a/src/r3-d3-api-geometry-a.js b/src/r3-d3-api-geometry-a.js index d3a52b3..6340f76 100644 --- a/src/r3-d3-api-geometry-a.js +++ b/src/r3-d3-api-geometry-a.js @@ -18,22 +18,41 @@ R3.D3.API.Geometry = function( __API_COMPONENT_MACRO__; if (R3.Utils.UndefinedOrNull(boundingBox)) { - boundingBox = new R3.API.Box3(); + boundingBox = new R3.API.Box3( + { + parent : this + } + ); } this.boundingBox = boundingBox; if (R3.Utils.UndefinedOrNull(boundingSphere)) { - boundingSphere = new R3.API.Sphere(); + boundingSphere = new R3.API.Sphere( + { + parent : this + } + ); } this.boundingSphere = boundingSphere; if (R3.Utils.UndefinedOrNull(faces)) { - faces = []; + faces = [ + new R3.D3.API.Face( + { + parent : this + }, + 0, + 1, + 2 + ) + ]; } this.faces = faces; if (R3.Utils.UndefinedOrNull(vertices)) { - vertices = []; + vertices = [ + new R3.API.Vector3() + ]; } this.vertices = vertices; }; diff --git a/src/r3-d3-api-material-a.js b/src/r3-d3-api-material-a.js index 46b0a90..7ec9795 100644 --- a/src/r3-d3-api-material-a.js +++ b/src/r3-d3-api-material-a.js @@ -1,9 +1,6 @@ /** * R3.D3.API.Material - * @param id - * @param name - * @param materialType - * @param parent + * @param apiComponent * @param parentMeshes * @param alphaTest * @param blendDst diff --git a/src/r3-d3-api-y-object.js b/src/r3-d3-api-y-object.js index 11fdaf3..4e2a097 100644 --- a/src/r3-d3-api-y-object.js +++ b/src/r3-d3-api-y-object.js @@ -4,12 +4,10 @@ * - 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 * - * @param parent * @param linkedObjects * @constructor */ R3.D3.Object = function( - parent, linkedObjects ) { diff --git a/src/r3-d3-api-z-animation.js b/src/r3-d3-api-z-animation.js index 5bded54..b9545ab 100644 --- a/src/r3-d3-api-z-animation.js +++ b/src/r3-d3-api-z-animation.js @@ -1,11 +1,9 @@ /** * R3.D3.Animation - * @param parent * @param apiComponent * @constructor */ R3.D3.Animation = function( - parent, apiComponent ) { diff --git a/src/r3-d3-audio.js b/src/r3-d3-audio.js index f0d79c2..3c0232d 100644 --- a/src/r3-d3-audio.js +++ b/src/r3-d3-audio.js @@ -1,11 +1,9 @@ /** * R3.D3.Audio - * @param parent * @param apiComponent * @constructor */ R3.D3.Audio = function( - parent, apiComponent ) { diff --git a/src/r3-d3-bone-weight.js b/src/r3-d3-bone-weight.js index a94b5c0..ba3ee0b 100644 --- a/src/r3-d3-bone-weight.js +++ b/src/r3-d3-bone-weight.js @@ -1,11 +1,9 @@ /** * R3.D3.BoneWeight - * @param parent * @param apiComponent * @constructor */ R3.D3.BoneWeight = function( - parent, apiComponent ) { @@ -19,8 +17,7 @@ R3.D3.BoneWeight = function( ); R3.Component.call( - this, - parent + this ); }; diff --git a/src/r3-d3-bone.js b/src/r3-d3-bone.js index c906708..b56d612 100644 --- a/src/r3-d3-bone.js +++ b/src/r3-d3-bone.js @@ -1,11 +1,9 @@ /** * R3.D3.Bone - * @param parent * @param apiComponent * @constructor */ R3.D3.Bone = function( - parent, apiComponent ) { @@ -19,8 +17,7 @@ R3.D3.Bone = function( ); R3.D3.Object.call( - this, - parent + this ); }; diff --git a/src/r3-d3-broadphase.js b/src/r3-d3-broadphase.js index b2aa271..83877aa 100644 --- a/src/r3-d3-broadphase.js +++ b/src/r3-d3-broadphase.js @@ -1,11 +1,9 @@ /** * R3.D3.Broadphase - * @param parent * @param apiComponent * @constructor */ R3.D3.Broadphase = function( - parent, apiComponent ) { @@ -18,8 +16,7 @@ R3.D3.Broadphase = function( ); R3.Component.call( - this, - parent + this ); }; diff --git a/src/r3-d3-camera-a.js b/src/r3-d3-camera-a.js index 836bb4e..5ac9df6 100644 --- a/src/r3-d3-camera-a.js +++ b/src/r3-d3-camera-a.js @@ -3,18 +3,15 @@ * * - This class cannot be instantiated - simply pass it all through to R3.D3.Object * - * @param parent * @param linkedObjects * @constructor */ R3.D3.Camera = function( - parent, linkedObjects ) { R3.D3.Object.call( this, - parent, linkedObjects ); diff --git a/src/r3-d3-camera-cube.js b/src/r3-d3-camera-cube.js index 1a482ea..1087bf3 100644 --- a/src/r3-d3-camera-cube.js +++ b/src/r3-d3-camera-cube.js @@ -1,11 +1,9 @@ /** * R3.D3.Camera.Cube - * @param parent * @param apiComponent * @constructor */ R3.D3.Camera.Cube = function( - parent, apiComponent ) { @@ -30,7 +28,6 @@ R3.D3.Camera.Cube = function( R3.D3.Camera.call( this, - parent, linkedObjects ); diff --git a/src/r3-d3-camera-orthographic-fixed-aspect.js b/src/r3-d3-camera-orthographic-fixed-aspect.js index b8072cd..8cd376a 100644 --- a/src/r3-d3-camera-orthographic-fixed-aspect.js +++ b/src/r3-d3-camera-orthographic-fixed-aspect.js @@ -1,11 +1,9 @@ /** * R3.D3.Camera.Orthographic.FixedAspect - * @param parent * @param apiComponent * @constructor */ R3.D3.Camera.Orthographic.FixedAspect = function( - parent, apiComponent ) { @@ -20,7 +18,6 @@ R3.D3.Camera.Orthographic.FixedAspect = function( R3.D3.Camera.Orthographic.call( this, - parent, linkedObjects ); diff --git a/src/r3-d3-camera-orthographic-scaled-aspect.js b/src/r3-d3-camera-orthographic-scaled-aspect.js index 46ad19b..6aef339 100644 --- a/src/r3-d3-camera-orthographic-scaled-aspect.js +++ b/src/r3-d3-camera-orthographic-scaled-aspect.js @@ -1,11 +1,9 @@ /** * R3.D3.Camera.Orthographic.ScaledAspect - * @param parent * @param apiComponent * @constructor */ R3.D3.Camera.Orthographic.ScaledAspect = function( - parent, apiComponent ) { @@ -24,7 +22,6 @@ R3.D3.Camera.Orthographic.ScaledAspect = function( R3.D3.Camera.Orthographic.call( this, - parent, linkedObjects ); diff --git a/src/r3-d3-camera-orthographic.js b/src/r3-d3-camera-orthographic.js index 0436752..c9912c8 100644 --- a/src/r3-d3-camera-orthographic.js +++ b/src/r3-d3-camera-orthographic.js @@ -3,18 +3,15 @@ * * - This is an abstract class - should not be instantiated directly * - * @param parent * @param linkedObjects * @constructor */ R3.D3.Camera.Orthographic = function( - parent, linkedObjects ) { R3.D3.Camera.call( this, - parent, linkedObjects ); diff --git a/src/r3-d3-camera-perspective-stereo.js b/src/r3-d3-camera-perspective-stereo.js index 909f29c..ca450ff 100644 --- a/src/r3-d3-camera-perspective-stereo.js +++ b/src/r3-d3-camera-perspective-stereo.js @@ -1,11 +1,9 @@ /** * R3.D3.Camera.Perspective.Stereo - * @param parent * @param apiComponent * @constructor */ R3.D3.Camera.Perspective.Stereo = function( - parent, apiComponent ) { @@ -21,7 +19,6 @@ R3.D3.Camera.Perspective.Stereo = function( R3.D3.Camera.call( this, - parent, linkedObjects ); diff --git a/src/r3-d3-camera-perspective.js b/src/r3-d3-camera-perspective.js index 00a10b9..6a0a47d 100644 --- a/src/r3-d3-camera-perspective.js +++ b/src/r3-d3-camera-perspective.js @@ -1,11 +1,9 @@ /** * R3.D3.Camera.Perspective - * @param parent * @param apiComponent * @constructor */ R3.D3.Camera.Perspective = function( - parent, apiComponent ) { @@ -27,7 +25,6 @@ R3.D3.Camera.Perspective = function( R3.D3.Camera.call( this, - parent, linkedObjects ); diff --git a/src/r3-d3-composer-render-target.js b/src/r3-d3-composer-render-target.js index d95f4ff..2ca47dd 100644 --- a/src/r3-d3-composer-render-target.js +++ b/src/r3-d3-composer-render-target.js @@ -1,11 +1,9 @@ /** * R3.D3.Composer.RenderTarget - * @param parent * @param apiComponent * @constructor */ R3.D3.Composer.RenderTarget = function( - parent, apiComponent ) { @@ -27,7 +25,6 @@ R3.D3.Composer.RenderTarget = function( R3.D3.Composer.call( this, - parent, linkedObjects ); }; diff --git a/src/r3-d3-composer-renderer.js b/src/r3-d3-composer-renderer.js index 8ad6910..9dba2b2 100644 --- a/src/r3-d3-composer-renderer.js +++ b/src/r3-d3-composer-renderer.js @@ -1,11 +1,9 @@ /** * R3.D3.Composer.Renderer - * @param parent * @param apiComponent * @constructor */ R3.D3.Composer.Renderer = function( - parent, apiComponent ) { @@ -27,7 +25,6 @@ R3.D3.Composer.Renderer = function( R3.D3.Composer.call( this, - parent, linkedObjects ); }; diff --git a/src/r3-d3-composer.js b/src/r3-d3-composer.js index 5f96bb5..2b54be4 100644 --- a/src/r3-d3-composer.js +++ b/src/r3-d3-composer.js @@ -3,12 +3,10 @@ * * - This is an abstract class, don't instatiate it directly * - * @param parent * @param linkedObjects * @constructor */ R3.D3.Composer = function( - parent, linkedObjects ) { @@ -34,7 +32,6 @@ R3.D3.Composer = function( R3.Component.call( this, - parent, linkedObjects ); }; diff --git a/src/r3-d3-effect-a.js b/src/r3-d3-effect-a.js index fca936d..363e300 100644 --- a/src/r3-d3-effect-a.js +++ b/src/r3-d3-effect-a.js @@ -1,11 +1,9 @@ /** * R3.D3.Effect - * @param parent * @param linkedObjects * @constructor */ R3.D3.Effect = function( - parent, linkedObjects ) { @@ -34,7 +32,6 @@ R3.D3.Effect = function( R3.Component.call( this, - parent, linkedObjects ); }; diff --git a/src/r3-d3-effect-anaglyph.js b/src/r3-d3-effect-anaglyph.js index f940d17..4742f8d 100644 --- a/src/r3-d3-effect-anaglyph.js +++ b/src/r3-d3-effect-anaglyph.js @@ -1,11 +1,9 @@ /** * R3.D3.Effect.Anaglyph - * @param parent * @param apiComponent * @constructor */ R3.D3.Effect.Anaglyph = function( - parent, apiComponent ) { @@ -17,8 +15,7 @@ R3.D3.Effect.Anaglyph = function( ); R3.D3.Effect.call( - this, - parent + this ); }; diff --git a/src/r3-d3-effect-parallax.js b/src/r3-d3-effect-parallax.js index 7df3784..2d93e71 100644 --- a/src/r3-d3-effect-parallax.js +++ b/src/r3-d3-effect-parallax.js @@ -1,11 +1,9 @@ /** * R3.D3.Effect.Parallax - * @param parent * @param apiComponent * @constructor */ R3.D3.Effect.Parallax = function( - parent, apiComponent ) { @@ -17,8 +15,7 @@ R3.D3.Effect.Parallax = function( ); R3.D3.Effect.call( - this, - parent + this ); }; diff --git a/src/r3-d3-effect-stereo.js b/src/r3-d3-effect-stereo.js index 6893bd0..55af470 100644 --- a/src/r3-d3-effect-stereo.js +++ b/src/r3-d3-effect-stereo.js @@ -1,11 +1,9 @@ /** * R3.D3.Effect.Stereo - * @param parent * @param apiComponent * @constructor */ R3.D3.Effect.Stereo = function( - parent, apiComponent ) { @@ -17,8 +15,7 @@ R3.D3.Effect.Stereo = function( ); R3.D3.Effect.call( - this, - parent + this ); }; diff --git a/src/r3-d3-face-graphics.js b/src/r3-d3-face-graphics.js index f21a926..a179c5b 100644 --- a/src/r3-d3-face-graphics.js +++ b/src/r3-d3-face-graphics.js @@ -1,91 +1,21 @@ /** - * R3.D3.Face - * @param parent + * R3.D3.Face.Graphics * @param apiComponent * @constructor */ R3.D3.Face.Graphics = function( - parent, apiComponent ) { __RUNTIME_COMPONENT_MACRO__; - R3.D3.Face.call( + R3.D3.API.Face.Graphics.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) + apiComponent.vertexColors ); this.uvs = this.uvs.reduce( @@ -93,13 +23,13 @@ R3.D3.Face.Graphics = function( function(result, uvs, uvSet) { result[uvSet] = uvs.reduce( + function(uvResult, uv) { uvResult.push( new R3.Vector2( - this.implementation, - uv, - this + this, + uv ) ); @@ -115,10 +45,31 @@ R3.D3.Face.Graphics = function( [] ); - this.normal = new R3.Vector3( - this.implementation, - this.normal, - this + this.color = new R3.Color( + this, + this.color + ); + + 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.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) { +R3.D3.Face.Graphics.prototype.createInstance = function() { - this.instance = new THREE.Face3( + this.instance = this.graphics.Face( this.v0index, this.v1index, - this.v2index + this.v2index, + this.normal, + this.color, + this.materialIndex, + this.vertexColors ); - 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.Component.prototype.createInstance.call(this); }; -R3.D3.Face.Graphics.prototype.updateInstance = function(property, uvSet, uvIndex) { +R3.D3.Face.Graphics.prototype.updateInstance = function(property) { if (property === 'materialIndex') { this.instance.materialIndex = this.materialIndex; - this.parentGeometry.instance.groupsNeedUpdate = true; + this.parent.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; + this.parent.instance.uvsNeedUpdate = true; 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() { - - 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), - [] + if (property === 'vertexColors') { + this.instance.vertexColors = this.vertexColors.reduce( + function(result, vertexColor) { + result.push( + this.graphics.Color( + vertexColor.r, + vertexColor.g, + vertexColor.b + ) ); - 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 - ); + ); + return; + } + + R3.D3.Face.prototype.updateInstance.call(this, property); }; -R3.D3.Face.prototype.createHelper = function(mesh) { +R3.D3.Face.Graphics.prototype.createHelper = function() { + + console.warn('todo: createHelper needs work'); + return; this.backupProperties = { color : { @@ -242,6 +154,7 @@ R3.D3.Face.prototype.createHelper = function(mesh) { b: mesh.materials[this.materialIndex].emissive.b } }, + vertexColors : mesh.materials[this.materialIndex].vertexColors }; @@ -251,16 +164,6 @@ R3.D3.Face.prototype.createHelper = function(mesh) { 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'); @@ -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.g = this.backupProperties.color.g; @@ -276,11 +182,6 @@ R3.D3.Face.prototype.removeHelper = function(mesh) { 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'); diff --git a/src/r3-d3-face.js b/src/r3-d3-face.js index 9682b72..f220bde 100644 --- a/src/r3-d3-face.js +++ b/src/r3-d3-face.js @@ -1,28 +1,29 @@ /** * R3.D3.Face - * @param parent * @param apiComponent * @param linkedObjects * @constructor */ R3.D3.Face = function( - parent, apiComponent, linkedObjects ) { - __RUNTIME_COMPONENT_MACRO__; + if (R3.Utils.UndefinedOrNull(linkedObjects)) { - R3.D3.API.Face.call( - this, - apiComponent, - apiComponent.v0index, - apiComponent.v1index, - apiComponent.v2index, - apiComponent.vertexNormals, - apiComponent.normal, - apiComponent.selected - ); + __RUNTIME_COMPONENT_MACRO__; + + R3.D3.API.Face.call( + this, + apiComponent, + apiComponent.v0index, + apiComponent.v1index, + apiComponent.v2index, + apiComponent.vertexNormals, + apiComponent.normal + ); + + } this.componentRuntime = R3.Component.GetComponentRuntime(this.parent); @@ -31,7 +32,7 @@ R3.D3.Face = function( result.push( new R3.Vector3( - parent, + this, vertexNormal ) ); @@ -42,13 +43,12 @@ R3.D3.Face = function( ); this.normal = new R3.Vector3( - parent, + this, this.normal ); R3.Component.call( this, - parent, linkedObjects ); @@ -62,165 +62,90 @@ R3.D3.Face.prototype.constructor = R3.D3.Face; * they don't call component createinstance * @param parentGeometry */ -R3.D3.Face.prototype.createInstance = function(parentGeometry) { +/** + * + */ +R3.D3.Face.prototype.createInstance = function() { switch (this.componentRuntime) { case R3.Component.GRAPHICS_RUNTIME : + + this.instance = this.graphics.Face( + this.v0index, + this.v1index, + this.v2index, + this.normal, + ); + break; + case R3.Component.PHYSICS_RUNTIME : + + this.instance = this.physics.Face( + this.v0index, + this.v1index, + this.v2index, + this.normal, + ); + 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') { - this.instance.materialIndex = this.materialIndex; - this.parentGeometry.instance.groupsNeedUpdate = true; + if (property === 'v0index') { + this.instance.a = this.v0index; 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; + if (property === 'v1index') { + this.instance.b = this.v1index; 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.id, - this.name, - this.v0index, - this.v1index, - this.v2index, - this.materialIndex, - this.uvs.reduce( - function(result, uvArray, index) { + this.instance.vertexNormals = this.vertexNormals.reduce( + function(result, vertexNormal) { - 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), - [] + result.push( + new R3.Vector3( + this, + vertexNormal + ) ); 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 - ); + ); + return; + } + + if (property === 'normal') { + this.instance.normal = new R3.Vector3( + this, + this.normal + ); + return; + } + + R3.Component.prototype.updateInstance.call(this, property); }; - -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.createHelper = function() { + console.warn('todo: implement R3.D3.Face.prototype.createHelper()'); }; -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'); - -}; \ No newline at end of file +R3.D3.Face.prototype.removeHelper = function() { + console.warn('todo: implement R3.D3.Face.prototype.removeHelper()'); +}; diff --git a/src/r3-d3-fog-exp.js b/src/r3-d3-fog-exp.js new file mode 100644 index 0000000..e6d35c6 --- /dev/null +++ b/src/r3-d3-fog-exp.js @@ -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); +}; diff --git a/src/r3-d3-fog-normal.js b/src/r3-d3-fog-normal.js new file mode 100644 index 0000000..bf4fab3 --- /dev/null +++ b/src/r3-d3-fog-normal.js @@ -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); +}; diff --git a/src/r3-d3-fog.js b/src/r3-d3-fog.js index 6146657..8d15b76 100644 --- a/src/r3-d3-fog.js +++ b/src/r3-d3-fog.js @@ -1,37 +1,12 @@ /** - * Fog Superset - The apiFog properties get moved into the Fog object itself, and then the instance is - * created - * @param graphics - * @param apiFog R3.D3.API.Fog + * R3.D3.Fog * @constructor */ -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 - ); +R3.D3.Fog = function() { this.color = new R3.Color( - this.graphics, - this.color, - this + this, + this.color ); 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.constructor = R3.D3.Fog; -/** - * Creates an instance scene - * @returns {THREE.Fog} - */ R3.D3.Fog.prototype.createInstance = function() { - if (this.exponential) { - - 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); + console.warn('This class should not be instantiated directly'); }; 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') { this.color.instance.setRGB( this.color.r, @@ -96,39 +30,8 @@ R3.D3.Fog.prototype.updateInstance = function(property) { this.color.b ); this.instance.color = this.color.instance; - } - - 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; - } + return; } 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) - ); - -}; diff --git a/src/r3-d3-font.js b/src/r3-d3-font.js deleted file mode 100644 index a99523f..0000000 --- a/src/r3-d3-font.js +++ /dev/null @@ -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) - ); - -}; \ No newline at end of file diff --git a/src/r3-d3-friction-contact-material.js b/src/r3-d3-friction-contact-material.js index fdf4fc5..d17f72f 100644 --- a/src/r3-d3-friction-contact-material.js +++ b/src/r3-d3-friction-contact-material.js @@ -1,33 +1,24 @@ /** - * FrictionContactMaterial Runtime - * @param physics R3.Runtime.Graphics - * @param apiFrictionContactMaterial R3.D3.API.FrictionContactMaterial + * R3.D3.FrictionContactMaterial + * @param apiComponent * @constructor */ R3.D3.FrictionContactMaterial = function( - physics, - apiFrictionContactMaterial + apiComponent ) { - this.physics = physics; - this.physics.isNotCannonThrow(); - - if (R3.Utils.UndefinedOrNull(apiFrictionContactMaterial)) { - apiFrictionContactMaterial = {}; - } + __RUNTIME_COMPONENT_MACRO__; R3.D3.API.FrictionContactMaterial.call( this, - apiFrictionContactMaterial.id, - apiFrictionContactMaterial.name, - apiFrictionContactMaterial.materials, - apiFrictionContactMaterial.friction, - apiFrictionContactMaterial.restitution, - apiFrictionContactMaterial.contactEquationStiffness, - apiFrictionContactMaterial.contactEquationRelaxation, - apiFrictionContactMaterial.frictionEquationStiffness, - apiFrictionContactMaterial.frictionEquationRelaxation, - apiFrictionContactMaterial.parent + apiComponent, + apiComponent.materials, + apiComponent.friction, + apiComponent.restitution, + apiComponent.contactEquationStiffness, + apiComponent.contactEquationRelaxation, + apiComponent.frictionEquationStiffness, + apiComponent.frictionEquationRelaxation ); R3.Component.call( @@ -47,20 +38,11 @@ R3.D3.FrictionContactMaterial.prototype.constructor = R3.D3.FrictionContactMater */ R3.D3.FrictionContactMaterial.prototype.createInstance = function() { - this.instance = new CANNON.ContactMaterial( - null, - null, - { - friction: this.friction, - restitution: this.restitution, - contactEquationStiffness: this.contactEquationStiffness - } - ); - - this.instance.materials = this.materials.map( - function(material){ - return material.instance; - } + this.instance = this.physics.ContactMaterial( + this.friction, + this.restitution, + this.contactEquationStiffness, + this.materials ); 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( - function(material) { - return material.instance; - } - ); + if (property === 'materials') { + this.physics.updateInstance(this, property); + return; + } - this.instance.friction = this.friction; - this.instance.restitution = this.restitution; - this.instance.contactEquationStiffness = this.contactEquationStiffness; - this.instance.contactEquationRelaxation = this.contactEquationRelaxation; - this.instance.frictionEquationStiffness = this.frictionEquationStiffness; - this.instance.frictionEquationRelaxation = this.frictionEquationRelaxation; + if (property === 'friction') { + this.physics.updateInstance(this, property); + return; + } + + 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 - ); -}; diff --git a/src/r3-d3-friction-material.js b/src/r3-d3-friction-material.js index 5e03ef2..766f960 100644 --- a/src/r3-d3-friction-material.js +++ b/src/r3-d3-friction-material.js @@ -1,28 +1,19 @@ /** - * FrictionMaterial Runtime - * @param physics R3.Runtime.Graphics - * @param apiFrictionMaterial R3.D3.API.FrictionMaterial + * R3.D3.FrictionMaterial + * @param apiComponent * @constructor */ R3.D3.FrictionMaterial = function( - physics, - apiFrictionMaterial + apiComponent ) { - this.physics = physics; - this.physics.isNotCannonThrow(); - - if (R3.Utils.UndefinedOrNull(apiFrictionMaterial)) { - apiFrictionMaterial = {}; - } + __RUNTIME_COMPONENT_MACRO__; R3.D3.API.FrictionMaterial.call( this, - apiFrictionMaterial.id, - apiFrictionMaterial.name, - apiFrictionMaterial.friction, - apiFrictionMaterial.restitution, - apiFrictionMaterial.parent + apiComponent, + apiComponent.friction, + apiComponent.restitution ); R3.Component.call(this); @@ -36,55 +27,30 @@ R3.D3.FrictionMaterial.prototype.constructor = R3.D3.FrictionMaterial; */ R3.D3.FrictionMaterial.prototype.createInstance = function() { - this.instance = new CANNON.Material( - this.name + this.instance = this.physics.Material( + this.name, + this.friction, + this.restitution ); - this.instance.friction = this.friction; - this.instance.restitution = this.restitution; - R3.Component.prototype.createInstance.call(this); }; /** * */ -R3.D3.FrictionMaterial.prototype.updateInstance = function() { - this.instance.friction = this.friction; - this.instance.restitution = this.restitution; - this.instance.name = this.name; -}; - -/** - * R3.D3.FrictionMaterial to R3.D3.API.FrictionMaterial - * @returns {R3.D3.API.FrictionMaterial} - */ -R3.D3.FrictionMaterial.prototype.toApiObject = function() { - - var apiFrictionMaterial = new R3.D3.API.FrictionMaterial( - 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 - ); +R3.D3.FrictionMaterial.prototype.updateInstance = function(property) { + + if (property === 'friction') { + this.physics.updateInstance(this, property); + return; + } + + if (property === 'restitution') { + this.physics.updateInstance(this, property); + return; + } + + R3.Component.prototype.updateInstance.call(this, property); + }; diff --git a/src/r3-d3-geometry-a.js b/src/r3-d3-geometry-a.js index c9f07c1..8303054 100644 --- a/src/r3-d3-geometry-a.js +++ b/src/r3-d3-geometry-a.js @@ -1,93 +1,69 @@ /** * R3.D3.Geometry - * @param graphics - * @param apiGeometry - * @property geometryType + * @param apiComponent + * @param linkedObjects * @constructor */ R3.D3.Geometry = function( - graphics, - apiGeometry + apiComponent, + linkedObjects ) { - this.graphics = graphics; - this.graphics.isNotThreeThrow(); + if (R3.Utils.UndefinedOrNull(linkedObjects)) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType : R3.D3.API.Geometry.GEOMETRY_TYPE_NONE - }; + __RUNTIME_COMPONENT_MACRO__; + + 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.graphics, this.boundingBox ); this.boundingSphere = new R3.Sphere( - this.graphics, this.boundingSphere ); - this.faces = this.faces.map( - function(face) { - return new R3.D3.Face( - this.graphics, - face - ) - }.bind(this) + linkedObjects.boundingBox = R3.Box3; + linkedObjects.boundingSphere = R3.Sphere; + + this.faces = this.faces.reduce( + function(result, face) { + if (face instanceof R3.D3.API.Face) { + result.push(R3.Component.ConstructFromObject(face)); + } else { + result.push(face); + } + return result; + }, + [] ); this.vertices = this.vertices.map( - function(vertex) { - return new R3.D3.Vertex( - this.graphics, - vertex - ) - }.bind(this) + function(result, vertex) { + if (vertex instanceof R3.D3.API.Vertex) { + result.push(R3.Component.ConstructFromObject(vertex)); + } else { + result.push(vertex); + } + return result; + }, + [] ); - var linkedObjects = {}; - - switch (this.geometryType) { - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES : - 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]; - } + linkedObjects.boundingBox = R3.Box3; + linkedObjects.boundingSphere = R3.Sphere; + linkedObjects.faces = [R3.D3.Face]; + linkedObjects.vertices = [R3.D3.Vertex]; R3.Component.call( this, diff --git a/src/r3-entity-manager.js b/src/r3-entity-manager.js index a6ad6cd..8b5f817 100644 --- a/src/r3-entity-manager.js +++ b/src/r3-entity-manager.js @@ -46,7 +46,6 @@ R3.EntityManager = function(apiEntityManager) { this.entityLoaded.bind(this) ); - R3.Component.call( this, { diff --git a/src/r3-font.js b/src/r3-font.js new file mode 100644 index 0000000..0717db4 --- /dev/null +++ b/src/r3-font.js @@ -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); +}; diff --git a/src/r3-runtime-graphics-three.js b/src/r3-runtime-graphics-three.js index 59843cb..2921989 100644 --- a/src/r3-runtime-graphics-three.js +++ b/src/r3-runtime-graphics-three.js @@ -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) { - return new THREE.Color(r,g,b,a); + return new THREE.Color(r,g,b); }; R3.Runtime.Graphics.Three.prototype.Matrix4 = function(rows) { @@ -557,4 +557,101 @@ R3.Runtime.Graphics.Three.prototype.StereoEffect = function( new THREE.StereoEffect( 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; + } + } + }; \ No newline at end of file diff --git a/src/r3-runtime-graphics.js b/src/r3-runtime-graphics.js index 5d53c5c..c482d92 100644 --- a/src/r3-runtime-graphics.js +++ b/src/r3-runtime-graphics.js @@ -174,4 +174,36 @@ R3.Runtime.Graphics.prototype.StereoEffect = function( renderer ) { console.warn('override StereoEffect in child class'); -}; \ No newline at end of file +}; + +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'); +}; + diff --git a/src/r3-runtime-physics-cannon.js b/src/r3-runtime-physics-cannon.js index 50a634d..c970b63 100644 --- a/src/r3-runtime-physics-cannon.js +++ b/src/r3-runtime-physics-cannon.js @@ -57,4 +57,88 @@ R3.Runtime.Physics.Cannon.prototype.Broadphase = function(broadphaseType) { 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; + } + } + }; \ No newline at end of file diff --git a/src/r3-runtime-physics.js b/src/r3-runtime-physics.js index 5dcc154..f6aea65 100644 --- a/src/r3-runtime-physics.js +++ b/src/r3-runtime-physics.js @@ -38,3 +38,24 @@ R3.Runtime.Physics.prototype.Quaternion = function(x,y,z,w) { R3.Runtime.Physics.prototype.Broadphase = function(broadphaseType) { 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'); +}; \ No newline at end of file