diff --git a/src/r3-api-ar.js b/bak/r3-api-ar.js similarity index 96% rename from src/r3-api-ar.js rename to bak/r3-api-ar.js index 8fc3f94..96ccbb6 100644 --- a/src/r3-api-ar.js +++ b/bak/r3-api-ar.js @@ -2,7 +2,7 @@ * R3.API.AR * @param id * @param name - * @param parentEntity + * @param parent * @param video * @param pathCamera * @param pathMarker @@ -15,7 +15,7 @@ R3.API.AR = function( id, name, - parentEntity, + parent, video, pathCamera, pathMarker, @@ -79,7 +79,7 @@ R3.API.AR = function( R3.API.Component.call( this, R3.Component.AR, - parentEntity + parent ); }; diff --git a/src/r3-api-graphics-runtime-a.js b/bak/r3-api-graphics-runtime-a.js similarity index 96% rename from src/r3-api-graphics-runtime-a.js rename to bak/r3-api-graphics-runtime-a.js index 769621c..587618e 100644 --- a/src/r3-api-graphics-runtime-a.js +++ b/bak/r3-api-graphics-runtime-a.js @@ -3,14 +3,14 @@ * @param id * @param name * @param graphicsType - * @param parentEntity + * @param parent * @constructor */ R3.API.GraphicsRuntime = function( id, name, graphicsType, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); @@ -30,7 +30,7 @@ R3.API.GraphicsRuntime = function( R3.API.Component.call( this, R3.API.GraphicsRuntime.GetComponentType(this.graphicsType), - parentEntity + parent ); }; diff --git a/src/r3-api-graphics-runtime-impact.js b/bak/r3-api-graphics-runtime-impact.js similarity index 95% rename from src/r3-api-graphics-runtime-impact.js rename to bak/r3-api-graphics-runtime-impact.js index ec62464..1b78a5f 100644 --- a/src/r3-api-graphics-runtime-impact.js +++ b/bak/r3-api-graphics-runtime-impact.js @@ -21,7 +21,7 @@ R3.API.GraphicsRuntime.Impact = function( apiGraphicsRuntime.id, apiGraphicsRuntime.name, apiGraphicsRuntime.graphicsType, - apiGraphicsRuntime.parentEntity + apiGraphicsRuntime.parent ); }; diff --git a/src/r3-api-graphics-runtime-three.js b/bak/r3-api-graphics-runtime-three.js similarity index 95% rename from src/r3-api-graphics-runtime-three.js rename to bak/r3-api-graphics-runtime-three.js index a91d5ea..78301ad 100644 --- a/src/r3-api-graphics-runtime-three.js +++ b/bak/r3-api-graphics-runtime-three.js @@ -21,7 +21,7 @@ R3.API.GraphicsRuntime.Three = function( apiGraphicsRuntime.id, apiGraphicsRuntime.name, apiGraphicsRuntime.graphicsType, - apiGraphicsRuntime.parentEntity + apiGraphicsRuntime.parent ); }; diff --git a/src/r3-api-number.js b/bak/r3-api-number.js similarity index 94% rename from src/r3-api-number.js rename to bak/r3-api-number.js index a22e60f..4afe050 100644 --- a/src/r3-api-number.js +++ b/bak/r3-api-number.js @@ -6,7 +6,7 @@ * @param min * @param max */ -R3.API.Number = function ( +R3.API.Number = function( value, grain, min, diff --git a/src/r3-api-render-configuration.js b/bak/r3-api-render-configuration.js similarity index 100% rename from src/r3-api-render-configuration.js rename to bak/r3-api-render-configuration.js diff --git a/src/r3-ar.js b/bak/r3-ar.js similarity index 99% rename from src/r3-ar.js rename to bak/r3-ar.js index d711b14..72e1195 100644 --- a/src/r3-ar.js +++ b/bak/r3-ar.js @@ -19,7 +19,7 @@ R3.AR = function( this, apiAR.id, apiAR.name, - apiAR.parentEntity, + apiAR.parent, apiAR.video, apiAR.pathCamera, apiAR.pathMarker, @@ -435,7 +435,7 @@ R3.AR.prototype.toApiObject = function() { return new R3.API.AR( this.id, this.name, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), R3.Utils.IdOrNull(this.video), this.pathCamera, this.pathMarker, diff --git a/src/r3-augmented-runtime.js b/bak/r3-augmented-runtime.js similarity index 100% rename from src/r3-augmented-runtime.js rename to bak/r3-augmented-runtime.js diff --git a/src/r3-graphics-runtime-impact.js b/bak/r3-graphics-runtime-impact.js similarity index 98% rename from src/r3-graphics-runtime-impact.js rename to bak/r3-graphics-runtime-impact.js index ee6152f..76bf3c3 100644 --- a/src/r3-graphics-runtime-impact.js +++ b/bak/r3-graphics-runtime-impact.js @@ -3,7 +3,7 @@ * @param apiGraphicsRuntimeImpact * @constructor */ -R3.GraphicsRuntime.Impact = function ( +R3.GraphicsRuntime.Impact = function( apiGraphicsRuntimeImpact ) { diff --git a/src/r3-number.js b/bak/r3-number.js similarity index 98% rename from src/r3-number.js rename to bak/r3-number.js index b057fde..20f83e3 100644 --- a/src/r3-number.js +++ b/bak/r3-number.js @@ -4,7 +4,7 @@ * @param parentObject * @constructor */ -R3.Number = function ( +R3.Number = function( apiNumber, parentObject ) { diff --git a/src/r3-render-configuration.js b/bak/r3-render-configuration.js similarity index 100% rename from src/r3-render-configuration.js rename to bak/r3-render-configuration.js diff --git a/gulpfile.js b/gulpfile.js index 538afe5..6cffe39 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,11 +7,24 @@ var replace = require('gulp-string-replace'); gulp.task('build', build); gulp.task('monitor', monitor); +var code = ' if (R3.Utils.UndefinedOrNull(apiComponent)) {'; +code += ' apiComponent = {};'; +code += ' }'; +code += ' this.apiComponent = apiComponent;'; +code += '\n'; +code += ' R3.API.Component.call('; +code += ' this,'; +code += ' this.apiComponent.parent,'; +code += ' this.apiComponent.id,'; +code += ' this.apiComponent.name'; +code += ' );'; + function build() { return gulp.src('./src/r3-*.js') .pipe(sort()) .pipe(concat('r3.js')) .pipe(replace('__DATE__', new Date().toString())) + .pipe(replace('__API_COMPONENT_MACRO__', code)); .pipe(minify({ ext:{ src:'.js', @@ -32,4 +45,4 @@ gulp.task( build, monitor ) -); \ No newline at end of file +); diff --git a/src/r3-a-1-event.js b/src/r3-a-1-event.js index 55eb946..3ee0541 100644 --- a/src/r3-a-1-event.js +++ b/src/r3-a-1-event.js @@ -2,7 +2,11 @@ * Event Core * @constructor */ -R3.Event = function() { +R3.Event = function(parent) { + if (!parent) { + parent = null; + } + this.parent = parent; }; /** @@ -13,7 +17,7 @@ R3.Event.Subscriptions = {}; R3.Event.OnceSubscriptions = {}; /** - * Events we can subscribe to and publish + * Events we can subscribe to and emit */ R3.Event.WINDOW_RESIZE = 0x1; R3.Event.PARENT_SCENE_CHANGE = 0x2; @@ -93,7 +97,7 @@ R3.Event.TOUCH_MOVE = 0x4b; R3.Event.TOUCH_CANCEL = 0x4c; R3.Event.GET_REMOTE_API_URL = 0x4d; R3.Event.COMPONENT_TYPES_UPDATE = 0x4e; -R3.Event.DELAYED_INSTANCE_ENCOUNTERED = 0x4f; +R3.Event.PROJECT_LOADED = 0x4f; R3.Event.CAST_SOURCE_CHANGED = 0x50; R3.Event.RESOLVE_DEPENDENCIES = 0x51; R3.Event.NAME_UPDATE = 0x52; @@ -225,7 +229,7 @@ R3.Event.GetEventName = function(number) { case 0x4c : return 'touch_cancel'; case 0x4d : return 'get_remote_api_url'; case 0x4e : return 'component_types_update'; - case 0x4f : return 'delayed_instance_encountered'; + case 0x4f : return 'project_loaded'; case 0x50 : return 'cast_source_changed'; case 0x51 : return 'resolve_dependencies';; case 0x52 : return 'name_update'; @@ -335,7 +339,7 @@ R3.Event.prototype.subscribe = function( * @param clientErrorCallback * @returns {number} of callbacks executed */ -R3.Event.prototype.publish = function( +R3.Event.prototype.emit = function( eventName, data, clientCallback, diff --git a/src/r3-a-2-utils.js b/src/r3-a-2-utils.js index 3a935a1..6f5281b 100644 --- a/src/r3-a-2-utils.js +++ b/src/r3-a-2-utils.js @@ -69,7 +69,7 @@ R3.Utils.SortFacesByMaterialIndex = function(faces) { * Sorts faces according to material index because later we will create * groups for each vertice group */ - faces.sort(function (a, b) { + faces.sort(function(a, b) { if (a.materialIndex < b.materialIndex) { return -1; @@ -158,7 +158,7 @@ R3.Utils.GetWindowSize = function() { R3.Event.Emit( R3.Event.GET_WINDOW_SIZE, null, - function (data) { + function(data) { size = data; }.bind(this) ); @@ -242,7 +242,7 @@ R3.Utils.GetRandomIntInclusive = function(min, max) { R3.Utils.InterpolateArray = function(data, fitCount) { - var linearInterpolate = function (before, after, atPoint) { + var linearInterpolate = function(before, after, atPoint) { return before + (after - before) * atPoint; }; @@ -271,7 +271,7 @@ R3.Utils.InterpolateArray = function(data, fitCount) { * @returns {boolean} * @constructor */ -R3.Utils.UndefinedOrNull = function ( +R3.Utils.UndefinedOrNull = function( variable ) { return typeof variable === 'undefined' || variable === null; @@ -283,7 +283,7 @@ R3.Utils.UndefinedOrNull = function ( * @returns {boolean} * @constructor */ -R3.Utils.Defined = function ( +R3.Utils.Defined = function( variable ) { return typeof variable !== 'undefined' && variable !== null; @@ -327,7 +327,7 @@ R3.Utils.GetParameters = function(fn) { * @returns {null} * @constructor */ -R3.Utils.IdOrNull = function (object) { +R3.Utils.IdOrNull = function(object) { if (R3.Utils.UndefinedOrNull(object)) { return null; } else { @@ -374,7 +374,7 @@ R3.Utils.LimitToPI = function(property, objectProperty) { * @returns [] * @constructor */ -R3.Utils.IdArrayOrEmptyArray = function (array) { +R3.Utils.IdArrayOrEmptyArray = function(array) { if (R3.Utils.UndefinedOrNull(array)) { return []; } else { @@ -448,7 +448,7 @@ R3.Utils.InvertWindingOrder = function(triangles) { R3.Utils.InvertMeshWindingOrder = function(mesh) { mesh.faces.forEach( - function (face) { + function(face) { var tmpV1 = face.v1; face.v1 = face.v2; @@ -767,7 +767,7 @@ R3.Utils.MovingAverage = function(period) { } }; -R3.Utils.Intersect = function (a, b) { +R3.Utils.Intersect = function(a, b) { var t; @@ -786,7 +786,7 @@ R3.Utils.Intersect = function (a, b) { * @param e * @returns {boolean} */ - function (e) { + function(e) { return (b.indexOf(e) > -1); } ).filter( @@ -797,13 +797,13 @@ R3.Utils.Intersect = function (a, b) { * @param c * @returns {boolean} */ - function (e, i, c) { + function(e, i, c) { return c.indexOf(e) === i; } ); }; -R3.Utils.Difference = function (a, b) { +R3.Utils.Difference = function(a, b) { var t; @@ -822,7 +822,7 @@ R3.Utils.Difference = function (a, b) { * @param e * @returns {boolean} */ - function (e) { + function(e) { return (b.indexOf(e) === -1); } ).filter( @@ -833,7 +833,7 @@ R3.Utils.Difference = function (a, b) { * @param c * @returns {boolean} */ - function (e, i, c) { + function(e, i, c) { return c.indexOf(e) === i; } ); diff --git a/src/r3-a-3-api-component.js b/src/r3-a-3-api-component.js new file mode 100644 index 0000000..52b0037 --- /dev/null +++ b/src/r3-a-3-api-component.js @@ -0,0 +1,468 @@ +/** + * API Component Interface - Do not construct objects of this type directly + * @param parent + * @param id + * @param name + * @constructor + */ +R3.API.Component = function( + parent, + id, + name +) { + + if (R3.Utils.UndefinedOrNull(parent)) { + parent = null; + } + this.parent = parent; + + if (R3.Utils.UndefinedOrNull(id)) { + id = R3.Utils.RandomId(); + } + this.id = id; + + this.componentType = this.getComponentType(); + + if (R3.Utils.UndefinedOrNull(name)) { + name = R3.Component.GetComponentFriendlyName(this.componentType) + ' (' + this.id + ')'; + } + this.name = name; +}; + +R3.API.Component.prototype.constructor = R3.API.Component; + +R3.API.Component.prototype.getComponentType = function() { + + if (this instanceof R3.API.Box3) { + return R3.Component.BOX3; + } + if (this instanceof R3.API.Canvas) { + return R3.Component.CANVAS; + } + if (this instanceof R3.API.Clock) { + return R3.Component.CLOCK; + } + if (this instanceof R3.API.Controls.D3.Editor) { + return R3.Component.CONTROLS_EDITOR; + } + if (this instanceof R3.API.Controls.D3.FirstPerson) { + return R3.Component.CONTROLS_FIRST_PERSON; + } + if (this instanceof R3.API.Controls.D3.Orbit) { + return R3.Component.CONTROLS_ORBIT; + } + if (this instanceof R3.API.Controls.Keyboard) { + return R3.Component.CONTROLS_KEYBOARD; + } + if (this instanceof R3.API.Controls.Mouse) { + return R3.Component.CONTROLS_MOUSE; + } + if (this instanceof R3.API.Controls.Touch) { + return R3.Component.CONTROLS_TOUCH; + } + if (this instanceof R3.API.Curve.Path.D2.Shape) { + return R3.Component.CURVE_PATH_D2_SHAPE; + } + if (this instanceof R3.API.Curve.Path.D2) { + return R3.Component.CURVE_PATH_D2; + } + if (this instanceof R3.API.Curve.Path) { + return R3.Component.CURVE_PATH; + } + if (this instanceof R3.API.Curve) { + return R3.Component.CURVE; + } + if (this instanceof R3.API.CustomCode) { + return R3.Component.CUSTOM_CODE; + } + if (this instanceof R3.API.DomElement) { + return R3.Component.DOM_ELEMENT; + } + if (this instanceof R3.API.DrawRange) { + return R3.Component.DRAW_RANGE; + } + if (this instanceof R3.API.Entity) { + return R3.Component.ENTITY; + } + if (this instanceof R3.API.EntityManager) { + return R3.Component.ENTITY_MANAGER; + } + if (this instanceof R3.API.Group) { + return R3.Component.GROUP; + } + if (this instanceof R3.API.GUI) { + return R3.Component.GUI; + } + if (this instanceof R3.API.Image) { + return R3.Component.IMAGE; + } + if (this instanceof R3.API.Mouse) { + return R3.Component.MOUSE; + } + if (this instanceof R3.API.Plane) { + return R3.Component.PLANE; + } + if (this instanceof R3.API.Project) { + return R3.Component.PROJECT; + } + if (this instanceof R3.API.Renderer.D3.Canvas.Target) { + return R3.Component.RENDERER_D3_CANVAS_TARGET; + } + if (this instanceof R3.API.Renderer.D3.Canvas) { + return R3.Component.RENDERER_D3_CANVAS; + } + if (this instanceof R3.API.Renderer.D3.Target) { + return R3.Component.RENDERER_D3_TARGET; + } + if (this instanceof R3.API.Renderer.D3) { + return R3.Component.RENDERER_D3; + } + if (this instanceof R3.API.Renderer.D2) { + return R3.Component.RENDERER_D2; + } + if (this instanceof R3.API.Server) { + return R3.Component.SERVER; + } + if (this instanceof R3.API.Socket.Receive) { + return R3.Component.SOCKET_RECEIVE; + } + if (this instanceof R3.API.Socket.Cast) { + return R3.Component.SOCKET_CAST; + } + if (this instanceof R3.API.Sphere) { + return R3.Component.SPHERE; + } + if (this instanceof R3.API.Stats) { + return R3.Component.STATS; + } + if (this instanceof R3.API.User) { + return R3.Component.USER; + } + if (this instanceof R3.API.Video) { + return R3.Component.VIDEO; + } + if (this instanceof R3.D3.API.Animation) { + return R3.Component.ANIMATION; + } + if (this instanceof R3.D3.API.Object) { + return R3.Component.OBJECT; + } + if (this instanceof R3.D3.API.Audio) { + return R3.Component.AUDIO; + } + if (this instanceof R3.D3.API.Bone) { + return R3.Component.BONE; + } + if (this instanceof R3.D3.API.Broadphase) { + return R3.Component.BROADPHASE; + } + if (this instanceof R3.D3.API.Camera.Perspective.Stereo) { + return R3.Component.CAMERA_PERSPECTIVE_STEREO; + } + if (this instanceof R3.D3.API.Camera.Perspective) { + return R3.Component.CAMERA_PERSPECTIVE; + } + if (this instanceof R3.D3.API.Camera.Orthographic) { + return R3.Component.CAMERA_ORTHOGRAPHIC; + } + if (this instanceof R3.D3.API.Camera.Cube) { + return R3.Component.CAMERA_CUBE; + } + if (this instanceof R3.D3.API.Composer) { + return R3.Component.COMPOSER; + } + if (this instanceof R3.D3.API.Effect.Stereo) { + return R3.Component.EFFECT_STEREO; + } + if (this instanceof R3.D3.API.Effect.Parallax) { + return R3.Component.EFFECT_PARALLAX; + } + if (this instanceof R3.D3.API.Effect.Anaglyph) { + return R3.Component.EFFECT_ANAGLYPH; + } + if (this instanceof R3.D3.API.Fog) { + return R3.Component.FOG; + } + if (this instanceof R3.D3.API.Font) { + return R3.Component.FONT; + } + if (this instanceof R3.D3.API.FrictionContactMaterial) { + return R3.Component.FRICTION_CONTACT_MATERIAL; + } + if (this instanceof R3.D3.API.FrictionMaterial) { + return R3.Component.FRICTION_MATERIAL; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Box) { + return R3.Component.GEOMETRY_BUFFER_BOX; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Circle) { + return R3.Component.GEOMETRY_BUFFER_CIRCLE; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Cone) { + return R3.Component.GEOMETRY_BUFFER_CONE; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Cylinder) { + return R3.Component.GEOMETRY_BUFFER_CYLINDER; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Dodecahedron) { + return R3.Component.GEOMETRY_BUFFER_DODECAHEDRON; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Extrude) { + return R3.Component.GEOMETRY_BUFFER_EXTRUDE; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Icosahedron) { + return R3.Component.GEOMETRY_BUFFER_ICOSAHEDRON; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Instanced) { + return R3.Component.GEOMETRY_BUFFER_INSTANCED; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Lathe) { + return R3.Component.GEOMETRY_BUFFER_LATHE; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Octahedron) { + return R3.Component.GEOMETRY_BUFFER_OCTAHEDRON; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Parametric) { + return R3.Component.GEOMETRY_BUFFER_PARAMETRIC; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Plane) { + return R3.Component.GEOMETRY_BUFFER_PLANE; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Polyhedron) { + return R3.Component.GEOMETRY_BUFFER_POLYHEDRON; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Ring) { + return R3.Component.GEOMETRY_BUFFER_RING; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Shape) { + return R3.Component.GEOMETRY_BUFFER_SHAPE; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Sphere) { + return R3.Component.GEOMETRY_BUFFER_SPHERE; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Tetrahedron) { + return R3.Component.GEOMETRY_BUFFER_TETRAHEDRON; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Text) { + return R3.Component.GEOMETRY_BUFFER_TEXT; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Torus) { + return R3.Component.GEOMETRY_BUFFER_TORUS; + } + if (this instanceof R3.D3.API.Geometry.Buffer.TorusKnot) { + return R3.Component.GEOMETRY_BUFFER_TORUS_KNOT; + } + if (this instanceof R3.D3.API.Geometry.Buffer.Tube) { + return R3.Component.GEOMETRY_BUFFER_TUBE; + } + if (this instanceof R3.D3.API.Geometry.Buffer) { + return R3.Component.GEOMETRY_BUFFER; + } + if (this instanceof R3.D3.API.Geometry.Normal.Box) { + return R3.Component.GEOMETRY_NORMAL_BOX; + } + if (this instanceof R3.D3.API.Geometry.Normal.Circle) { + return R3.Component.GEOMETRY_NORMAL_CIRCLE; + } + if (this instanceof R3.D3.API.Geometry.Normal.Cone) { + return R3.Component.GEOMETRY_NORMAL_CONE; + } + if (this instanceof R3.D3.API.Geometry.Normal.Cylinder) { + return R3.Component.GEOMETRY_NORMAL_CYLINDER; + } + if (this instanceof R3.D3.API.Geometry.Normal.Dodecahedron) { + return R3.Component.GEOMETRY_NORMAL_DODECAHEDRON; + } + if (this instanceof R3.D3.API.Geometry.Normal.Edges) { + return R3.Component.GEOMETRY_NORMAL_EDGES; + } + if (this instanceof R3.D3.API.Geometry.Normal.Extrude) { + return R3.Component.GEOMETRY_NORMAL_EXTRUDE; + } + if (this instanceof R3.D3.API.Geometry.Normal.Icosahedron) { + return R3.Component.GEOMETRY_NORMAL_ICOSAHEDRON; + } + if (this instanceof R3.D3.API.Geometry.Normal.Lathe) { + return R3.Component.GEOMETRY_NORMAL_LATHE; + } + if (this instanceof R3.D3.API.Geometry.Normal.Octahedron) { + return R3.Component.GEOMETRY_NORMAL_OCTAHEDRON; + } + if (this instanceof R3.D3.API.Geometry.Normal.Parametric) { + return R3.Component.GEOMETRY_NORMAL_PARAMETRIC; + } + if (this instanceof R3.D3.API.Geometry.Normal.Plane) { + return R3.Component.GEOMETRY_NORMAL_PLANE; + } + if (this instanceof R3.D3.API.Geometry.Normal.Polyhedron) { + return R3.Component.GEOMETRY_NORMAL_POLYHEDRON; + } + if (this instanceof R3.D3.API.Geometry.Normal.Ring) { + return R3.Component.GEOMETRY_NORMAL_RING; + } + if (this instanceof R3.D3.API.Geometry.Normal.Shape) { + return R3.Component.GEOMETRY_NORMAL_SHAPE; + } + if (this instanceof R3.D3.API.Geometry.Normal.Sphere) { + return R3.Component.GEOMETRY_NORMAL_SPHERE; + } + if (this instanceof R3.D3.API.Geometry.Normal.Tetrahedron) { + return R3.Component.GEOMETRY_NORMAL_TETRAHEDRON; + } + if (this instanceof R3.D3.API.Geometry.Normal.Text) { + return R3.Component.GEOMETRY_NORMAL_TEXT; + } + if (this instanceof R3.D3.API.Geometry.Normal.Torus) { + return R3.Component.GEOMETRY_NORMAL_TORUS; + } + if (this instanceof R3.D3.API.Geometry.Normal.TorusKnot) { + return R3.Component.GEOMETRY_NORMAL_TORUS_KNOT; + } + if (this instanceof R3.D3.API.Geometry.Normal.Tube) { + return R3.Component.GEOMETRY_NORMAL_TUBE; + } + if (this instanceof R3.D3.API.Geometry.Normal.Wireframe) { + return R3.Component.GEOMETRY_NORMAL_WIREFRAME; + } + if (this instanceof R3.D3.API.Geometry.Normal) { + return R3.Component.GEOMETRY_NORMAL; + } + if (this instanceof R3.D3.API.Geometry) { + return R3.Component.GEOMETRY; + } + if (this instanceof R3.D3.API.Light.Ambient) { + return R3.Component.LIGHT_AMBIENT; + } + if (this instanceof R3.D3.API.Light.Directional) { + return R3.Component.LIGHT_DIRECTIONAL; + } + if (this instanceof R3.D3.API.Light.Hemisphere) { + return R3.Component.LIGHT_HEMISPHERE; + } + if (this instanceof R3.D3.API.Light.Point) { + return R3.Component.LIGHT_POINT; + } + if (this instanceof R3.D3.API.Light.RectArea) { + return R3.Component.LIGHT_RECT_AREA; + } + if (this instanceof R3.D3.API.Light.Spot) { + return R3.Component.LIGHT_SPOT; + } + if (this instanceof R3.D3.API.Material.Basic) { + return R3.Component.MATERIAL_BASIC; + } + if (this instanceof R3.D3.API.Material.Phong) { + return R3.Component.MATERIAL_PHONG; + } + if (this instanceof R3.D3.API.Material.Points) { + return R3.Component.MATERIAL_POINTS; + } + if (this instanceof R3.D3.API.Material.Shader) { + return R3.Component.MATERIAL_SHADER; + } + if (this instanceof R3.D3.API.Material.Shader.Raw) { + return R3.Component.MATERIAL_SHADER_RAW; + } + if (this instanceof R3.D3.API.Material.Standard) { + return R3.Component.MATERIAL_STANDARD; + } + if (this instanceof R3.D3.API.Mesh) { + return R3.Component.MESH; + } + if (this instanceof R3.D3.API.ParticleEngine) { + return R3.Component.PARTICLE_ENGINE; + } + if (this instanceof R3.D3.API.Particle) { + return R3.Component.PARTICLE; + } + if (this instanceof R3.D3.API.Pass.Bloom) { + return R3.Component.PASS_BLOOM; + } + if (this instanceof R3.D3.API.Pass.FXAA) { + return R3.Component.PASS_FXAA; + } + if (this instanceof R3.D3.API.Pass.Render) { + return R3.Component.PASS_RENDER; + } + if (this instanceof R3.D3.API.Pass.SSAO) { + return R3.Component.PASS_SSAO; + } + if (this instanceof R3.D3.API.PhysicsWorld) { + return R3.Component.PHYSICS_WORLD; + } + if (this instanceof R3.D3.API.Raycaster) { + return R3.Component.RAYCASTER; + } + if (this instanceof R3.D3.API.RaycastVehicle) { + return R3.Component.RAYCAST_VEHICLE; + } + if (this instanceof R3.D3.API.RaycastWheel) { + return R3.Component.RAYCAST_WHEEL; + } + if (this instanceof R3.D3.API.RenderTarget.Cube) { + return R3.Component.RENDER_TARGET_CUBE; + } + if (this instanceof R3.D3.API.RenderTarget) { + return R3.Component.RENDER_TARGET; + } + if (this instanceof R3.D3.API.RigidBody) { + return R3.Component.RIGID_BODY; + } + if (this instanceof R3.D3.API.Scene) { + return R3.Component.SCENE; + } + if (this instanceof R3.D3.API.Shader.Vertex) { + return R3.Component.SHADER_VERTEX; + } + if (this instanceof R3.D3.API.Shader.Fragment) { + return R3.Component.SHADER_FRAGMENT; + } + if (this instanceof R3.D3.API.Shader) { + return R3.Component.SHADER; + } + if (this instanceof R3.D3.API.Shadow.Directional) { + return R3.Component.SHADOW_DIRECTIONAL; + } + if (this instanceof R3.D3.API.Shadow.Spot) { + return R3.Component.SHADOW_SPOT; + } + if (this instanceof R3.D3.API.Shadow) { + return R3.Component.SHADOW; + } + if (this instanceof R3.D3.API.Shape) { + return R3.Component.SHAPE; + } + if (this instanceof R3.D3.API.Skeleton) { + return R3.Component.SKELETON; + } + if (this instanceof R3.D3.API.Solver) { + return R3.Component.SOLVER; + } + if (this instanceof R3.D3.API.Spline) { + return R3.Component.SPLINE; + } + if (this instanceof R3.D3.API.Text) { + return R3.Component.TEXT; + } + if (this instanceof R3.D3.API.Texture.Canvas) { + return R3.Component.TEXTURE_CANVAS; + } + if (this instanceof R3.D3.API.Texture.Cube) { + return R3.Component.TEXTURE_CUBE; + } + if (this instanceof R3.D3.API.Texture.Image) { + return R3.Component.TEXTURE_IMAGE; + } + if (this instanceof R3.D3.API.Texture) { + return R3.Component.TEXTURE; + } + if (this instanceof R3.D3.API.Viewport.FixedAspect) { + return R3.Component.VIEWPORT_FIXED_ASPECT; + } + if (this instanceof R3.D3.API.Viewport.ZoomedAspect) { + return R3.Component.VIEWPORT_ZOOMED_ASPECT; + } + if (this instanceof R3.D3.API.Viewport) { + return R3.Component.VIEWPORT; + } +}; \ No newline at end of file diff --git a/src/r3-a-component-a.js b/src/r3-a-4-component-a.js similarity index 75% rename from src/r3-a-component-a.js rename to src/r3-a-4-component-a.js index 2820f62..7f0f58b 100644 --- a/src/r3-a-component-a.js +++ b/src/r3-a-4-component-a.js @@ -2,17 +2,26 @@ * Component Interface * @constructor * @param linkedObjects - * @param delayed + * @param parent */ R3.Component = function( - linkedObjects, - delayed + parent, + linkedObjects ) { + /** + * Call the Event constructor first so we can set the parent right away + */ + R3.Event.call( + this, + parent + ); + + this.componentType = this.getComponentType(); + if (R3.Utils.UndefinedOrNull(linkedObjects)) { linkedObjects = {}; } this.linkedObjects = linkedObjects; - this.linkedObjects.parentEntity = R3.Entity; this.idToObject = {}; @@ -30,14 +39,9 @@ R3.Component = function( this.generateNewImageIds = false; - if (R3.Utils.UndefinedOrNull(delayed)) { - delayed = false; - } - this.delayed = delayed; - this.dependencies = this.getDependencies(); - R3.Event.Emit( + this.emit( R3.Event.COMPONENT_REGISTER, { component : this @@ -49,7 +53,7 @@ R3.Component = function( this.performInstanceCreation(); } else { - R3.Event.Emit( + this.emit( R3.Event.REGISTER_DEPENDENCIES, { component : this @@ -68,7 +72,6 @@ R3.Component.prototype.constructor = R3.Component; * Ensure we have no dependencies * Build a list of all child components - if they are all linked, we are ready to create an instance * Ensure we are linked - * Ensure we are not delayed * Try to create the instance * Error Log if failed * Don't do anything if we are not fully linked @@ -101,38 +104,16 @@ R3.Component.prototype.performInstanceCreation = function() { * Don't try to create an instance of this object until it is fully linked */ if (this.linked) { - if (!this.delayed) { - try { - this.createInstance(); - } catch (error) { - console.error(error); - } - } else { - /** - * Some systems require an instance creation at an exact time, like System.Input for Edit Controls - - * we need to give them the opportunity to handle this situation - */ - R3.Event.Emit( - R3.Event.DELAYED_INSTANCE_ENCOUNTERED, - { - component : this - } - ) + try { + this.createInstance(); + } catch (error) { + console.error(error); } } }; R3.Component.prototype.createInstance = function() { - // console.log('create instance : '+ this.name); - - /** - * When you do actually call 'createInstance' - it is wise to state we are no longer delayed - we assume the caller - * knows when to call createInstance, so we do the housekeeping here - * @type {boolean} - */ - this.delayed = false; - if (this.instance) { this.loaded = true; @@ -153,12 +134,22 @@ R3.Component.prototype.createInstance = function() { } if (this instanceof R3.Entity) { - R3.Event.Emit( - R3.Event.ENTITY_LOADED, - { - entity:this - } - ) + + if (this instanceof R3.Project) { + R3.Event.Emit( + R3.Event.PROJECT_LOADED, + { + entity:this + } + ) + } else { + R3.Event.Emit( + R3.Event.ENTITY_LOADED, + { + entity: this + } + ) + } } }; @@ -174,7 +165,6 @@ R3.Component.prototype.getDependencies = function() { if ( this.linkedObjects.hasOwnProperty(property) && - property.indexOf('parent') !== 0 && this.hasOwnProperty(property) ){ if (typeof this[property] === 'string') { @@ -210,25 +200,63 @@ R3.Component.prototype.getDependencies = function() { }; R3.Component.prototype.updateInstance = function(property) { + console.warn('TODO: update instance for parent change'); - if (property === 'parentEntity') { + // + // if (property === 'parent') { + // + // if (this.parent instanceof R3.Entity) { + // this.parent.addComponent(this); + // + // this.buildIdToObject(); + // + // Object.keys(this.idToObject).map( + // function(componentId) { + // + // if (this.id !== componentId) { + // this.parent.addComponent(this.idToObject[componentId]); + // } + // + // }.bind(this) + // ) + // } + // + // } - if (this.parentEntity instanceof R3.Entity) { - this.parentEntity.addComponent(this); +}; - this.buildIdToObject(); +/** + * R3.Component.prototype.getParent traverses the parent chain looking for the first parent which has a certain + * property. If the constructor is given, then not only does the property have to exist - it also has to match the + * constructor + * @param property + * @param constructor + * @returns {null|*} + */ +R3.Component.prototype.getParent = function(property, constructor) { - Object.keys(this.idToObject).map( - function(componentId) { + if (R3.Utils.UndefinedOrNull(constructor)) { + constructor = null; + } - if (this.id !== componentId) { - this.parentEntity.addComponent(this.idToObject[componentId]); - } + if (this.parent) { + if (this.parent.hasOwnProperty(property)) { - }.bind(this) - ) + if (constructor) { + if (this.parent[property] instanceof constructor) { + return this.parent[property]; + } else { + return this.parent.getParent(property, constructor); + } + } else { + return this.parent[property]; + } + } else { + return this.parent.getParent(property, constructor); } - + } else { + console.warn('property : ' + property + ' of type ' + constructor + ' was not found in the parent chain'); + return null; } }; @@ -242,7 +270,7 @@ R3.Component.MATERIAL_STANDARD = 0x2; R3.Component.RENDERER = 0x3; R3.Component.SERVER = 0x4; R3.Component.CAMERA_PERSPECTIVE = 0x5; -//R3.Component.SOCKET = 0x6; +R3.Component.UNUSED = 0x6; R3.Component.MESH = 0x7; R3.Component.SPLINE = 0x8; R3.Component.SHADOW_DIRECTIONAL = 0x9; @@ -253,7 +281,7 @@ R3.Component.PASS_RENDER = 0xd; R3.Component.SCENE = 0xe; R3.Component.RAYCASTER = 0xf; R3.Component.TEXT = 0x10; -R3.Component.FACE = 0x11; +R3.Component.UNUSED = 0x11; R3.Component.VIEWPORT = 0x12; R3.Component.SYSTEM = 0x13; R3.Component.GRAPHICS = 0x14; @@ -295,21 +323,21 @@ R3.Component.CLOCK = 0x37; R3.Component.ANIMATION = 0x38; R3.Component.CONTROLS_KEYBOARD = 0x39; R3.Component.CONTROLS_MOUSE = 0x3a; -R3.Component.GRAPHICS_THREE = 0x3b; +R3.Component.RENDERER_D3_CANVAS_TARGET = 0x3b; R3.Component.FONT = 0x3c; R3.Component.CANVAS = 0x3d; R3.Component.BONE = 0x3e; -R3.Component.GRAPHICS_IMPACT = 0x3f; +R3.Component.RENDERER_D3_CANVAS = 0x3f; R3.Component.CONTROLS_FIRST_PERSON = 0x40; -R3.Component.SYSTEM_ANIMATION = 0x41; -R3.Component.SYSTEM_CUSTOM_CODE = 0x42; -R3.Component.SYSTEM_GUI = 0x43; -R3.Component.SYSTEM_INPUT = 0x44; -R3.Component.SYSTEM_LINKING = 0x45; -R3.Component.SYSTEM_PHYSICS = 0x46; -R3.Component.SYSTEM_RENDER = 0x47; -R3.Component.SYSTEM_STORAGE = 0x48; -R3.Component.SYSTEM_VISUALIZATION = 0x49; +R3.Component.RENDERER_D3_TARGET = 0x41; +R3.Component.SPHERE = 0x42; +R3.Component.UNUSED = 0x43; +R3.Component.UNUSED = 0x44; +R3.Component.UNUSED = 0x45; +R3.Component.UNUSED = 0x46; +R3.Component.UNUSED = 0x47; +R3.Component.UNUSED = 0x48; +R3.Component.UNUSED = 0x49; R3.Component.LIGHT_AMBIENT = 0x4a; R3.Component.LIGHT_DIRECTIONAL = 0x4b; R3.Component.LIGHT_HEMISPHERE = 0x4c; @@ -409,8 +437,10 @@ R3.Component.MATERIAL_POINTS = 0xa3; R3.Component.VIDEO = 0xa4; R3.Component.USER = 0xa5; R3.Component.PROJECT = 0xa6; +R3.Component.VIEWPORT_FIXED_ASPECT = 0xa7; +R3.Component.VIEWPORT_ZOOMED_ASPECT = 0xa8; -R3.Component.MAX_COMPONENTS = 0xa7; +R3.Component.MAX_COMPONENTS = 0xa9; R3.Component.GRAPHICS_RUNTIME = 0x1; R3.Component.PHYSICS_RUNTIME = 0x2; @@ -420,13 +450,6 @@ R3.Component.DEFAULT_RUNTIME = 0x5; R3.Component.GUI_RUNTIME = 0x6; R3.Component.CODER_RUNTIME = 0x7; -R3.Component.GetCompentTypes = function(constructor) { - - if (constructor === R3.Component) { - - } -}; - /** * Returns string name for component number * @param number @@ -434,6 +457,7 @@ R3.Component.GetCompentTypes = function(constructor) { * @constructor */ R3.Component.GetComponentInfo = function(number) { + switch(number) { case 0x1 : return { name : 'R3.Socket.Receive', @@ -465,12 +489,12 @@ R3.Component.GetComponentInfo = function(number) { constructor : R3.D3.Camera.Perspective, apiConstructor : R3.D3.API.Camera.Perspective }; - case 0x6 : return;/*{ - name : 'R3.Socket', - runtime : R3.Component.SOCKET_RUNTIME, - constructor : R3.Socket, - apiConstructor : R3.API.Socket - };*/ + case 0x6 : return { + name : 'R3.Color', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Color, + apiConstructor : R3.API.Color + }; case 0x7 : return { name : 'R3.D3.Mesh', runtime : R3.Component.GRAPHICS_RUNTIME, @@ -780,10 +804,10 @@ R3.Component.GetComponentInfo = function(number) { apiConstructor : R3.API.Controls }; case 0x3b : return { - name : 'R3.GraphicsRuntime.Three', - runtime : R3.Component.DEFAULT_RUNTIME, - constructor : R3.GraphicsRuntime.Three, - apiConstructor : R3.API.GraphicsRuntime.Three + name : 'R3.Renderer.D3.Canvas.Target', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Renderer.D3.Canvas.Target, + apiConstructor : R3.API.Renderer.D3.Canvas.Target }; case 0x3c : return { name : 'R3.D3.Font', @@ -804,10 +828,10 @@ R3.Component.GetComponentInfo = function(number) { apiConstructor : R3.D3.API.Bone }; case 0x3f : return { - name : 'R3.GraphicsRuntime.Impact', - runtime : R3.Component.DEFAULT_RUNTIME, - constructor : R3.GraphicsRuntime.Impact, - apiConstructor : R3.API.GraphicsRuntime.Impact + name : 'R3.Renderer.D3.Canvas', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Renderer.D3.Canvas, + apiConstructor : R3.API.Renderer.D3.Canvas }; case 0x40 : return { name : 'R3.Controls.D3.FirstPerson', @@ -816,16 +840,16 @@ R3.Component.GetComponentInfo = function(number) { apiConstructor : R3.API.Controls.D3.FirstPerson }; case 0x41 : return { - name : 'R3.System.Animation', - runtime : R3.Component.DEFAULT_RUNTIME, - constructor : R3.System.Animation, - apiConstructor : R3.API.System + name : 'R3.Renderer.D3.Target', + runtime : R3.Component.GRAPHICS_RUNTIME, + constructor : R3.Renderer.D3.Target, + apiConstructor : R3.API.Renderer.D3.Target }; case 0x42 : return { - name : 'R3.System.CustomCode', + name : 'R3.Sphere', runtime : R3.Component.DEFAULT_RUNTIME, - constructor : R3.System.CustomCode, - apiConstructor : R3.API.System + constructor : R3.Sphere, + apiConstructor : R3.API.Sphere }; case 0x43 : return { name : 'R3.System.GUI', @@ -1436,7 +1460,7 @@ R3.Component.GetComponentInfo = function(number) { /** * Returns the runtime friendly name * @param runtime - * @returns {*} + * @returns string * @constructor */ R3.Component.GetRuntimeName = function(runtime) { @@ -1482,6 +1506,22 @@ R3.Component.GetComponentName = function(componentType) { return 'unused'; }; +/** + * Gets a friendly name for the component + * @param componentType + * @returns {string} + * @constructor + */ +R3.Component.GetComponentFriendlyName = function(componentType) { + + var name = R3.Component.GetComponentName(componentType); + + name = name.replace('R3.D3.',''); + name = name.replace('.', ' '); + + return name; +}; + /** * @return {null || Object} */ @@ -1495,6 +1535,470 @@ R3.Component.GetComponentRuntime = function(componentType) { return null; }; +/** + * Returns the component type based on the constructor + * @returns {number} + * @constructor + */ +R3.Component.prototype.getComponentType = function() { + + if (this instanceof R3.Box3) { + return R3.Component.BOX3; + } + if (this instanceof R3.Canvas) { + return R3.Component.CANVAS; + } + if (this instanceof R3.Clock) { + return R3.Component.CLOCK; + } + if (this instanceof R3.Controls.D3.Orbit) { + return R3.Component.CONTROLS_ORBIT; + } + if (this instanceof R3.Controls.D3.FirstPerson) { + return R3.Component.CONTROLS_FIRST_PERSON; + } + if (this instanceof R3.Controls.D3.Editor) { + return R3.Component.CONTROLS_EDITOR; + } + if (this instanceof R3.Controls.Keyboard) { + return R3.Component.CONTROLS_KEYBOARD; + } + if (this instanceof R3.Controls.Mouse) { + return R3.Component.CONTROLS_MOUSE; + } + if (this instanceof R3.Controls.Touch) { + return R3.Component.CONTROLS_TOUCH; + } + if (this instanceof R3.Curve.Path.D2.Shape) { + return R3.Component.CURVE_PATH_D2_SHAPE; + } + if (this instanceof R3.Curve.Path.D2) { + return R3.Component.CURVE_PATH_D2; + } + if (this instanceof R3.Curve.Path) { + return R3.Component.CURVE_PATH; + } + if (this instanceof R3.Curve) { + return R3.Component.CURVE; + } + if (this instanceof R3.CustomCode) { + return R3.Component.CUSTOM_CODE; + } + if (this instanceof R3.D3.Animation) { + return R3.Component.ANIMATION; + } + if (this instanceof R3.D3.Object) { + return R3.Component.OBJECT; + } + if (this instanceof R3.D3.Audio) { + return R3.Component.AUDIO; + } + if (this instanceof R3.D3.Bone) { + return R3.Component.BONE; + } + if (this instanceof R3.D3.Broadphase) { + return R3.Component.BROADPHASE; + } + if (this instanceof R3.D3.Camera.Cube) { + return R3.Component.CAMERA_CUBE; + } + if (this instanceof R3.D3.Camera.Orthographic) { + return R3.Component.CAMERA_ORTHOGRAPHIC; + } + if (this instanceof R3.D3.Camera.Perspective) { + return R3.Component.CAMERA_PERSPECTIVE; + } + if (this instanceof R3.D3.Camera.Perspective.Stereo) { + return R3.Component.CAMERA_PERSPECTIVE_STEREO; + } + if (this instanceof R3.D3.Composer) { + return R3.Component.COMPOSER; + } + if (this instanceof R3.D3.Effect.Anaglyph) { + return R3.Component.EFFECT_ANAGLYPH; + } + if (this instanceof R3.D3.Effect.Parallax) { + return R3.Component.EFFECT_PARALLAX; + } + if (this instanceof R3.D3.Effect.Stereo) { + return R3.Component.EFFECT_STEREO; + } + if (this instanceof R3.D3.Fog) { + return R3.Component.FOG; + } + if (this instanceof R3.D3.Font) { + return R3.Component.FONT; + } + if (this instanceof R3.D3.FrictionContactMaterial) { + return R3.Component.FRICTION_CONTACT_MATERIAL; + } + if (this instanceof R3.D3.FrictionMaterial) { + return R3.Component.FRICTION_MATERIAL; + } + if (this instanceof R3.D3.Geometry.Buffer.Box) { + return R3.Component.GEOMETRY_BUFFER_BOX; + } + if (this instanceof R3.D3.Geometry.Buffer.Circle) { + return R3.Component.GEOMETRY_BUFFER_CIRCLE; + } + if (this instanceof R3.D3.Geometry.Buffer.Cone) { + return R3.Component.GEOMETRY_BUFFER_CONE; + } + if (this instanceof R3.D3.Geometry.Buffer.Cylinder) { + return R3.Component.GEOMETRY_BUFFER_CYLINDER; + } + if (this instanceof R3.D3.Geometry.Buffer.Dodecahedron) { + return R3.Component.GEOMETRY_BUFFER_DODECAHEDRON; + } + if (this instanceof R3.D3.Geometry.Buffer.Extrude) { + return R3.Component.GEOMETRY_BUFFER_EXTRUDE; + } + if (this instanceof R3.D3.Geometry.Buffer.Icosahedron) { + return R3.Component.GEOMETRY_BUFFER_ICOSAHEDRON; + } + if (this instanceof R3.D3.Geometry.Buffer.Instanced) { + return R3.Component.GEOMETRY_BUFFER_INSTANCED; + } + if (this instanceof R3.D3.Geometry.Buffer.Lathe) { + return R3.Component.GEOMETRY_BUFFER_LATHE; + } + if (this instanceof R3.D3.Geometry.Buffer.Octahedron) { + return R3.Component.GEOMETRY_BUFFER_OCTAHEDRON; + } + if (this instanceof R3.D3.Geometry.Buffer.Parametric) { + return R3.Component.GEOMETRY_BUFFER_PARAMETRIC; + } + if (this instanceof R3.D3.Geometry.Buffer.Plane) { + return R3.Component.GEOMETRY_BUFFER_PLANE; + } + if (this instanceof R3.D3.Geometry.Buffer.Polyhedron) { + return R3.Component.GEOMETRY_BUFFER_POLYHEDRON; + } + if (this instanceof R3.D3.Geometry.Buffer.Ring) { + return R3.Component.GEOMETRY_BUFFER_RING; + } + if (this instanceof R3.D3.Geometry.Buffer.Shape) { + return R3.Component.GEOMETRY_BUFFER_SHAPE; + } + if (this instanceof R3.D3.Geometry.Buffer.Sphere) { + return R3.Component.GEOMETRY_BUFFER_SPHERE; + } + if (this instanceof R3.D3.Geometry.Buffer.Tetrahedron) { + return R3.Component.GEOMETRY_BUFFER_TETRAHEDRON; + } + if (this instanceof R3.D3.Geometry.Buffer.Text) { + return R3.Component.GEOMETRY_BUFFER_TEXT; + } + if (this instanceof R3.D3.Geometry.Buffer.Torus) { + return R3.Component.GEOMETRY_BUFFER_TORUS_KNOT; + } + if (this instanceof R3.D3.Geometry.Buffer.TorusKnot) { + return R3.Component.GEOMETRY_BUFFER_TORUS_KNOT; + } + if (this instanceof R3.D3.Geometry.Buffer.Tube) { + return R3.Component.GEOMETRY_BUFFER_TUBE; + } + if (this instanceof R3.D3.Geometry.Buffer) { + return R3.Component.GEOMETRY_BUFFER; + } + if (this instanceof R3.D3.Geometry.Normal.Box) { + return R3.Component.GEOMETRY_NORMAL_BOX; + } + if (this instanceof R3.D3.Geometry.Normal.Circle) { + return R3.Component.GEOMETRY_NORMAL_CIRCLE; + } + if (this instanceof R3.D3.Geometry.Normal.Cone) { + return R3.Component.GEOMETRY_NORMAL_CONE; + } + if (this instanceof R3.D3.Geometry.Normal.Cylinder) { + return R3.Component.GEOMETRY_NORMAL_CYLINDER; + } + if (this instanceof R3.D3.Geometry.Normal.Dodecahedron) { + return R3.Component.GEOMETRY_NORMAL_DODECAHEDRON; + } + if (this instanceof R3.D3.Geometry.Normal.Edges) { + return R3.Component.GEOMETRY_NORMAL_EDGES; + } + if (this instanceof R3.D3.Geometry.Normal.Extrude) { + return R3.Component.GEOMETRY_NORMAL_EXTRUDE; + } + if (this instanceof R3.D3.Geometry.Normal.Icosahedron) { + return R3.Component.GEOMETRY_NORMAL_ICOSAHEDRON; + } + if (this instanceof R3.D3.Geometry.Normal.Lathe) { + return R3.Component.GEOMETRY_NORMAL_LATHE; + } + if (this instanceof R3.D3.Geometry.Normal.Octahedron) { + return R3.Component.GEOMETRY_NORMAL_OCTAHEDRON; + } + if (this instanceof R3.D3.Geometry.Normal.Parametric) { + return R3.Component.GEOMETRY_NORMAL_PARAMETRIC; + } + if (this instanceof R3.D3.Geometry.Normal.Plane) { + return R3.Component.GEOMETRY_NORMAL_PLANE; + } + if (this instanceof R3.D3.Geometry.Normal.Polyhedron) { + return R3.Component.GEOMETRY_NORMAL_POLYHEDRON; + } + if (this instanceof R3.D3.Geometry.Normal.Ring) { + return R3.Component.GEOMETRY_NORMAL_RING; + } + if (this instanceof R3.D3.Geometry.Normal.Shape) { + return R3.Component.GEOMETRY_NORMAL_SHAPE; + } + if (this instanceof R3.D3.Geometry.Normal.Sphere) { + return R3.Component.GEOMETRY_NORMAL_SPHERE; + } + if (this instanceof R3.D3.Geometry.Normal.Tetrahedron) { + return R3.Component.GEOMETRY_NORMAL_TETRAHEDRON; + } + if (this instanceof R3.D3.Geometry.Normal.Text) { + return R3.Component.GEOMETRY_NORMAL_TEXT; + } + if (this instanceof R3.D3.Geometry.Normal.Torus) { + return R3.Component.GEOMETRY_NORMAL_TORUS; + } + if (this instanceof R3.D3.Geometry.Normal.TorusKnot) { + return R3.Component.GEOMETRY_NORMAL_TORUS_KNOT; + } + if (this instanceof R3.D3.Geometry.Normal.Tube) { + return R3.Component.GEOMETRY_NORMAL_TUBE; + } + if (this instanceof R3.D3.Geometry.Normal.Wireframe) { + return R3.Component.GEOMETRY_NORMAL_WIREFRAME; + } + if (this instanceof R3.D3.Helper) { + return R3.Component.HELPER; + } + if (this instanceof R3.D3.Light.Ambient) { + return R3.Component.LIGHT_AMBIENT; + } + if (this instanceof R3.D3.Light.Directional) { + return R3.Component.LIGHT_DIRECTIONAL; + } + if (this instanceof R3.D3.Light.Hemisphere) { + return R3.Component.LIGHT_HEMISPHERE; + } + if (this instanceof R3.D3.Light.Point) { + return R3.Component.LIGHT_POINT; + } + if (this instanceof R3.D3.Light.RectArea) { + return R3.Component.LIGHT_RECT_AREA; + } + if (this instanceof R3.D3.Light.Spot) { + return R3.Component.LIGHT_SPOT; + } + if (this instanceof R3.D3.Material.Basic) { + return R3.Component.MATERIAL_BASIC; + } + if (this instanceof R3.D3.Material.Phong) { + return R3.Component.MATERIAL_PHONG; + } + if (this instanceof R3.D3.Material.Points) { + return R3.Component.MATERIAL_POINTS; + } + if (this instanceof R3.D3.Material.Shader) { + return R3.Component.MATERIAL_SHADER; + } + if (this instanceof R3.D3.Material.Shader.Raw) { + return R3.Component.MATERIAL_SHADER_RAW; + } + if (this instanceof R3.D3.Material.Standard) { + return R3.Component.MATERIAL_STANDARD; + } + if (this instanceof R3.D3.Mesh) { + return R3.Component.MESH; + } + if (this instanceof R3.D3.ParticleEngine) { + return R3.Component.PARTICLE_ENGINE; + } + if (this instanceof R3.D3.Particle) { + return R3.Component.PARTICLE; + } + if (this instanceof R3.D3.Pass.Bloom) { + return R3.Component.PASS_BLOOM; + } + if (this instanceof R3.D3.Pass.FXAA) { + return R3.Component.PASS_FXAA; + } + if (this instanceof R3.D3.Pass.Render) { + return R3.Component.PASS_RENDER; + } + if (this instanceof R3.D3.Pass.SSAO) { + return R3.Component.PASS_SSAO; + } + if (this instanceof R3.D3.PhysicsWorld) { + return R3.Component.PHYSICS_WORLD; + } + if (this instanceof R3.D3.Raycaster) { + return R3.Component.RAYCASTER; + } + if (this instanceof R3.D3.RaycastVehicle) { + return R3.Component.RAYCAST_VEHICLE; + } + if (this instanceof R3.D3.RaycastWheel) { + return R3.Component.RAYCAST_WHEEL; + } + if (this instanceof R3.D3.RenderTarget.Cube) { + return R3.Component.RENDER_TARGET_CUBE; + } + if (this instanceof R3.D3.RenderTarget) { + return R3.Component.RENDER_TARGET; + } + if (this instanceof R3.D3.RigidBody) { + return R3.Component.RIGID_BODY; + } + if (this instanceof R3.D3.Scene) { + return R3.Component.SCENE; + } + if (this instanceof R3.D3.Shader.Fragment) { + return R3.Component.SHADER_FRAGMENT; + } + if (this instanceof R3.D3.Shader.Vertex) { + return R3.Component.SHADER_VERTEX; + } + if (this instanceof R3.D3.Shader) { + return R3.Component.SHADER; + } + if (this instanceof R3.D3.Shadow.Directional) { + return R3.Component.SHADOW_DIRECTIONAL; + } + if (this instanceof R3.D3.Shadow.Spot) { + return R3.Component.SHADOW_SPOT; + } + if (this instanceof R3.D3.Shadow) { + return R3.Component.SHADOW; + } + if (this instanceof R3.D3.Shape.Box) { + return R3.Component.SHAPE_BOX; + } + if (this instanceof R3.D3.Shape.ConvexHull) { + return R3.Component.SHAPE_CONVEX_HULL; + } + if (this instanceof R3.D3.Shape.ConvexHull.Cylinder) { + return R3.Component.SHAPE_CONVEX_HULL_CYLINDER; + } + if (this instanceof R3.D3.Shape.HeightMap) { + return R3.Component.SHAPE_HEIGHT_MAP; + } + if (this instanceof R3.D3.Shape.Plane) { + return R3.Component.SHAPE_PLANE; + } + if (this instanceof R3.D3.Shape.Sphere) { + return R3.Component.SHAPE_SPHERE; + } + if (this instanceof R3.D3.Shape.TriMesh) { + return R3.Component.SHAPE_TRI_MESH; + } + if (this instanceof R3.D3.Shape) { + return R3.Component.SHAPE; + } + if (this instanceof R3.D3.Solver) { + return R3.Component.SOLVER; + } + if (this instanceof R3.D3.Spline) { + return R3.Component.SPLINE; + } + if (this instanceof R3.D3.Text) { + return R3.Component.TEXT; + } + if (this instanceof R3.D3.Texture.Canvas) { + return R3.Component.TEXTURE_CANVAS; + } + if (this instanceof R3.D3.Texture.Cube) { + return R3.Component.TEXTURE_CUBE; + } + if (this instanceof R3.D3.Texture.Image) { + return R3.Component.TEXTURE_IMAGE; + } + if (this instanceof R3.D3.Texture) { + return R3.Component.TEXTURE; + } + if (this instanceof R3.D3.Viewport.Fixed.Aspect) { + return R3.Component.VIEWPORT_FIXED_ASPECT; + } + if (this instanceof R3.D3.Viewport.Zoomed.Aspect) { + return R3.Component.VIEWPORT_ZOOMED_ASPECT; + } + if (this instanceof R3.D3.Viewport) { + return R3.Component.VIEWPORT; + } + if (this instanceof R3.DomElement) { + return R3.Component.DOM_ELEMENT; + } + if (this instanceof R3.DrawRange) { + return R3.Component.DRAW_RANGE; + } + if (this instanceof R3.Entity) { + return R3.Component.ENTITY; + } + if (this instanceof R3.EntityManager) { + return R3.Component.ENTITY_MANAGER; + } + if (this instanceof R3.Group) { + return R3.Component.GROUP; + } + if (this instanceof R3.GUI) { + return R3.Component.GUI; + } + if (this instanceof R3.GUIRuntime) { + return R3.Component.GUI_RUNTIME; + } + if (this instanceof R3.Image) { + return R3.Component.IMAGE; + } + if (this instanceof R3.Mouse) { + return R3.Component.MOUSE; + } + if (this instanceof R3.Plane) { + return R3.Component.PLANE; + } + if (this instanceof R3.Project) { + return R3.Component.PROJECT; + } + if (this instanceof R3.Renderer.D3.Canvas.Target) { + return R3.Component.RENDERER_D3_CANVAS_TARGET; + } + if (this instanceof R3.Renderer.D3.Canvas) { + return R3.Component.RENDERER_D3_CANVAS; + } + if (this instanceof R3.Renderer.D3.Target) { + return R3.Component.RENDERER_D3_TARGET; + } + if (this instanceof R3.Renderer.D2) { + return R3.Component.RENDERER_D2; + } + if (this instanceof R3.Renderer.D3) { + return R3.Component.RENDERER_D3; + } + if (this instanceof R3.Renderer) { + return R3.Component.RENDERER; + } + if (this instanceof R3.Server) { + return R3.Component.SERVER; + } + if (this instanceof R3.Socket.Cast) { + return R3.Component.SOCKET_CAST; + } + if (this instanceof R3.Socket.Receive) { + return R3.Component.SOCKET_RECEIVE; + } + if (this instanceof R3.Sphere) { + return R3.Component.SPHERE; + } + if (this instanceof R3.Stats) { + return R3.Component.STATS; + } + if (this instanceof R3.User) { + return R3.Component.USER; + } + if (this instanceof R3.Video) { + return R3.Component.VIDEO; + } + + console.warn('Component Type not Registered' + this); +}; + /** * @return {null || Object} @@ -1543,7 +2047,7 @@ R3.Component.prototype.getChildrenComponents = function() { this.buildIdToObject(); Object.keys(this.idToObject).map( - function (objectId) { + function(objectId) { if (this.id !== objectId) { components.push(this.idToObject[objectId]); } @@ -1621,7 +2125,7 @@ R3.Component.prototype.buildIdToObject = function() { * Remove null objects (can happen) */ this[property] = this[property].filter( - function (object) { + function(object) { if (object === null) { console.log('null object found and removed'); return false; @@ -1631,7 +2135,7 @@ R3.Component.prototype.buildIdToObject = function() { ); this[property].map( - function (object) { + function(object) { this.processComponent(object); }.bind(this) ); @@ -1645,7 +2149,7 @@ R3.Component.prototype.buildIdToObject = function() { if (this instanceof R3.D3.Scene) { if (!this.storeClones) { this.clones.map( - function (clone) { + function(clone) { if (this.idToObject.hasOwnProperty(clone.id)) { delete this.idToObject[clone.id]; } @@ -1723,8 +2227,8 @@ R3.Component.prototype.replace = function(componentType) { } ); - if (this.parentEntity && this.parentEntity.loaded) { - this.parentEntity.addComponent(replacement); + if (this.parent && this.parent.loaded) { + this.parent.addComponent(replacement); } this.remove(); @@ -1757,7 +2261,7 @@ R3.Component.prototype.clone = function() { } ); - runtimeComponent.parentEntity = null; + runtimeComponent.parent = null; return runtimeComponent; }; @@ -1896,7 +2400,7 @@ R3.Component.prototype.save = function(remote) { toSave.push(apiObject); - this.publish( + this.emit( R3.Event.SAVE_COMPONENT, { apiObject: apiObject, @@ -1917,7 +2421,7 @@ R3.Component.prototype.save = function(remote) { /** * @return {null|Object} */ -R3.Component.GetRuntimeObject = function(runtimeInfo) { +R3.Component.GetRuntimeObject = function(info) { var runtime = null; @@ -1929,55 +2433,57 @@ R3.Component.GetRuntimeObject = function(runtimeInfo) { } ); - if (runtimeInfo === R3.Component.GRAPHICS_RUNTIME) { + if (info.runtime === R3.Component.GRAPHICS_RUNTIME) { if (R3.Utils.UndefinedOrNull(runtime.graphics)) { - console.warn('no runtime graphics'); + console.warn('no runtime graphics: ', info); return null; } return runtime.graphics; - } else if (runtimeInfo === R3.Component.PHYSICS_RUNTIME) { + } else if (info.runtime === R3.Component.PHYSICS_RUNTIME) { if (R3.Utils.UndefinedOrNull(runtime.physics)) { - console.warn('no runtime physics'); + console.warn('no runtime physics ', info); return null; } return runtime.physics; - } else if (runtimeInfo === R3.Component.GUI_RUNTIME) { + } else if (info.runtime === R3.Component.GUI_RUNTIME) { if (R3.Utils.UndefinedOrNull(runtime.gui)) { - console.warn('no runtime gui'); + console.warn('no runtime gui ', info); return null; } return runtime.gui; - } else if (runtimeInfo === R3.Component.SOCKET_RUNTIME) { + } else if (info.runtime === R3.Component.SOCKET_RUNTIME) { if (R3.Utils.UndefinedOrNull(runtime.sockets)) { - console.warn('no runtime sockets'); + console.warn('no runtime sockets ', info); return null; } return runtime.sockets; - } else if (runtimeInfo === R3.Component.STATISTICS_RUNTIME) { + } else if (info.runtime === R3.Component.STATISTICS_RUNTIME) { if (R3.Utils.UndefinedOrNull(runtime.statistics)) { - console.warn('no runtime statistics'); + console.warn('no runtime statistics ', info); return null; } return runtime.statistics; - } else if (runtimeInfo === R3.Component.DEFAULT_RUNTIME) { + } else if (info.runtime === R3.Component.DEFAULT_RUNTIME) { + + return null; } else { - console.log('unknown runtime object found : ' + info.runtime); + throw new Error('unknown runtime object found: ' + info); } return null; @@ -1989,7 +2495,7 @@ R3.Component.Construct = function(componentType) { var componentClass = info.constructor; - var runtime = R3.Component.GetRuntimeObject(info.runtime); + var runtime = R3.Component.GetRuntimeObject(info); if (runtime) { return new componentClass(runtime); @@ -2005,7 +2511,7 @@ R3.Component.ConstructFromObject = function(rawComponentObject) { var info = R3.Component.GetComponentInfo(rawComponentObject.componentType); - var runtime = R3.Component.GetRuntimeObject(info.runtime); + var runtime = R3.Component.GetRuntimeObject(info); if (runtime) { runtimeComponent = new info.constructor(runtime, rawComponentObject); diff --git a/src/r3-a-api-component.js b/src/r3-a-api-component.js deleted file mode 100644 index 36c2159..0000000 --- a/src/r3-a-api-component.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * API Component Interface - Do not construct objects of this type directly - * @param componentType - * @param parentEntity - * @constructor - */ -R3.API.Component = function( - componentType, - parentEntity -) { - this.componentType = componentType; - - if (R3.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; - } - this.parentEntity = parentEntity; -}; - -R3.API.Component.prototype.constructor = R3.API.Component; \ No newline at end of file diff --git a/src/r3-api-box3.js b/src/r3-api-box3.js index a16d2fd..2509dee 100644 --- a/src/r3-api-box3.js +++ b/src/r3-api-box3.js @@ -1,31 +1,29 @@ /** * R3.API.Box3 - * @param id - * @param name - * @param parentEntity + * @param apiComponent * @param min * @param max * @constructor */ -R3.API.Box3 = function ( - id, - name, - parentEntity, +R3.API.Box3 = function( + apiComponent, min, max ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); + if (R3.Utils.UndefinedOrNull(apiComponent)) { + apiComponent = {}; } - this.id = id; + this.apiComponent = apiComponent; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Box (' + id + ')'; - } - this.name = name; + R3.API.Component.call( + this, + this.apiComponent.parent, + this.apiComponent.id, + this.apiComponent.name + ); if (R3.Utils.UndefinedOrNull(min)) { - min = new R3.API.Vector3(0,0,0); + min = new R3.API.Vector3(); } this.min = min; @@ -33,12 +31,6 @@ R3.API.Box3 = function ( max = new R3.API.Vector3(1,1,1); } this.max = max; - - R3.API.Component.call( - this, - R3.Component.BOX3, - parentEntity - ) }; R3.API.Box3.prototype = Object.create(R3.API.Component.prototype); diff --git a/src/r3-api-canvas.js b/src/r3-api-canvas.js index e714e8e..4fcc67f 100644 --- a/src/r3-api-canvas.js +++ b/src/r3-api-canvas.js @@ -1,9 +1,6 @@ /** * R3.API.Canvas - * @param id - * @param name - * @param parentEntity - * @param parentTexture + * @param apiComponent * @param autoUpdateSize * @param width * @param height @@ -14,10 +11,7 @@ * @constructor */ R3.API.Canvas = function( - id, - name, - parentEntity, - parentTexture, + apiComponent, autoUpdateSize, width, height, @@ -26,20 +20,18 @@ R3.API.Canvas = function( texts, textBaseline ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Canvas (' + id + ')'; + if (R3.Utils.UndefinedOrNull(apiComponent)) { + apiComponent = {}; } - this.name = name; + this.apiComponent = apiComponent; - if (R3.Utils.UndefinedOrNull(parentTexture)) { - parentTexture = null; - } - this.parentTexture = parentTexture; + R3.API.Component.call( + this, + this.apiComponent.parent, + this.apiComponent.id, + this.apiComponent.name + ); if (R3.Utils.UndefinedOrNull(autoUpdateSize)) { autoUpdateSize = true; @@ -76,11 +68,6 @@ R3.API.Canvas = function( } this.textBaseline = textBaseline; - R3.API.Component.call( - this, - R3.Component.CANVAS, - parentEntity - ); }; R3.API.Canvas.prototype = Object.create(R3.API.Component.prototype); diff --git a/src/r3-api-clock.js b/src/r3-api-clock.js index 4a4e902..3639b8e 100644 --- a/src/r3-api-clock.js +++ b/src/r3-api-clock.js @@ -1,47 +1,15 @@ /** - * Raw Clock API object - should always correspond with the Clock Schema + * R3.API.Clock * @constructor - * @param id - * @param name - * @param parentEntity + * @param apiComponent */ R3.API.Clock = function( - id, - name, - parentEntity + apiComponent ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; + __API_COMPONENT_MACRO__ - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Clock (' + this.id + ')'; - } - this.name = name; - - R3.API.Component.call( - this, - R3.Component.CLOCK, - parentEntity - ); }; R3.API.Clock.prototype = Object.create(R3.API.Component.prototype); R3.API.Clock.prototype.constructor = R3.API.Clock; - -/** - * Creates an API camera from an Object camera - * @param objectClock - * @constructor - */ -R3.API.Clock.FromObject = function(objectClock) { - - return new R3.API.Clock( - objectClock.id, - objectClock.name, - objectClock.parentEntity - ); - -}; diff --git a/src/r3-api-color.js b/src/r3-api-color.js index 8fa9e86..785ef5d 100644 --- a/src/r3-api-color.js +++ b/src/r3-api-color.js @@ -1,13 +1,19 @@ /** * API Color + * @param parent * @param r * @param g * @param b * @param a * @constructor */ -R3.API.Color = function (r, g, b, a) { - +R3.API.Color = function( + r, + g, + b, + a +) { + if (R3.Utils.UndefinedOrNull(r)) { r = 1; } @@ -29,23 +35,3 @@ R3.API.Color = function (r, g, b, a) { this.a = a; }; - -/** - * Returns an API color from an Object color - * @param objectColor - * @constructor - */ -R3.API.Color.FromObject = function(objectColor) { - - if (R3.Utils.UndefinedOrNull(objectColor)){ - objectColor = {}; - } - - return new R3.API.Color( - objectColor.r, - objectColor.g, - objectColor.b, - objectColor.a - ); - -}; diff --git a/src/r3-api-controls-0.js b/src/r3-api-controls-0.js index 8995ccd..525b208 100644 --- a/src/r3-api-controls-0.js +++ b/src/r3-api-controls-0.js @@ -1,51 +1,48 @@ /** - * Raw Controls API object + * R3.API.Controls + * @param parent * @param id - * @param controlsType * @param name * @param canvas - * @param parentEntity - * @property controlsType * @constructor */ R3.API.Controls = function( + parent, id, name, - controlsType, - canvas, - parentEntity + canvas ) { + R3.API.Component.call( + this, + parent + ); + if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); } this.id = id; - if (R3.Utils.UndefinedOrNull(controlsType)) { - controlsType = R3.API.Controls.CONTROLS_TYPE_NONE; - } - this.controlsType = controlsType; - if (R3.Utils.UndefinedOrNull(name)) { name = 'Controls'; - switch (this.controlsType) { - case R3.API.Controls.CONTROLS_TYPE_TOUCH : + switch (this.componentType) { + case R3.Component.CONTROLS_TOUCH: name = 'Controls Touch'; break; - case R3.API.Controls.CONTROLS_TYPE_KEYBOARD : + case R3.Component.CONTROLS_KEYBOARD : name = 'Controls Keyboard'; break; - case R3.API.Controls.CONTROLS_TYPE_MOUSE : + case R3.Component.CONTROLS_MOUSE : name = 'Controls Mouse'; break; - case R3.API.Controls.CONTROLS_TYPE_EDITOR : + case R3.Component.CONTROLS_EDITOR : name = 'Controls Editor'; break; - case R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON : + case R3.Component.CONTROLS_FIRST_PERSON : name = 'Controls First Person'; break; - case R3.API.Controls.CONTROLS_TYPE_ORBIT : + case R3.Component.CONTROLS_ORBIT : name = 'Controls Orbit'; break; } @@ -58,61 +55,7 @@ R3.API.Controls = function( canvas = null; } this.canvas = canvas; - - R3.API.Component.call( - this, - R3.API.Controls.GetComponentType(this.controlsType), - parentEntity - ); }; R3.API.Controls.prototype = Object.create(R3.API.Component.prototype); R3.API.Controls.prototype.constructor = R3.API.Controls; - -R3.API.Controls.GetComponentType = function(controlsType) { - - var componentType = null; - - switch (controlsType) { - case R3.API.Controls.CONTROLS_TYPE_NONE : - componentType = R3.Component.CONTROLS; - break; - case R3.API.Controls.CONTROLS_TYPE_TOUCH : - componentType = R3.Component.CONTROLS_TOUCH; - break; - case R3.API.Controls.CONTROLS_TYPE_KEYBOARD : - componentType = R3.Component.CONTROLS_KEYBOARD; - break; - case R3.API.Controls.CONTROLS_TYPE_MOUSE : - componentType = R3.Component.CONTROLS_MOUSE; - break; - case R3.API.Controls.CONTROLS_TYPE_EDITOR : - componentType = R3.Component.CONTROLS_EDITOR; - break; - case R3.API.Controls.CONTROLS_TYPE_ORBIT : - componentType = R3.Component.CONTROLS_ORBIT; - break; - default : - throw new Error('unhandled controls type: ' + controlsType); - break; - } - - return componentType; -}; - -/** - * Controls Type - * @type {number} - */ -R3.API.Controls.CONTROLS_TYPE_NONE = 0x0; -R3.API.Controls.CONTROLS_TYPE_TOUCH = 0x1; -R3.API.Controls.CONTROLS_TYPE_KEYBOARD = 0x2; -R3.API.Controls.CONTROLS_TYPE_MOUSE = 0x3; -R3.API.Controls.CONTROLS_TYPE_EDITOR = 0x4; -R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON = 0x5; -R3.API.Controls.CONTROLS_TYPE_ORBIT = 0x6; - - -R3.API.Controls.D3 = function() {}; -R3.API.Controls.D3.prototype = Object.create(R3.API.Controls.prototype); -R3.API.Controls.D3.prototype.constructor = R3.API.Controls.D3; \ No newline at end of file diff --git a/src/r3-api-controls-d3-editor.js b/src/r3-api-controls-d3-editor.js index 18ed523..19f93ab 100644 --- a/src/r3-api-controls-d3-editor.js +++ b/src/r3-api-controls-d3-editor.js @@ -1,43 +1,28 @@ /** - * @param apiControls + * @param apiControlsD3 * @param raycaster - * @param camera * @constructor */ R3.API.Controls.D3.Editor = function( - apiControls, - raycaster, - camera + apiControlsD3, + raycaster ) { - if (R3.Utils.UndefinedOrNull(apiControls)) { - apiControls = { - controlsType : R3.API.Controls.CONTROLS_TYPE_EDITOR - }; + if (R3.Utils.UndefinedOrNull(apiControlsD3)) { + apiControlsD3 = {}; } - if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) { - apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_EDITOR; - } + R3.API.Controls.D3.call( + this, + apiControlsD3, + apiControlsD3.camera + ); if (R3.Utils.UndefinedOrNull(raycaster)) { raycaster = new R3.D3.API.Raycaster(); } this.raycaster = raycaster; - if (R3.Utils.UndefinedOrNull(camera)) { - camera = null; - } - this.camera = camera; - - R3.API.Controls.call( - this, - apiControls.id, - apiControls.name, - apiControls.controlsType, - apiControls.canvas, - apiControls.parentEntity - ); }; R3.API.Controls.D3.Editor.prototype = Object.create(R3.API.Controls.D3.prototype); diff --git a/src/r3-api-controls-d3-first-person.js b/src/r3-api-controls-d3-first-person.js index f8a2cb9..507e3f8 100644 --- a/src/r3-api-controls-d3-first-person.js +++ b/src/r3-api-controls-d3-first-person.js @@ -1,7 +1,6 @@ /** * R3.API.Controls.D3.FirstPerson - * @param apiControls - * @param camera + * @param apiControlsD3 * @param enabled * @param movementSpeed * @param lookSpeed @@ -19,8 +18,7 @@ * @constructor */ R3.API.Controls.D3.FirstPerson = function( - apiControls, - camera, + apiControlsD3, enabled, movementSpeed, lookSpeed, @@ -37,20 +35,15 @@ R3.API.Controls.D3.FirstPerson = function( autoSpeedFactor ) { - if (R3.Utils.UndefinedOrNull(apiControls)) { - apiControls = { - controlsType : R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON - }; + if (R3.Utils.UndefinedOrNull(apiControlsD3)) { + apiControlsD3 = {}; } - if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) { - apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_FIRST_PERSON; - } - - if (R3.Utils.UndefinedOrNull(camera)) { - camera = null; - } - this.camera = camera; + R3.API.Controls.D3.call( + this, + apiControlsD3, + apiControlsD3.camera + ); if (R3.Utils.UndefinedOrNull(enabled)) { enabled = true; @@ -122,14 +115,6 @@ R3.API.Controls.D3.FirstPerson = function( } this.autoSpeedFactor = autoSpeedFactor; - R3.API.Controls.call( - this, - apiControls.id, - apiControls.name, - apiControls.controlsType, - apiControls.canvas, - apiControls.parentEntity - ); }; R3.API.Controls.D3.FirstPerson.prototype = Object.create(R3.API.Controls.D3.prototype); diff --git a/src/r3-api-controls-d3-orbit.js b/src/r3-api-controls-d3-orbit.js index c6eb30f..e861f1f 100644 --- a/src/r3-api-controls-d3-orbit.js +++ b/src/r3-api-controls-d3-orbit.js @@ -1,13 +1,8 @@ /** * R3.API.Controls.D3.Orbit - * @param apiControls - * @param camera + * @param apiControlsD3 * @param target * @param enabled - * @param minDistance - * @param maxDistance - * @param minZoom - * @param maxZoom * @param minPolarAngle * @param maxPolarAngle * @param enableDamping @@ -24,8 +19,7 @@ * @constructor */ R3.API.Controls.D3.Orbit = function( - apiControls, - camera, + apiControlsD3, target, enabled, minPolarAngle, @@ -43,20 +37,15 @@ R3.API.Controls.D3.Orbit = function( enableKeys ) { - if (R3.Utils.UndefinedOrNull(apiControls)) { - apiControls = { - controlsType : R3.API.Controls.CONTROLS_TYPE_ORBIT - }; + if (R3.Utils.UndefinedOrNull(apiControlsD3)) { + apiControlsD3 = {}; } - if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) { - apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_ORBIT; - } - - if (R3.Utils.UndefinedOrNull(camera)) { - camera = null; - } - this.camera = camera; + R3.API.Controls.D3.call( + this, + apiControlsD3, + apiControlsD3.camera + ); if (R3.Utils.UndefinedOrNull(target)) { target = null; @@ -133,14 +122,6 @@ R3.API.Controls.D3.Orbit = function( } this.enableKeys = enableKeys; - R3.API.Controls.call( - this, - apiControls.id, - apiControls.name, - apiControls.controlsType, - apiControls.canvas, - apiControls.parentEntity - ); }; R3.API.Controls.D3.Orbit.prototype = Object.create(R3.API.Controls.D3.prototype); diff --git a/src/r3-api-controls-d3.js b/src/r3-api-controls-d3.js new file mode 100644 index 0000000..ee8ac6a --- /dev/null +++ b/src/r3-api-controls-d3.js @@ -0,0 +1,29 @@ +/** + * Raw Controls API object + * @constructor + */ +R3.API.Controls.D3 = function( + apiControls, + camera +) { + + if (R3.Utils.UndefinedOrNull(apiControls)) { + apiControls = {}; + } + + R3.API.Controls.call( + this, + apiControls.parent, + apiControls.id, + apiControls.name, + apiControls.canvas + ); + + if (R3.Utils.UndefinedOrNull(camera)) { + camera = null; + } + this.camera = camera; +}; + +R3.API.Controls.D3.prototype = Object.create(R3.API.Controls.prototype); +R3.API.Controls.D3.prototype.constructor = R3.API.Controls.D3; diff --git a/src/r3-api-controls-keyboard.js b/src/r3-api-controls-keyboard.js index 132fbeb..fb53411 100644 --- a/src/r3-api-controls-keyboard.js +++ b/src/r3-api-controls-keyboard.js @@ -5,24 +5,12 @@ R3.API.Controls.Keyboard = function( apiControls ) { - - if (R3.Utils.UndefinedOrNull(apiControls)) { - apiControls = { - controlsType : R3.API.Controls.CONTROLS_TYPE_KEYBOARD - }; - } - - if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) { - apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_KEYBOARD; - } - R3.API.Controls.call( this, + apiControls.parent, apiControls.id, apiControls.name, - apiControls.controlsType, - apiControls.canvas, - apiControls.parentEntity + apiControls.canvas ); }; diff --git a/src/r3-api-controls-mouse.js b/src/r3-api-controls-mouse.js index 2b46176..4cf067f 100644 --- a/src/r3-api-controls-mouse.js +++ b/src/r3-api-controls-mouse.js @@ -5,27 +5,14 @@ R3.API.Controls.Mouse = function( apiControls ) { - - if (R3.Utils.UndefinedOrNull(apiControls)) { - apiControls = { - controlsType : R3.API.Controls.CONTROLS_TYPE_MOUSE - }; - } - - if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) { - apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_MOUSE; - } - R3.API.Controls.call( this, + apiControls.parent, apiControls.id, apiControls.name, - apiControls.controlsType, - apiControls.canvas, - apiControls.parentEntity + apiControls.canvas ); }; R3.API.Controls.Mouse.prototype = Object.create(R3.API.Controls.prototype); R3.API.Controls.Mouse.prototype.constructor = R3.API.Controls.Mouse; - diff --git a/src/r3-api-controls-touch.js b/src/r3-api-controls-touch.js index bdedc7f..7f7db65 100644 --- a/src/r3-api-controls-touch.js +++ b/src/r3-api-controls-touch.js @@ -8,29 +8,19 @@ R3.API.Controls.Touch = function( sensitivity ) { - if (R3.Utils.UndefinedOrNull(apiControls)) { - apiControls = { - controlsType : R3.API.Controls.CONTROLS_TYPE_TOUCH - }; - } - - if (R3.Utils.UndefinedOrNull(apiControls.controlsType)) { - apiControls.controlsType = R3.API.Controls.CONTROLS_TYPE_TOUCH; - } + R3.API.Controls.call( + this, + apiControls.parent, + apiControls.id, + apiControls.name, + apiControls.canvas + ); if (R3.Utils.UndefinedOrNull(sensitivity)) { sensitivity = 5; } this.sensitivity = sensitivity; - R3.API.Controls.call( - this, - apiControls.id, - apiControls.name, - apiControls.controlsType, - apiControls.canvas, - apiControls.parentEntity - ); }; R3.API.Controls.Touch.prototype = Object.create(R3.API.Controls.prototype); diff --git a/src/r3-api-curve-a.js b/src/r3-api-curve-a.js index 0c804df..4a783da 100644 --- a/src/r3-api-curve-a.js +++ b/src/r3-api-curve-a.js @@ -3,22 +3,21 @@ * @param id * @param name * @param curveType - * @param parentEntity + * @param parent * @param arcLenghDivisions * @constructor */ -R3.API.Curve = function ( +R3.API.Curve = function( + parent, id, name, curveType, - parentEntity, arcLenghDivisions ) { - - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; + R3.API.Component.call( + this, + parent + ); if (R3.Utils.UndefinedOrNull(curveType)) { curveType = R3.API.Curve.CURVE_TYPE_NONE; @@ -50,7 +49,7 @@ R3.API.Curve = function ( R3.API.Component.call( this, R3.API.Curve.GetComponentType(this.curveType), - parentEntity + parent ); }; diff --git a/src/r3-api-curve-path-a.js b/src/r3-api-curve-path-a.js index e1f93a8..8b73e5f 100644 --- a/src/r3-api-curve-path-a.js +++ b/src/r3-api-curve-path-a.js @@ -5,7 +5,7 @@ * @param curves * @param autoClose */ -R3.API.Curve.Path = function ( +R3.API.Curve.Path = function( apiCurve, curves, autoClose @@ -35,7 +35,7 @@ R3.API.Curve.Path = function ( apiCurve.id, apiCurve.name, apiCurve.curveType, - apiCurve.parentEntity, + apiCurve.parent, apiCurve.arcLenghDivisions ); }; diff --git a/src/r3-api-curve-path-d2-a.js b/src/r3-api-curve-path-d2-a.js index e8f1cfc..f862c9e 100644 --- a/src/r3-api-curve-path-d2-a.js +++ b/src/r3-api-curve-path-d2-a.js @@ -4,7 +4,7 @@ * @param apiCurvePath * @param points */ -R3.API.Curve.Path.D2 = function ( +R3.API.Curve.Path.D2 = function( apiCurvePath, points ) { diff --git a/src/r3-api-curve-path-d2-shape.js b/src/r3-api-curve-path-d2-shape.js index bec2134..325c498 100644 --- a/src/r3-api-curve-path-d2-shape.js +++ b/src/r3-api-curve-path-d2-shape.js @@ -3,7 +3,7 @@ * @constructor * @param apiCurvePathD2 */ -R3.API.Curve.Path.D2.Shape = function ( +R3.API.Curve.Path.D2.Shape = function( apiCurvePathD2 ) { if (R3.Utils.UndefinedOrNull(apiCurvePathD2)) { diff --git a/src/r3-api-custom-code.js b/src/r3-api-custom-code.js index ad004b4..3a54f7b 100644 --- a/src/r3-api-custom-code.js +++ b/src/r3-api-custom-code.js @@ -4,15 +4,15 @@ * @param name * @param eventId * @param code - * @param parentEntity + * @param parent * @constructor */ -R3.API.CustomCode = function ( +R3.API.CustomCode = function( id, name, eventId, code, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); @@ -37,7 +37,7 @@ R3.API.CustomCode = function ( R3.API.Component.call( this, R3.Component.CUSTOM_CODE, - parentEntity + parent ); }; diff --git a/src/r3-api-dom-element.js b/src/r3-api-dom-element.js index 5e570ab..ddd5d9f 100644 --- a/src/r3-api-dom-element.js +++ b/src/r3-api-dom-element.js @@ -3,14 +3,14 @@ * @param id * @param name * @param domElementId - * @param parentEntity + * @param parent * @constructor */ R3.API.DomElement = function( id, name, domElementId, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -31,7 +31,7 @@ R3.API.DomElement = function( R3.API.Component.call( this, R3.Component.DOM_ELEMENT, - parentEntity + parent ); }; @@ -43,11 +43,11 @@ R3.API.DomElement.prototype.constructor = R3.API.DomElement; * @param objectDomElement * @constructor */ -R3.API.DomElement.FromObject = function (objectDomElement) { +R3.API.DomElement.FromObject = function(objectDomElement) { return new R3.API.DomElement( objectDomElement.id, objectDomElement.name, objectDomElement.domElementId, - objectDomElement.parentEntity + objectDomElement.parent ) }; diff --git a/src/r3-api-draw-range.js b/src/r3-api-draw-range.js index 70516bf..fa868b2 100644 --- a/src/r3-api-draw-range.js +++ b/src/r3-api-draw-range.js @@ -3,14 +3,14 @@ * @constructor * @param id * @param name - * @param parentEntity + * @param parent * @param start * @param count */ -R3.API.DrawRange = function ( +R3.API.DrawRange = function( id, name, - parentEntity, + parent, start, count ) { @@ -37,7 +37,7 @@ R3.API.DrawRange = function ( R3.API.Component.call( this, R3.Component.DRAW_RANGE, - parentEntity + parent ) }; diff --git a/src/r3-api-entity-manager.js b/src/r3-api-entity-manager.js index 9398d21..b931ab8 100644 --- a/src/r3-api-entity-manager.js +++ b/src/r3-api-entity-manager.js @@ -5,14 +5,14 @@ * @param name * @param entities R3.API.Entity[] * @param defaultEntity - * @param parentEntity + * @param parent */ R3.API.EntityManager = function( id, name, entities, defaultEntity, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); @@ -37,7 +37,7 @@ R3.API.EntityManager = function( R3.API.Component.call( this, R3.Component.ENTITY_MANAGER, - parentEntity + parent ); }; @@ -52,7 +52,7 @@ R3.API.EntityManager.prototype.constructor = R3.API.EntityManager; R3.API.EntityManager.FromObject = function(objectEntityManager) { var apiEntities = objectEntityManager.entities.map( - function (objectEntity) { + function(objectEntity) { return R3.API.Entity.FromObject(objectEntity); } ); @@ -62,6 +62,6 @@ R3.API.EntityManager.FromObject = function(objectEntityManager) { objectEntityManager.name, apiEntities, objectEntityManager.defaultEntity, - objectEntityManager.parentEntity + objectEntityManager.parent ); }; diff --git a/src/r3-api-entity.js b/src/r3-api-entity.js index 8c33190..9a7bcad 100644 --- a/src/r3-api-entity.js +++ b/src/r3-api-entity.js @@ -3,14 +3,14 @@ * @param id * @param name * @param components R3.Component[] - * @param parentEntity R3.Entity + * @param parent R3.Entity * @constructor */ R3.API.Entity = function( id, name, components, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); @@ -27,10 +27,16 @@ R3.API.Entity = function( } this.components = components; + var componentType = R3.Component.ENTITY; + + if (this instanceof R3.API.Project) { + componentType = R3.Component.PROJECT; + } + R3.API.Component.call( this, - R3.Component.ENTITY, - parentEntity + componentType, + parent ); }; @@ -47,6 +53,6 @@ R3.API.Entity.FromObject = function(objectEntity) { objectEntity.id, objectEntity.name, objectEntity.components, - objectEntity.parentEntity + objectEntity.parent ) }; diff --git a/src/r3-api-group.js b/src/r3-api-group.js index 6d0dd7e..dd2180c 100644 --- a/src/r3-api-group.js +++ b/src/r3-api-group.js @@ -3,15 +3,15 @@ * @constructor * @param id * @param name - * @param parentEntity + * @param parent * @param start * @param count * @param materialIndex */ -R3.API.Group = function ( +R3.API.Group = function( id, name, - parentEntity, + parent, start, count, materialIndex @@ -44,7 +44,7 @@ R3.API.Group = function ( R3.API.Component.call( this, R3.Component.GROUP, - parentEntity + parent ) }; diff --git a/src/r3-api-gui.js b/src/r3-api-gui.js index 2e6277f..d6a3b1d 100644 --- a/src/r3-api-gui.js +++ b/src/r3-api-gui.js @@ -3,14 +3,14 @@ * @param id * @param name * @param domElement - * @param parentEntity + * @param parent * @constructor */ R3.API.GUI = function( id, name, domElement, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -31,7 +31,7 @@ R3.API.GUI = function( R3.API.Component.call( this, R3.Component.GUI, - parentEntity + parent ); }; @@ -58,7 +58,7 @@ R3.API.GUI.FromObject = function(objectGUI) { objectGUI.id, objectGUI.name, apiDomElement, - objectGUI.parentEntity + objectGUI.parent ); }; diff --git a/src/r3-api-image.js b/src/r3-api-image.js index 87a6a9e..0405ee1 100644 --- a/src/r3-api-image.js +++ b/src/r3-api-image.js @@ -2,7 +2,7 @@ * R3.API.Image * @param id * @param name - * @param parentEntity + * @param parent * @param parentTexture * @param fileName * @param extension @@ -16,7 +16,7 @@ R3.API.Image = function( id, name, - parentEntity, + parent, parentTexture, fileName, extension, @@ -92,7 +92,7 @@ R3.API.Image = function( R3.API.Component.call( this, R3.Component.IMAGE, - parentEntity + parent ); }; diff --git a/src/r3-api-matrix4.js b/src/r3-api-matrix4.js index a7db1d5..44ce5b8 100644 --- a/src/r3-api-matrix4.js +++ b/src/r3-api-matrix4.js @@ -83,14 +83,14 @@ R3.API.Matrix4.FromObject = function(objectMatrix) { } }; -R3.API.Matrix4.prototype.rotationMatrixX = function (radians) { +R3.API.Matrix4.prototype.rotationMatrixX = function(radians) { this.identity(); this.rows[1] = new R3.API.Vector4(0, Math.cos(radians), -1 * Math.sin(radians), 0); this.rows[2] = new R3.API.Vector4(0, Math.sin(radians), Math.cos(radians), 0); return this; }; -R3.API.Matrix4.prototype.rotationMatrixY = function (radians) { +R3.API.Matrix4.prototype.rotationMatrixY = function(radians) { this.identity(); this.rows[0] = new R3.API.Vector4( Math.cos(radians), @@ -107,32 +107,32 @@ R3.API.Matrix4.prototype.rotationMatrixY = function (radians) { return this; }; -R3.API.Matrix4.prototype.rotationMatrixZ = function (radians) { +R3.API.Matrix4.prototype.rotationMatrixZ = function(radians) { this.identity(); this.rows[0] = new R3.API.Vector4(Math.cos(radians), -1 * Math.sin(radians), 0, 0); this.rows[1] = new R3.API.Vector4(Math.sin(radians), Math.cos(radians), 0, 0); return this; }; -R3.API.Matrix4.prototype.rotateX = function (radians, point) { +R3.API.Matrix4.prototype.rotateX = function(radians, point) { this.identity(); this.rotationMatrixX(radians); return this.multiply(point); }; -R3.API.Matrix4.prototype.rotateY = function (radians, point) { +R3.API.Matrix4.prototype.rotateY = function(radians, point) { this.identity(); this.rotationMatrixY(radians); return this.multiply(point); }; -R3.API.Matrix4.prototype.rotateZ = function (radians, point) { +R3.API.Matrix4.prototype.rotateZ = function(radians, point) { this.identity(); this.rotationMatrixZ(radians); return this.multiply(point); }; -R3.API.Matrix4.prototype.multiply = function (mvp) { +R3.API.Matrix4.prototype.multiply = function(mvp) { if (mvp instanceof R3.API.Quaternion || mvp instanceof R3.API.Vector4) { return new R3.API.Quaternion( this.rows[0].x * mvp.x + this.rows[0].y * mvp.y + this.rows[0].z * mvp.z + this.rows[0].w * mvp.w, @@ -149,7 +149,7 @@ R3.API.Matrix4.prototype.multiply = function (mvp) { } }; -R3.API.Matrix4.prototype.identity = function () { +R3.API.Matrix4.prototype.identity = function() { this.rows = [ new R3.API.Vector4(1, 0, 0, 0), new R3.API.Vector4(0, 1, 0, 0), diff --git a/src/r3-api-mouse.js b/src/r3-api-mouse.js index ebe6f49..e37e16d 100644 --- a/src/r3-api-mouse.js +++ b/src/r3-api-mouse.js @@ -2,7 +2,7 @@ * API Mouse * @param id * @param name - * @param parentEntity + * @param parent * @param x * @param y * @constructor @@ -10,7 +10,7 @@ R3.API.Mouse = function( id, name, - parentEntity, + parent, x, y ) { @@ -37,7 +37,7 @@ R3.API.Mouse = function( R3.API.Component.call( this, R3.Component.MOUSE, - parentEntity + parent ); }; diff --git a/src/r3-api-plane.js b/src/r3-api-plane.js index d6257a1..26896f2 100644 --- a/src/r3-api-plane.js +++ b/src/r3-api-plane.js @@ -1,9 +1,9 @@ -R3.API.Plane = function ( +R3.API.Plane = function( id, name, normal, constant, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -29,7 +29,7 @@ R3.API.Plane = function ( R3.API.Component.call( this, R3.Component.PLANE, - parentEntity + parent ); }; @@ -42,12 +42,12 @@ R3.API.Plane.prototype.constructor = R3.API.Plane; * @param objectPlane * @constructor */ -R3.API.Plane.FromObject = function (objectPlane) { +R3.API.Plane.FromObject = function(objectPlane) { return new R3.API.Plane( objectPlane.id, objectPlane.name, R3.API.Vector3.FromObject(objectPlane.normal), objectPlane.constant, - objectPlane.parentEntity + objectPlane.parent ); }; diff --git a/src/r3-api-project.js b/src/r3-api-project.js index 6f9995f..1fadaaa 100644 --- a/src/r3-api-project.js +++ b/src/r3-api-project.js @@ -2,28 +2,24 @@ * API Project * @param id * @param name - * @param parentEntity + * @param parent * @param users * @param isPublic * @param entities * @param renderers * @param cameras - * @param cameraIndex - * @param controls * @param mode * @constructor */ R3.API.Project = function( id, name, - parentEntity, + parent, users, isPublic, entities, renderers, cameras, - cameraIndex, - controls, mode ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -71,38 +67,25 @@ R3.API.Project = function( } this.cameras = cameras; - if (R3.Utils.UndefinedOrNull(cameraIndex)) { - cameraIndex = R3.API.Project.CAMERA_INDEX_EDIT; - } - this.cameraIndex = cameraIndex; - - if (R3.Utils.UndefinedOrNull(controls)) { - controls = new R3.API.Controls.D3.Orbit( - { - canvas: this.renderer.canvas - }, - this.cameras[this.cameraIndex] - ) - } - this.controls = controls; - if (R3.Utils.UndefinedOrNull(mode)) { - mode = R3.API.Project.DEFAULT_MODE_EDIT; + mode = R3.API.Project.APPLICATION_MODE_EDIT; } this.mode = mode; R3.API.Component.call( this, - R3.Component.PROJECT, - parentEntity + this.id, + this.name, + this.components, + this.parent ); }; R3.API.Project.prototype = Object.create(R3.API.Component.prototype); R3.API.Project.prototype.constructor = R3.API.Project; -R3.API.Project.DEFAULT_MODE_RUN = 0x1; -R3.API.Project.DEFAULT_MODE_EDIT = 0x2; +R3.API.Project.APPLICATION_MODE_RUN = 0x1; +R3.API.Project.APPLICATION_MODE_EDIT = 0x2; R3.API.Project.CAMERA_INDEX_EDIT = 0x0; R3.API.Project.CAMERA_INDEX_RUN = 0x1; \ No newline at end of file diff --git a/src/r3-api-quaternion-a.js b/src/r3-api-quaternion-a.js index 5a35d23..20606e3 100644 --- a/src/r3-api-quaternion-a.js +++ b/src/r3-api-quaternion-a.js @@ -8,7 +8,7 @@ * @param angle * @constructor */ -R3.API.Quaternion = function ( +R3.API.Quaternion = function( x, y, z, @@ -48,14 +48,14 @@ R3.API.Quaternion = function ( this.angle = angle; }; -R3.API.Quaternion.prototype.translate = function (v) { +R3.API.Quaternion.prototype.translate = function(v) { this.x += v.x; this.y += v.y; this.z += v.z; return this; }; -R3.API.Quaternion.prototype.copy = function () { +R3.API.Quaternion.prototype.copy = function() { return new R3.API.Quaternion( this.x, this.y, @@ -67,7 +67,7 @@ R3.API.Quaternion.prototype.copy = function () { /** * Note, this normalize function leaves 'w' component untouched */ -R3.API.Quaternion.prototype.normalize = function () { +R3.API.Quaternion.prototype.normalize = function() { var EPSILON = 0.000001; @@ -84,7 +84,7 @@ R3.API.Quaternion.prototype.normalize = function () { this.z *= invLength; }; -R3.API.Quaternion.prototype.multiply = function (q) { +R3.API.Quaternion.prototype.multiply = function(q) { var x, y, z, w; var a = q; @@ -124,7 +124,7 @@ R3.API.Quaternion.prototype.multiply = function (q) { } }; -R3.API.Quaternion.prototype.setFromAngle = function (angle) { +R3.API.Quaternion.prototype.setFromAngle = function(angle) { this.instance.setFromAxisAngle(this.axis.instance, angle); @@ -136,7 +136,7 @@ R3.API.Quaternion.prototype.setFromAngle = function (angle) { return this; }; -R3.API.Quaternion.prototype.subtract = function (v) { +R3.API.Quaternion.prototype.subtract = function(v) { if (v instanceof R3.API.Vector3) { this.x -= v.x; @@ -154,7 +154,7 @@ R3.API.Quaternion.prototype.subtract = function (v) { return this; }; -R3.API.Quaternion.prototype.magnitude = function () { +R3.API.Quaternion.prototype.magnitude = function() { return Math.sqrt( (this.x * this.x) + (this.y * this.y) + @@ -163,7 +163,7 @@ R3.API.Quaternion.prototype.magnitude = function () { ); }; -R3.API.Quaternion.prototype.normalize = function () { +R3.API.Quaternion.prototype.normalize = function() { var magnitude = this.magnitude(); @@ -199,7 +199,7 @@ R3.API.Quaternion.prototype.setFromRotationMatrix = function(matrix4) { * @param t * @returns {R3.Quaternion} */ -R3.API.Quaternion.prototype.slerp = function (quaternion, t) { +R3.API.Quaternion.prototype.slerp = function(quaternion, t) { this.updateInstance(); @@ -218,7 +218,7 @@ R3.API.Quaternion.prototype.slerp = function (quaternion, t) { * @param objectQuaternion * @constructor */ -R3.API.Quaternion.FromObject = function (objectQuaternion) { +R3.API.Quaternion.FromObject = function(objectQuaternion) { var apiAxis = null; diff --git a/src/r3-api-quaternion-points.js b/src/r3-api-quaternion-points.js index 5dd94bb..cf37b74 100644 --- a/src/r3-api-quaternion-points.js +++ b/src/r3-api-quaternion-points.js @@ -1,8 +1,8 @@ -R3.API.Quaternion.Points = function () { +R3.API.Quaternion.Points = function() { this.vectors = []; }; -R3.API.Quaternion.Points.prototype.add = function (vector) { +R3.API.Quaternion.Points.prototype.add = function(vector) { if (vector instanceof R3.API.Vector3) { vector = new R3.API.Quaternion( @@ -23,7 +23,7 @@ R3.API.Quaternion.Points.prototype.add = function (vector) { return this; }; -R3.API.Quaternion.Points.prototype.copy = function () { +R3.API.Quaternion.Points.prototype.copy = function() { var vectors = []; @@ -34,7 +34,7 @@ R3.API.Quaternion.Points.prototype.copy = function () { return vectors; }; -R3.API.Quaternion.Points.prototype.maximizeXDistance = function (grain) { +R3.API.Quaternion.Points.prototype.maximizeXDistance = function(grain) { // console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2)); @@ -79,7 +79,7 @@ R3.API.Quaternion.Points.prototype.maximizeXDistance = function (grain) { }; -R3.API.Quaternion.Points.prototype.maximizeYDistance = function (grain) { +R3.API.Quaternion.Points.prototype.maximizeYDistance = function(grain) { // console.log("vectors (before): " + JSON.stringify(this.vectors, null, 2)); @@ -124,7 +124,7 @@ R3.API.Quaternion.Points.prototype.maximizeYDistance = function (grain) { }; -R3.API.Quaternion.Points.prototype.lookAt = function (at, up) { +R3.API.Quaternion.Points.prototype.lookAt = function(at, up) { var polyCenter = this.average(); @@ -145,7 +145,7 @@ R3.API.Quaternion.Points.prototype.lookAt = function (at, up) { } }; -R3.API.Quaternion.Points.prototype.distances = function () { +R3.API.Quaternion.Points.prototype.distances = function() { var minX = this.vectors[0].x; var minY = this.vectors[0].y; @@ -184,7 +184,7 @@ R3.API.Quaternion.Points.prototype.distances = function () { ) }; -R3.API.Quaternion.Points.prototype.average = function () { +R3.API.Quaternion.Points.prototype.average = function() { var averageX = 0; var averageY = 0; var averageZ = 0; @@ -202,7 +202,7 @@ R3.API.Quaternion.Points.prototype.average = function () { ); }; -R3.API.Quaternion.Points.prototype.negate = function () { +R3.API.Quaternion.Points.prototype.negate = function() { for (var i = 0; i < this.vectors.length; i++) { this.vectors[i].x *= -1; @@ -214,7 +214,7 @@ R3.API.Quaternion.Points.prototype.negate = function () { }; -R3.API.Quaternion.Points.prototype.toOrigin = function () { +R3.API.Quaternion.Points.prototype.toOrigin = function() { var distanceFromOrigin = this.average().negate(); diff --git a/src/r3-api-renderer-a.js b/src/r3-api-renderer-a.js index f6f201b..fd84a81 100644 --- a/src/r3-api-renderer-a.js +++ b/src/r3-api-renderer-a.js @@ -3,22 +3,15 @@ * @param id * @param name * @param rendererType - * @param parentEntity - * @param width - * @param height - * @param offset + * @param parent * @param canvas * @constructor */ -R3.API.Renderer = function ( +R3.API.Renderer = function( id, name, - rendererType, - parentEntity, - width, - height, - offset, - canvas + parent, + rendererType ) { if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); @@ -51,30 +44,10 @@ R3.API.Renderer = function ( } this.name = name; - if (R3.Utils.UndefinedOrNull(width)) { - width = 1; - } - this.width = width; - - if (R3.Utils.UndefinedOrNull(height)) { - height = 1; - } - this.height = height; - - if (R3.Utils.UndefinedOrNull(offset)) { - offset = new R3.API.Vector2(0,0); - } - this.offset = offset; - - if (R3.Utils.UndefinedOrNull(canvas)) { - canvas = new R3.API.Canvas(); - } - this.canvas = canvas; - R3.API.Component.call( this, R3.API.Renderer.GetComponentType(this.rendererType), - parentEntity + parent ); }; @@ -93,8 +66,14 @@ R3.API.Renderer.GetComponentType = function(rendererType) { case R3.API.Renderer.RENDERER_TYPE_2D : componentType = R3.Component.RENDERER_D2; break; - case R3.API.Renderer.RENDERER_TYPE_3D : - componentType = R3.Component.RENDERER_D3; + case R3.API.Renderer.RENDERER_TYPE_3D_CANVAS : + componentType = R3.Component.RENDERER_D3_CANVAS; + break; + case R3.API.Renderer.RENDERER_TYPE_3D_TARGET : + componentType = R3.Component.RENDERER_D3_TARGET; + break; + case R3.API.Renderer.RENDERER_TYPE_3D_CANVAS_AND_TARGET : + componentType = R3.Component.RENDERER_D3_CANVAS_TARGET; break; default : console.warn('could not determine component type'); @@ -104,9 +83,11 @@ R3.API.Renderer.GetComponentType = function(rendererType) { return componentType; }; -R3.API.Renderer.RENDERER_TYPE_NONE = 0x0; -R3.API.Renderer.RENDERER_TYPE_2D = 0x1; -R3.API.Renderer.RENDERER_TYPE_3D = 0x2; +R3.API.Renderer.RENDERER_TYPE_NONE = 0x0; +R3.API.Renderer.RENDERER_TYPE_2D = 0x1; +R3.API.Renderer.RENDERER_TYPE_3D_CANVAS = 0x2; +R3.API.Renderer.RENDERER_TYPE_3D_TARGET = 0x3; +R3.API.Renderer.RENDERER_TYPE_3D_CANVAS_AND_TARGET = 0x4; R3.API.Renderer.MODE_CANVAS = 0x1; R3.API.Renderer.MODE_TARGET = 0x2; @@ -120,15 +101,3 @@ R3.API.Renderer.TONE_MAPPING_LINEAR = 1; R3.API.Renderer.TONE_MAPPING_REINHARD = 2; R3.API.Renderer.TONE_MAPPING_UNCHARTED_2 = 3; R3.API.Renderer.TONE_MAPPING_CINEON = 4; - -R3.API.Renderer.ASPECT_RATIO_NONE = 0x1; -R3.API.Renderer.ASPECT_RATIO_4_3 = 0x2; -R3.API.Renderer.ASPECT_RATIO_3_2 = 0x3; -R3.API.Renderer.ASPECT_RATIO_16_10 = 0x4; -R3.API.Renderer.ASPECT_RATIO_17_10 = 0x5; -R3.API.Renderer.ASPECT_RATIO_16_9 = 0x6; - -R3.API.Renderer.SCALE_MODE_NONE = 0x1; -R3.API.Renderer.SCALE_MODE_LETTERBOX = 0x2; -R3.API.Renderer.SCALE_MODE_ZOOM_TO_BIGGER = 0x3; -R3.API.Renderer.SCALE_MODE_NON_UNIFORM = 0x4; diff --git a/src/r3-api-renderer-d2.js b/src/r3-api-renderer-d2.js index d207dcf..e7013f2 100644 --- a/src/r3-api-renderer-d2.js +++ b/src/r3-api-renderer-d2.js @@ -2,9 +2,11 @@ * R3.API.Renderer.D2 * @constructor * @param apiRenderer + * @param canvas */ -R3.API.Renderer.D2 = function ( - apiRenderer +R3.API.Renderer.D2 = function( + apiRenderer, + canvas ) { if (R3.Utils.UndefinedOrNull(apiRenderer)) { @@ -21,14 +23,15 @@ R3.API.Renderer.D2 = function ( this, apiRenderer.id, apiRenderer.name, - apiRenderer.rendererType, - apiRenderer.parentEntity, - apiRenderer.width, - apiRenderer.height, - apiRenderer.offset, - apiRenderer.canvas + apiRenderer.parent, + apiRenderer.rendererType ); + if (R3.Utils.UndefinedOrNull(canvas)) { + canvas = new R3.API.Canvas(); + } + this.canvas = canvas; + }; R3.API.Renderer.D2.prototype = Object.create(R3.API.Renderer.prototype); diff --git a/src/r3-api-renderer-d3-canvas-target.js b/src/r3-api-renderer-d3-canvas-target.js new file mode 100644 index 0000000..220ee6b --- /dev/null +++ b/src/r3-api-renderer-d3-canvas-target.js @@ -0,0 +1,296 @@ +/** + * R3.API.Renderer.D3 + * @param apiRenderer + * @param renderMode + * @param autoClear + * @param autoClearColor + * @param autoClearDepth + * @param autoClearStencil + * @param gammaFactor + * @param gammaInput + * @param gammaOutput + * @param maxMorphTargets + * @param maxMorphNormals + * @param physicallyCorrectLights + * @param shadowMapEnabled + * @param shadowMapAutoUpdate + * @param shadowMapNeedsUpdate + * @param shadowMapType + * @param shadowMapRenderReverseSided + * @param shadowMapRenderSingleSided + * @param sortObjects + * @param toneMapping + * @param toneMappingExposure + * @param toneMappingWhitePoint + * @param premultipliedAlpha + * @param antialias + * @param stencil + * @param preserveDrawingBuffer + * @param depth + * @param logarithmicDepthBuffer + * @param localClippingEnabled + * @param renderTarget + * @param clippingPlanes + * @param clearColor + * @param viewports + * @param alpha + * @param opacity + * @param composer - only one composer can be active at a time + * @param effect - only one effect can be active at a time + * @param enableComposer + * @param enableEffect + * @constructor + */ +R3.API.Renderer.D3.Canvas.Target = function( + apiRenderer, + renderMode, + autoClear, + autoClearColor, + autoClearDepth, + autoClearStencil, + gammaFactor, + gammaInput, + gammaOutput, + maxMorphTargets, + maxMorphNormals, + physicallyCorrectLights, + shadowMapEnabled, + shadowMapAutoUpdate, + shadowMapNeedsUpdate, + shadowMapType, + shadowMapRenderReverseSided, + shadowMapRenderSingleSided, + sortObjects, + toneMapping, + toneMappingExposure, + toneMappingWhitePoint, + premultipliedAlpha, + antialias, + stencil, + preserveDrawingBuffer, + depth, + logarithmicDepthBuffer, + localClippingEnabled, + renderTarget, + clippingPlanes, + clearColor, + viewports, + alpha, + opacity +) { + + if (R3.Utils.UndefinedOrNull(apiRenderer)) { + apiRenderer = { + rendererType : R3.API.Renderer.RENDERER_TYPE_3D + }; + } + + if (R3.Utils.UndefinedOrNull(apiRenderer.rendererType)) { + apiRenderer.rendererType = R3.API.Renderer.RENDERER_TYPE_3D; + } + + if (R3.Utils.UndefinedOrNull(renderMode)) { + renderMode = R3.API.Renderer.MODE_CANVAS; + } + this.renderMode = renderMode; + + if (R3.Utils.UndefinedOrNull(autoClear)) { + autoClear = true; + } + this.autoClear = autoClear; + + if (R3.Utils.UndefinedOrNull(autoClearColor)) { + autoClearColor = true; + } + this.autoClearColor = autoClearColor; + + if (R3.Utils.UndefinedOrNull(autoClearDepth)) { + autoClearDepth = true; + } + this.autoClearDepth = autoClearDepth; + + if (R3.Utils.UndefinedOrNull(autoClearStencil)) { + autoClearStencil = true; + } + this.autoClearStencil = autoClearStencil; + + if (R3.Utils.UndefinedOrNull(gammaFactor)) { + gammaFactor = 2; + } + this.gammaFactor = gammaFactor; + + if (R3.Utils.UndefinedOrNull(gammaInput)) { + gammaInput = false; + } + this.gammaInput = gammaInput; + + if (R3.Utils.UndefinedOrNull(gammaOutput)) { + gammaOutput = false; + } + this.gammaOutput = gammaOutput; + + if (R3.Utils.UndefinedOrNull(maxMorphTargets)) { + maxMorphTargets = 8; + } + this.maxMorphTargets = maxMorphTargets; + + if (R3.Utils.UndefinedOrNull(maxMorphNormals)) { + maxMorphNormals = 4; + } + this.maxMorphNormals = maxMorphNormals; + + if (R3.Utils.UndefinedOrNull(physicallyCorrectLights)) { + physicallyCorrectLights = false; + } + this.physicallyCorrectLights = physicallyCorrectLights; + + if (R3.Utils.UndefinedOrNull(shadowMapEnabled)) { + shadowMapEnabled = false; + } + this.shadowMapEnabled = shadowMapEnabled; + + if (R3.Utils.UndefinedOrNull(shadowMapAutoUpdate)) { + shadowMapAutoUpdate = true; + } + this.shadowMapAutoUpdate = shadowMapAutoUpdate; + + if (R3.Utils.UndefinedOrNull(shadowMapNeedsUpdate)) { + shadowMapNeedsUpdate = false; + } + this.shadowMapNeedsUpdate = shadowMapNeedsUpdate; + + if (R3.Utils.UndefinedOrNull(shadowMapType)) { + shadowMapType = R3.API.Renderer.SHADOW_MAP_TYPE_BASIC; + } + this.shadowMapType = shadowMapType; + + if (R3.Utils.UndefinedOrNull(shadowMapRenderReverseSided)) { + shadowMapRenderReverseSided = true; + } + this.shadowMapRenderReverseSided = shadowMapRenderReverseSided; + + if (R3.Utils.UndefinedOrNull(shadowMapRenderSingleSided)) { + shadowMapRenderSingleSided = true; + } + this.shadowMapRenderSingleSided = shadowMapRenderSingleSided; + + if (R3.Utils.UndefinedOrNull(sortObjects)) { + sortObjects = true; + } + this.sortObjects = sortObjects; + + if (R3.Utils.UndefinedOrNull(toneMapping)) { + toneMapping = R3.API.Renderer.TONE_MAPPING_LINEAR; + } + this.toneMapping = toneMapping; + + if (R3.Utils.UndefinedOrNull(toneMappingExposure)) { + toneMappingExposure = 1; + } + this.toneMappingExposure = toneMappingExposure; + + if (R3.Utils.UndefinedOrNull(toneMappingWhitePoint)) { + toneMappingWhitePoint = 1; + } + this.toneMappingWhitePoint = toneMappingWhitePoint; + + if (R3.Utils.UndefinedOrNull(premultipliedAlpha)) { + premultipliedAlpha = true; + } + this.premultipliedAlpha = premultipliedAlpha; + + if (R3.Utils.UndefinedOrNull(antialias)) { + antialias = false; + } + this.antialias = antialias; + + if (R3.Utils.UndefinedOrNull(stencil)) { + stencil = true; + } + this.stencil = stencil; + + if (R3.Utils.UndefinedOrNull(preserveDrawingBuffer)) { + preserveDrawingBuffer = false; + } + this.preserveDrawingBuffer = preserveDrawingBuffer; + + if (R3.Utils.UndefinedOrNull(depth)) { + depth = true; + } + this.depth = depth; + + if (R3.Utils.UndefinedOrNull(logarithmicDepthBuffer)) { + logarithmicDepthBuffer = false; + } + this.logarithmicDepthBuffer = logarithmicDepthBuffer; + + if (R3.Utils.UndefinedOrNull(localClippingEnabled)) { + localClippingEnabled = false; + } + this.localClippingEnabled = localClippingEnabled; + + if (R3.Utils.UndefinedOrNull(renderTarget)) { + renderTarget = null; + } + this.renderTarget = renderTarget; + + if (R3.Utils.UndefinedOrNull(clippingPlanes)) { + clippingPlanes = []; + } + this.clippingPlanes = clippingPlanes; + + if (R3.Utils.UndefinedOrNull(clearColor)) { + clearColor = new R3.API.Color(this, 0.11, 0.11, 0.11); + } + this.clearColor = clearColor; + + if (R3.Utils.UndefinedOrNull(viewports)) { + viewports = [new R3.D3.API.Viewport()]; + } + this.viewports = viewports; + + if (R3.Utils.UndefinedOrNull(alpha)) { + alpha = true; + } + this.alpha = alpha; + + if (R3.Utils.UndefinedOrNull(opacity)) { + opacity = 1; + } + this.opacity = opacity; + + if (R3.Utils.UndefinedOrNull(composer)) { + composer = new R3.API.Composer(); + composer.renderer = this.id; + } + this.composer = composer; + + if (R3.Utils.UndefinedOrNull(effect)) { + effect = new R3.API.Effect(); + effect.renderer = this.id; + } + this.effect = effect; + + if (R3.Utils.UndefinedOrNull(enableComposer)) { + enableComposer = false; + } + this.enableComposer = enableComposer; + + if (R3.Utils.UndefinedOrNull(enableEffect)) { + enableEffect = false; + } + this.enableEffect = enableEffect; + + R3.API.Renderer.call( + this, + apiRenderer.id, + apiRenderer.name, + apiRenderer.parent, + apiRenderer.rendererType, + apiRenderer.canvas + ); + +}; + +R3.API.Renderer.D3.prototype = Object.create(R3.API.Renderer.prototype); +R3.API.Renderer.D3.prototype.constructor = R3.API.Renderer.D3; \ No newline at end of file diff --git a/src/r3-api-renderer-d3-canvas.js b/src/r3-api-renderer-d3-canvas.js new file mode 100644 index 0000000..dfc4a9b --- /dev/null +++ b/src/r3-api-renderer-d3-canvas.js @@ -0,0 +1,274 @@ +/** + * R3.API.Renderer.D3 + * @param apiRenderer + * @param renderMode + * @param autoClear + * @param autoClearColor + * @param autoClearDepth + * @param autoClearStencil + * @param gammaFactor + * @param gammaInput + * @param gammaOutput + * @param maxMorphTargets + * @param maxMorphNormals + * @param physicallyCorrectLights + * @param shadowMapEnabled + * @param shadowMapAutoUpdate + * @param shadowMapNeedsUpdate + * @param shadowMapType + * @param shadowMapRenderReverseSided + * @param shadowMapRenderSingleSided + * @param sortObjects + * @param toneMapping + * @param toneMappingExposure + * @param toneMappingWhitePoint + * @param premultipliedAlpha + * @param antialias + * @param stencil + * @param preserveDrawingBuffer + * @param depth + * @param logarithmicDepthBuffer + * @param localClippingEnabled + * @param renderTarget + * @param clippingPlanes + * @param clearColor + * @param viewports + * @param alpha + * @param opacity + * @param composer - only one composer can be active at a time + * @param effect - only one effect can be active at a time + * @param enableComposer + * @param enableEffect + * @constructor + */ +R3.API.Renderer.D3.Canvas = function( + apiRenderer, + renderMode, + autoClear, + autoClearColor, + autoClearDepth, + autoClearStencil, + gammaFactor, + gammaInput, + gammaOutput, + maxMorphTargets, + maxMorphNormals, + physicallyCorrectLights, + shadowMapEnabled, + shadowMapAutoUpdate, + shadowMapNeedsUpdate, + shadowMapType, + shadowMapRenderReverseSided, + shadowMapRenderSingleSided, + sortObjects, + toneMapping, + toneMappingExposure, + toneMappingWhitePoint, + premultipliedAlpha, + antialias, + stencil, + preserveDrawingBuffer, + depth, + logarithmicDepthBuffer, + localClippingEnabled, + renderTarget, + clippingPlanes, + clearColor, + viewports, + alpha, + opacity +) { + + if (R3.Utils.UndefinedOrNull(apiRenderer)) { + apiRenderer = { + rendererType : R3.API.Renderer.RENDERER_TYPE_3D + }; + } + + if (R3.Utils.UndefinedOrNull(apiRenderer.rendererType)) { + apiRenderer.rendererType = R3.API.Renderer.RENDERER_TYPE_3D; + } + + if (R3.Utils.UndefinedOrNull(renderMode)) { + renderMode = R3.API.Renderer.MODE_CANVAS; + } + this.renderMode = renderMode; + + if (R3.Utils.UndefinedOrNull(autoClear)) { + autoClear = true; + } + this.autoClear = autoClear; + + if (R3.Utils.UndefinedOrNull(autoClearColor)) { + autoClearColor = true; + } + this.autoClearColor = autoClearColor; + + if (R3.Utils.UndefinedOrNull(autoClearDepth)) { + autoClearDepth = true; + } + this.autoClearDepth = autoClearDepth; + + if (R3.Utils.UndefinedOrNull(autoClearStencil)) { + autoClearStencil = true; + } + this.autoClearStencil = autoClearStencil; + + if (R3.Utils.UndefinedOrNull(gammaFactor)) { + gammaFactor = 2; + } + this.gammaFactor = gammaFactor; + + if (R3.Utils.UndefinedOrNull(gammaInput)) { + gammaInput = false; + } + this.gammaInput = gammaInput; + + if (R3.Utils.UndefinedOrNull(gammaOutput)) { + gammaOutput = false; + } + this.gammaOutput = gammaOutput; + + if (R3.Utils.UndefinedOrNull(maxMorphTargets)) { + maxMorphTargets = 8; + } + this.maxMorphTargets = maxMorphTargets; + + if (R3.Utils.UndefinedOrNull(maxMorphNormals)) { + maxMorphNormals = 4; + } + this.maxMorphNormals = maxMorphNormals; + + if (R3.Utils.UndefinedOrNull(physicallyCorrectLights)) { + physicallyCorrectLights = false; + } + this.physicallyCorrectLights = physicallyCorrectLights; + + if (R3.Utils.UndefinedOrNull(shadowMapEnabled)) { + shadowMapEnabled = false; + } + this.shadowMapEnabled = shadowMapEnabled; + + if (R3.Utils.UndefinedOrNull(shadowMapAutoUpdate)) { + shadowMapAutoUpdate = true; + } + this.shadowMapAutoUpdate = shadowMapAutoUpdate; + + if (R3.Utils.UndefinedOrNull(shadowMapNeedsUpdate)) { + shadowMapNeedsUpdate = false; + } + this.shadowMapNeedsUpdate = shadowMapNeedsUpdate; + + if (R3.Utils.UndefinedOrNull(shadowMapType)) { + shadowMapType = R3.API.Renderer.SHADOW_MAP_TYPE_BASIC; + } + this.shadowMapType = shadowMapType; + + if (R3.Utils.UndefinedOrNull(shadowMapRenderReverseSided)) { + shadowMapRenderReverseSided = true; + } + this.shadowMapRenderReverseSided = shadowMapRenderReverseSided; + + if (R3.Utils.UndefinedOrNull(shadowMapRenderSingleSided)) { + shadowMapRenderSingleSided = true; + } + this.shadowMapRenderSingleSided = shadowMapRenderSingleSided; + + if (R3.Utils.UndefinedOrNull(sortObjects)) { + sortObjects = true; + } + this.sortObjects = sortObjects; + + if (R3.Utils.UndefinedOrNull(toneMapping)) { + toneMapping = R3.API.Renderer.TONE_MAPPING_LINEAR; + } + this.toneMapping = toneMapping; + + if (R3.Utils.UndefinedOrNull(toneMappingExposure)) { + toneMappingExposure = 1; + } + this.toneMappingExposure = toneMappingExposure; + + if (R3.Utils.UndefinedOrNull(toneMappingWhitePoint)) { + toneMappingWhitePoint = 1; + } + this.toneMappingWhitePoint = toneMappingWhitePoint; + + if (R3.Utils.UndefinedOrNull(premultipliedAlpha)) { + premultipliedAlpha = true; + } + this.premultipliedAlpha = premultipliedAlpha; + + if (R3.Utils.UndefinedOrNull(antialias)) { + antialias = false; + } + this.antialias = antialias; + + if (R3.Utils.UndefinedOrNull(stencil)) { + stencil = true; + } + this.stencil = stencil; + + if (R3.Utils.UndefinedOrNull(preserveDrawingBuffer)) { + preserveDrawingBuffer = false; + } + this.preserveDrawingBuffer = preserveDrawingBuffer; + + if (R3.Utils.UndefinedOrNull(depth)) { + depth = true; + } + this.depth = depth; + + if (R3.Utils.UndefinedOrNull(logarithmicDepthBuffer)) { + logarithmicDepthBuffer = false; + } + this.logarithmicDepthBuffer = logarithmicDepthBuffer; + + if (R3.Utils.UndefinedOrNull(localClippingEnabled)) { + localClippingEnabled = false; + } + this.localClippingEnabled = localClippingEnabled; + + if (R3.Utils.UndefinedOrNull(renderTarget)) { + renderTarget = null; + } + this.renderTarget = renderTarget; + + if (R3.Utils.UndefinedOrNull(clippingPlanes)) { + clippingPlanes = []; + } + this.clippingPlanes = clippingPlanes; + + if (R3.Utils.UndefinedOrNull(clearColor)) { + clearColor = new R3.API.Color(this, 0.11, 0.11, 0.11); + } + this.clearColor = clearColor; + + if (R3.Utils.UndefinedOrNull(viewports)) { + viewports = [new R3.D3.API.Viewport()]; + } + this.viewports = viewports; + + if (R3.Utils.UndefinedOrNull(alpha)) { + alpha = true; + } + this.alpha = alpha; + + if (R3.Utils.UndefinedOrNull(opacity)) { + opacity = 1; + } + this.opacity = opacity; + + R3.API.Renderer.call( + this, + apiRenderer.id, + apiRenderer.name, + apiRenderer.parent, + apiRenderer.rendererType, + apiRenderer.canvas + ); + +}; + +R3.API.Renderer.D3.prototype = Object.create(R3.API.Renderer.prototype); +R3.API.Renderer.D3.prototype.constructor = R3.API.Renderer.D3; \ No newline at end of file diff --git a/src/r3-api-renderer-d3-target.js b/src/r3-api-renderer-d3-target.js new file mode 100644 index 0000000..d2b5038 --- /dev/null +++ b/src/r3-api-renderer-d3-target.js @@ -0,0 +1,296 @@ +/** + * R3.API.Renderer.D3 + * @param apiRenderer + * @param renderMode + * @param autoClear + * @param autoClearColor + * @param autoClearDepth + * @param autoClearStencil + * @param gammaFactor + * @param gammaInput + * @param gammaOutput + * @param maxMorphTargets + * @param maxMorphNormals + * @param physicallyCorrectLights + * @param shadowMapEnabled + * @param shadowMapAutoUpdate + * @param shadowMapNeedsUpdate + * @param shadowMapType + * @param shadowMapRenderReverseSided + * @param shadowMapRenderSingleSided + * @param sortObjects + * @param toneMapping + * @param toneMappingExposure + * @param toneMappingWhitePoint + * @param premultipliedAlpha + * @param antialias + * @param stencil + * @param preserveDrawingBuffer + * @param depth + * @param logarithmicDepthBuffer + * @param localClippingEnabled + * @param renderTarget + * @param clippingPlanes + * @param clearColor + * @param viewports + * @param alpha + * @param opacity + * @param composer - only one composer can be active at a time + * @param effect - only one effect can be active at a time + * @param enableComposer + * @param enableEffect + * @constructor + */ +R3.API.Renderer.D3.Target = function( + apiRenderer, + renderMode, + autoClear, + autoClearColor, + autoClearDepth, + autoClearStencil, + gammaFactor, + gammaInput, + gammaOutput, + maxMorphTargets, + maxMorphNormals, + physicallyCorrectLights, + shadowMapEnabled, + shadowMapAutoUpdate, + shadowMapNeedsUpdate, + shadowMapType, + shadowMapRenderReverseSided, + shadowMapRenderSingleSided, + sortObjects, + toneMapping, + toneMappingExposure, + toneMappingWhitePoint, + premultipliedAlpha, + antialias, + stencil, + preserveDrawingBuffer, + depth, + logarithmicDepthBuffer, + localClippingEnabled, + renderTarget, + clippingPlanes, + clearColor, + viewports, + alpha, + opacity +) { + + if (R3.Utils.UndefinedOrNull(apiRenderer)) { + apiRenderer = { + rendererType : R3.API.Renderer.RENDERER_TYPE_3D + }; + } + + if (R3.Utils.UndefinedOrNull(apiRenderer.rendererType)) { + apiRenderer.rendererType = R3.API.Renderer.RENDERER_TYPE_3D; + } + + if (R3.Utils.UndefinedOrNull(renderMode)) { + renderMode = R3.API.Renderer.MODE_CANVAS; + } + this.renderMode = renderMode; + + if (R3.Utils.UndefinedOrNull(autoClear)) { + autoClear = true; + } + this.autoClear = autoClear; + + if (R3.Utils.UndefinedOrNull(autoClearColor)) { + autoClearColor = true; + } + this.autoClearColor = autoClearColor; + + if (R3.Utils.UndefinedOrNull(autoClearDepth)) { + autoClearDepth = true; + } + this.autoClearDepth = autoClearDepth; + + if (R3.Utils.UndefinedOrNull(autoClearStencil)) { + autoClearStencil = true; + } + this.autoClearStencil = autoClearStencil; + + if (R3.Utils.UndefinedOrNull(gammaFactor)) { + gammaFactor = 2; + } + this.gammaFactor = gammaFactor; + + if (R3.Utils.UndefinedOrNull(gammaInput)) { + gammaInput = false; + } + this.gammaInput = gammaInput; + + if (R3.Utils.UndefinedOrNull(gammaOutput)) { + gammaOutput = false; + } + this.gammaOutput = gammaOutput; + + if (R3.Utils.UndefinedOrNull(maxMorphTargets)) { + maxMorphTargets = 8; + } + this.maxMorphTargets = maxMorphTargets; + + if (R3.Utils.UndefinedOrNull(maxMorphNormals)) { + maxMorphNormals = 4; + } + this.maxMorphNormals = maxMorphNormals; + + if (R3.Utils.UndefinedOrNull(physicallyCorrectLights)) { + physicallyCorrectLights = false; + } + this.physicallyCorrectLights = physicallyCorrectLights; + + if (R3.Utils.UndefinedOrNull(shadowMapEnabled)) { + shadowMapEnabled = false; + } + this.shadowMapEnabled = shadowMapEnabled; + + if (R3.Utils.UndefinedOrNull(shadowMapAutoUpdate)) { + shadowMapAutoUpdate = true; + } + this.shadowMapAutoUpdate = shadowMapAutoUpdate; + + if (R3.Utils.UndefinedOrNull(shadowMapNeedsUpdate)) { + shadowMapNeedsUpdate = false; + } + this.shadowMapNeedsUpdate = shadowMapNeedsUpdate; + + if (R3.Utils.UndefinedOrNull(shadowMapType)) { + shadowMapType = R3.API.Renderer.SHADOW_MAP_TYPE_BASIC; + } + this.shadowMapType = shadowMapType; + + if (R3.Utils.UndefinedOrNull(shadowMapRenderReverseSided)) { + shadowMapRenderReverseSided = true; + } + this.shadowMapRenderReverseSided = shadowMapRenderReverseSided; + + if (R3.Utils.UndefinedOrNull(shadowMapRenderSingleSided)) { + shadowMapRenderSingleSided = true; + } + this.shadowMapRenderSingleSided = shadowMapRenderSingleSided; + + if (R3.Utils.UndefinedOrNull(sortObjects)) { + sortObjects = true; + } + this.sortObjects = sortObjects; + + if (R3.Utils.UndefinedOrNull(toneMapping)) { + toneMapping = R3.API.Renderer.TONE_MAPPING_LINEAR; + } + this.toneMapping = toneMapping; + + if (R3.Utils.UndefinedOrNull(toneMappingExposure)) { + toneMappingExposure = 1; + } + this.toneMappingExposure = toneMappingExposure; + + if (R3.Utils.UndefinedOrNull(toneMappingWhitePoint)) { + toneMappingWhitePoint = 1; + } + this.toneMappingWhitePoint = toneMappingWhitePoint; + + if (R3.Utils.UndefinedOrNull(premultipliedAlpha)) { + premultipliedAlpha = true; + } + this.premultipliedAlpha = premultipliedAlpha; + + if (R3.Utils.UndefinedOrNull(antialias)) { + antialias = false; + } + this.antialias = antialias; + + if (R3.Utils.UndefinedOrNull(stencil)) { + stencil = true; + } + this.stencil = stencil; + + if (R3.Utils.UndefinedOrNull(preserveDrawingBuffer)) { + preserveDrawingBuffer = false; + } + this.preserveDrawingBuffer = preserveDrawingBuffer; + + if (R3.Utils.UndefinedOrNull(depth)) { + depth = true; + } + this.depth = depth; + + if (R3.Utils.UndefinedOrNull(logarithmicDepthBuffer)) { + logarithmicDepthBuffer = false; + } + this.logarithmicDepthBuffer = logarithmicDepthBuffer; + + if (R3.Utils.UndefinedOrNull(localClippingEnabled)) { + localClippingEnabled = false; + } + this.localClippingEnabled = localClippingEnabled; + + if (R3.Utils.UndefinedOrNull(renderTarget)) { + renderTarget = null; + } + this.renderTarget = renderTarget; + + if (R3.Utils.UndefinedOrNull(clippingPlanes)) { + clippingPlanes = []; + } + this.clippingPlanes = clippingPlanes; + + if (R3.Utils.UndefinedOrNull(clearColor)) { + clearColor = new R3.API.Color(this, 0.11, 0.11, 0.11); + } + this.clearColor = clearColor; + + if (R3.Utils.UndefinedOrNull(viewports)) { + viewports = [new R3.D3.API.Viewport()]; + } + this.viewports = viewports; + + if (R3.Utils.UndefinedOrNull(alpha)) { + alpha = true; + } + this.alpha = alpha; + + if (R3.Utils.UndefinedOrNull(opacity)) { + opacity = 1; + } + this.opacity = opacity; + + if (R3.Utils.UndefinedOrNull(composer)) { + composer = new R3.API.Composer(); + composer.renderer = this.id; + } + this.composer = composer; + + if (R3.Utils.UndefinedOrNull(effect)) { + effect = new R3.API.Effect(); + effect.renderer = this.id; + } + this.effect = effect; + + if (R3.Utils.UndefinedOrNull(enableComposer)) { + enableComposer = false; + } + this.enableComposer = enableComposer; + + if (R3.Utils.UndefinedOrNull(enableEffect)) { + enableEffect = false; + } + this.enableEffect = enableEffect; + + R3.API.Renderer.call( + this, + apiRenderer.id, + apiRenderer.name, + apiRenderer.parent, + apiRenderer.rendererType, + apiRenderer.canvas + ); + +}; + +R3.API.Renderer.D3.prototype = Object.create(R3.API.Renderer.prototype); +R3.API.Renderer.D3.prototype.constructor = R3.API.Renderer.D3; \ No newline at end of file diff --git a/src/r3-api-renderer-d3.js b/src/r3-api-renderer-d3.js index 009a646..95cbb8b 100644 --- a/src/r3-api-renderer-d3.js +++ b/src/r3-api-renderer-d3.js @@ -35,17 +35,13 @@ * @param viewports * @param alpha * @param opacity - * @param logicalSize - * @param aspectRatio - * @param scaleMode - * @param scenes - * @param composers - * @param effects + * @param composer - only one composer can be active at a time + * @param effect - only one effect can be active at a time * @param enableComposer - * @param enableEffects + * @param enableEffect * @constructor */ -R3.API.Renderer.D3 = function ( +R3.API.Renderer.D3 = function( apiRenderer, renderMode, autoClear, @@ -80,12 +76,7 @@ R3.API.Renderer.D3 = function ( clearColor, viewports, alpha, - opacity, - scenes, - composers, - effect, - enableComposer, - enableEffect + opacity ) { if (R3.Utils.UndefinedOrNull(apiRenderer)) { @@ -249,19 +240,12 @@ R3.API.Renderer.D3 = function ( this.clippingPlanes = clippingPlanes; if (R3.Utils.UndefinedOrNull(clearColor)) { - clearColor = new R3.API.Color(0.11, 0.11, 0.11); + clearColor = new R3.API.Color(this, 0.11, 0.11, 0.11); } this.clearColor = clearColor; if (R3.Utils.UndefinedOrNull(viewports)) { - viewports = [new R3.D3.API.Viewport( - null, - null, - 1, - 1, - 0, - 0 - )]; + viewports = [new R3.D3.API.Viewport()]; } this.viewports = viewports; @@ -275,15 +259,34 @@ R3.API.Renderer.D3 = function ( } this.opacity = opacity; + if (R3.Utils.UndefinedOrNull(composer)) { + composer = new R3.API.Composer(); + composer.renderer = this.id; + } + this.composer = composer; + + if (R3.Utils.UndefinedOrNull(effect)) { + effect = new R3.API.Effect(); + effect.renderer = this.id; + } + this.effect = effect; + + if (R3.Utils.UndefinedOrNull(enableComposer)) { + enableComposer = false; + } + this.enableComposer = enableComposer; + + if (R3.Utils.UndefinedOrNull(enableEffect)) { + enableEffect = false; + } + this.enableEffect = enableEffect; + R3.API.Renderer.call( this, apiRenderer.id, apiRenderer.name, + apiRenderer.parent, apiRenderer.rendererType, - apiRenderer.parentEntity, - apiRenderer.width, - apiRenderer.height, - apiRenderer.offset, apiRenderer.canvas ); diff --git a/src/r3-api-server.js b/src/r3-api-server.js index b255071..94f76b1 100644 --- a/src/r3-api-server.js +++ b/src/r3-api-server.js @@ -10,7 +10,7 @@ * @param preferIp - Set to true to use IP instead of resolving DNS at getUrl() runtime * @param port * @param protocols - * @param parentEntity + * @param parent * @constructor */ R3.API.Server = function( @@ -24,7 +24,7 @@ R3.API.Server = function( preferIp, port, protocols, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -80,7 +80,7 @@ R3.API.Server = function( R3.API.Component.call( this, R3.Component.SERVER, - parentEntity + parent ); }; diff --git a/src/r3-api-socket-0.js b/src/r3-api-socket-0.js index 2542bcb..9bba617 100644 --- a/src/r3-api-socket-0.js +++ b/src/r3-api-socket-0.js @@ -6,7 +6,7 @@ * @param roomId * @param peerId * @param server R3.Server - * @param parentEntity + * @param parent * @constructor */ R3.API.Socket = function( @@ -16,7 +16,7 @@ R3.API.Socket = function( roomId, peerId, server, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -87,7 +87,7 @@ R3.API.Socket = function( R3.API.Component.call( this, R3.API.Socket.GetComponentType(this.socketType), - parentEntity + parent ); }; diff --git a/src/r3-api-socket-cast.js b/src/r3-api-socket-cast.js index 1a61a1d..e41021a 100644 --- a/src/r3-api-socket-cast.js +++ b/src/r3-api-socket-cast.js @@ -46,7 +46,7 @@ R3.API.Socket.Cast = function( apiSocket.roomId, apiSocket.peerId, apiSocket.server, - apiSocket.parentEntity + apiSocket.parent ); }; diff --git a/src/r3-api-socket-receive.js b/src/r3-api-socket-receive.js index a71d6f6..6a89ab9 100644 --- a/src/r3-api-socket-receive.js +++ b/src/r3-api-socket-receive.js @@ -46,7 +46,7 @@ R3.API.Socket.Receive = function( apiSocket.roomId, apiSocket.peerId, apiSocket.server, - apiSocket.parentEntity + apiSocket.parent ); }; diff --git a/src/r3-api-sphere.js b/src/r3-api-sphere.js index c8901e8..7e59134 100644 --- a/src/r3-api-sphere.js +++ b/src/r3-api-sphere.js @@ -4,7 +4,7 @@ * @param center * @param radius */ -R3.API.Sphere = function ( +R3.API.Sphere = function( center, radius ) { diff --git a/src/r3-api-stats.js b/src/r3-api-stats.js index ccc1dc2..c991120 100644 --- a/src/r3-api-stats.js +++ b/src/r3-api-stats.js @@ -3,14 +3,14 @@ * @param id * @param name * @param domElement - * @param parentEntity + * @param parent * @constructor */ R3.API.Stats = function( id, name, domElement, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -31,7 +31,7 @@ R3.API.Stats = function( R3.API.Component.call( this, R3.Component.STATS, - parentEntity + parent ); }; @@ -58,7 +58,7 @@ R3.API.Stats.FromObject = function(objectStats) { objectStats.id, objectStats.name, apiDomElement, - objectStats.parentEntity + objectStats.parent ); }; diff --git a/src/r3-api-system.js b/src/r3-api-system.js index 508902c..a9869bb 100644 --- a/src/r3-api-system.js +++ b/src/r3-api-system.js @@ -3,14 +3,14 @@ * @param id String * @param name String * @param systemType - * @param parentEntity + * @param parent * @constructor */ -R3.API.System = function ( +R3.API.System = function( id, name, systemType, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -81,7 +81,7 @@ R3.API.System = function ( R3.API.Component.call( this, componentType, - parentEntity + parent ); }; @@ -99,6 +99,6 @@ R3.API.System.FromObject = function(objectComponent) { objectComponent.id, objectComponent.name, objectComponent.systemType, - objectComponent.parentEntity + objectComponent.parent ); }; diff --git a/src/r3-api-user.js b/src/r3-api-user.js index 93df188..259ad8f 100644 --- a/src/r3-api-user.js +++ b/src/r3-api-user.js @@ -2,7 +2,7 @@ * API User * @param id * @param name - * @param parentEntity + * @param parent * @param googleId * @param fullName * @param givenName @@ -16,7 +16,7 @@ R3.API.User = function( id, name, - parentEntity, + parent, googleId, fullName, givenName, @@ -79,7 +79,7 @@ R3.API.User = function( R3.API.Component.call( this, R3.Component.USER, - parentEntity + parent ); }; diff --git a/src/r3-api-vector2.js b/src/r3-api-vector2.js index f9a7c36..e9df043 100644 --- a/src/r3-api-vector2.js +++ b/src/r3-api-vector2.js @@ -1,4 +1,10 @@ -R3.API.Vector2 = function (x, y) { +/** + * R3.API.Vector2 + * @param x + * @param y + * @constructor + */ +R3.API.Vector2 = function(x, y) { if (R3.Utils.UndefinedOrNull(x)) { x = 0; @@ -9,34 +15,134 @@ R3.API.Vector2 = function (x, y) { y = 0; } this.y = y; - -}; - -R3.API.Vector2.prototype.copy = function () { - return new R3.API.Vector2( - this.x, - this.y - ); -}; - -R3.API.Vector2.prototype.equals = function (v) { - return this.x === v.x && this.y === v.y; }; /** - * Returns an API vector from an Object vector - * @param objectVector - * @constructor + * Equals + * TODO: Test + * @param v + * @returns {boolean} */ -R3.API.Vector2.FromObject = function (objectVector) { +R3.API.Vector2.prototype.equals = function(v) { - if (R3.Utils.UndefinedOrNull(objectVector)) { - console.warn('vector from db undefined - stale version in db'); - objectVector = {}; + if ((this.x === v.x) && + (this.y === v.y)) { + return true; + } else { + return false; } - return new R3.API.Vector2( - objectVector.x, - objectVector.y - ) }; + +/** + * Add + * TODO: Test + * @param v + */ +R3.API.Vector2.prototype.add = function(v) { + this.x += v.x; + this.y += v.y; + return this; +}; + +/** + * Subtract + * TODO: Test + * @param v + */ +R3.API.Vector2.prototype.subtract = function(v) { + this.x -= v.x; + this.y -= v.y; + return this; +}; + +/** + * Multiply + * TODO: Test + * @param v + */ +R3.API.Vector2.prototype.multiply = function(v) { + this.x *= v.x; + this.y *= v.y; + return this; +}; + +/** + * Divide + * TODO: Test + * @param v + */ +R3.API.Vector2.prototype.divide = function(v) { + this.x *= (1.0 / v.x); + this.y *= (1.0 / v.y); + return this; +}; + +/** + * Clamp + * TODO: Test + * @param min R3.API.Vector2 + * @param max R3.API.Vector2 + * @returns {R3.API.Vector2} + */ +R3.API.Vector2.prototype.clamp = function(min, max) { + + this.x = Math.max(min.x, Math.min(max.x, this.x)); + this.y = Math.max(min.y, Math.min(max.y, this.y)); + + return this; + +}; + +/** + * Length + * TODO: Test + * @returns {number} + */ +R3.API.Vector2.prototype.length = function() { + return Math.sqrt( + this.x * this.x + this.y * this.y + ); +}; + +/** + * Dot product + * TODO: Test + * @param v + * @returns {number} + */ +R3.API.Vector2.prototype.dot = function(v) { + return this.x * v.x + this.y * v.y; +}; + +/** + * Normalize + * TODO: Test + */ +R3.API.Vector2.prototype.normalize = function() { + return this.multiply(1.0 / this.length()); +}; + +/** + * TODO: Test + * Angle between this vector and origin + * @returns {number} + */ +R3.API.Vector2.prototype.angle = function() { + var angle = Math.atan2(this.y, this.x); + if ( angle < 0 ) angle += 2 * Math.PI; + return angle; +}; + +/** + * Interpolate to v from here + * TODO: Test + * @param v + * @param alpha + * @returns {R3.API.Vector2} + */ +R3.API.Vector2.prototype.lerp = function( v, alpha ) { + this.x += ( v.x - this.x ) * alpha; + this.y += ( v.y - this.y ) * alpha; + return this; +}; \ No newline at end of file diff --git a/src/r3-api-vector3.js b/src/r3-api-vector3.js index 923b136..bf118a9 100644 --- a/src/r3-api-vector3.js +++ b/src/r3-api-vector3.js @@ -1,4 +1,11 @@ -R3.API.Vector3 = function (x, y, z) { +/** + * R3.API.Vector3 + * @param x + * @param y + * @param z + * @constructor + */ +R3.API.Vector3 = function(x, y, z) { if (R3.Utils.UndefinedOrNull(x)) { x = 0; @@ -17,6 +24,13 @@ R3.API.Vector3 = function (x, y, z) { }; +R3.API.Vector3.prototype.setFrom = function(vector3) { + this.x = vector3.x; + this.y = vector3.y; + this.z = vector3.z; + return this; +}; + R3.API.Vector3.prototype.negate = function() { this.x = -this.x; this.y = -this.y; @@ -24,71 +38,55 @@ R3.API.Vector3.prototype.negate = function() { return this; }; -R3.API.Vector3.prototype.subtract = function (v) { - return new R3.API.Vector3( - this.x - v.x, - this.y - v.y, - this.z - v.z - ); +R3.API.Vector3.prototype.subtract = function(v) { + this.x -= v.x; + this.y -= v.y; + this.z -= v.z; + return this; }; -R3.API.Vector3.prototype.sub = function (v) { - return new R3.API.Vector3( - this.x - v.x, - this.y - v.y, - this.z - v.z - ); +R3.API.Vector3.prototype.sub = function(v) { + return this.subtract(v); }; -R3.API.Vector3.prototype.equals = function (v) { +R3.API.Vector3.prototype.equals = function(v) { return this.x === v.x && this.y === v.y && this.z === v.z; }; -R3.API.Vector3.prototype.cross = function (v) { - return new R3.API.Vector3( - this.y * v.z - this.z * v.y, - this.z * v.x - this.x * v.z, - this.x * v.y - this.y * v.x - ); +R3.API.Vector3.prototype.cross = function(v) { + var x = this.y * v.z - this.z * v.y; + var y = this.z * v.x - this.x * v.z; + var z = this.x * v.y - this.y * v.x; + this.x = x; + this.y = y; + this.z = z; + return this; }; -R3.API.Vector3.clockwise = function (u, v, w, viewPoint) { - var normal = R3.API.Vector3.normal(u, v, w); - var uv = u.copy(); - var winding = normal.dot(uv.subtract(viewPoint)); - return (winding > 0); -}; - -R3.API.Vector3.normal = function (u, v, w) { - var vv = v.copy(); - var wv = w.copy(); - return vv.subtract(u).cross(wv.subtract(u)); -}; - -R3.API.Vector3.prototype.lookAt = function (at, up) { +R3.API.Vector3.prototype.lookAt = function(at, up) { var lookAtMatrix = R3.API.Matrix4.lookAt(this, at, up); return this.multiply(lookAtMatrix); }; -R3.API.Vector3.prototype.translate = function (v) { +R3.API.Vector3.prototype.translate = function(v) { this.x += v.x; this.y += v.y; this.z += v.z; return this; }; -R3.API.Vector3.prototype.add = function (v) { +R3.API.Vector3.prototype.add = function(v) { this.x += v.x; this.y += v.y; this.z += v.z; return this; }; -R3.API.Vector3.prototype.squared = function () { +R3.API.Vector3.prototype.squared = function() { return this.x * this.x + this.y * this.y + this.z * this.z; }; -R3.API.Vector3.prototype.copy = function () { +R3.API.Vector3.prototype.copy = function() { return new R3.API.Vector3( this.x, this.y, @@ -96,18 +94,23 @@ R3.API.Vector3.prototype.copy = function () { ); }; -R3.API.Vector3.prototype.set = function (x, y, z) { +R3.API.Vector3.prototype.set = function(x, y, z) { this.x = x; this.y = y; this.z = z; }; -R3.API.Vector3.prototype.lerp = function ( v, alpha ) { - return new R3.API.Vector3( - this.x + ( v.x - this.x ) * alpha, - this.y + ( v.y - this.y ) * alpha, - this.z + ( v.z - this.z ) * alpha - ); +R3.API.Vector3.prototype.lerp = function( v, alpha ) { + + var x = this.x + ( v.x - this.x ) * alpha; + var y = this.y + ( v.y - this.y ) * alpha; + var z = this.z + ( v.z - this.z ) * alpha; + + this.x = x; + this.y = y; + this.z = z; + + return this; }; R3.API.Vector3.prototype.distanceTo = function(v) { @@ -135,11 +138,11 @@ R3.API.Vector3.AngleDirection = function(forward, directionToCheck, up) { /** * Multiplies this vector with a scalar, vector or matrix. If you want a copy, copy() it first - * @param object {Number | R3.API.Vector3 | R3.API.Vector4 | R3.API.Matrix3 | R3.API.Matrix4} + * @param object {Number | R3.API.Vector3 | R3.Vector4 | R3.API.Matrix3 | R3.API.Matrix4} * @param cross boolean true if you want the cross product, otherwise returns the scalar (dot or inner) product * @returns {R3.API.Vector3 | Number} */ -R3.API.Vector3.prototype.multiply = function (object, cross) { +R3.API.Vector3.prototype.multiply = function(object, cross) { var x, y, z; @@ -188,11 +191,11 @@ R3.API.Vector3.prototype.multiply = function (object, cross) { }; -R3.API.Vector3.prototype.dot = function (v) { +R3.API.Vector3.prototype.dot = function(v) { return (this.x * v.x) + (this.y * v.y) + (this.z * v.z); }; -R3.API.Vector3.prototype.normalize = function () { +R3.API.Vector3.prototype.normalize = function() { var EPSILON = 0.000001; var v2 = this.squared(); @@ -201,19 +204,12 @@ R3.API.Vector3.prototype.normalize = function () { } var invLength = 1.0 / Math.sqrt(v2); - return new R3.API.Vector3( - this.x * invLength, - this.y * invLength, - this.z * invLength - ); -}; -R3.API.Vector3.prototype.clone = function () { - return new R3.API.Vector3( - this.x, - this.y, - this.z - ); + this.x *= invLength; + this.y *= invLength; + this.z *= invLength; + + return this; }; R3.API.Vector3.prototype.applyQuaternion = function(q) { @@ -252,26 +248,7 @@ R3.API.Vector3.prototype.reflect = function(normal) { return this.sub( v1.copy( normal ).multiply( 2 * this.dot( normal ) ) ); }; -R3.API.Vector3.prototype.angleTo = function (v) { +R3.API.Vector3.prototype.angleTo = function(v) { var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) ); return Math.acos( exports.Math.clamp( theta, - 1, 1 ) ); }; - -/** - * Returns an API vector from an Object vector - * @param objectVector - * @constructor - */ -R3.API.Vector3.FromObject = function (objectVector) { - - if (R3.Utils.UndefinedOrNull(objectVector)) { - console.warn('vector from db undefined - stale version in db'); - objectVector = {}; - } - - return new R3.API.Vector3( - objectVector.x, - objectVector.y, - objectVector.z - ) -}; diff --git a/src/r3-api-vector4.js b/src/r3-api-vector4.js index 442bd2a..da0d283 100644 --- a/src/r3-api-vector4.js +++ b/src/r3-api-vector4.js @@ -1,46 +1,31 @@ -R3.API.Vector4 = function (x, y, z, w) { - - if (R3.Utils.UndefinedOrNull(x)) { - x = 0; - } - this.x = x; - - if (R3.Utils.UndefinedOrNull(y)) { - y = 0; - } - this.y = y; - - if (R3.Utils.UndefinedOrNull(z)) { - z = 0; - } - this.z = z; - - if (R3.Utils.UndefinedOrNull(w)) { - w = 1; - } - this.w = w; -}; - -R3.API.Vector4.prototype.equals = function (v) { - return this.x === v.x && this.y === v.y && this.z === v.z && this.w === v.w; -}; - /** - * Returns an API vector from an Object vector - * @param objectVector + * R3.API.Vector4 + * @param x + * @param y + * @param z + * @param w * @constructor */ -R3.API.Vector4.FromObject = function (objectVector) { +R3.API.Vector4 = function(x, y, z, w) { - if (R3.Utils.UndefinedOrNull(objectVector)) { - console.warn('vector from db undefined - stale version in db'); - objectVector = {}; - } + if (R3.Utils.UndefinedOrNull(x)) { + x = 0; + } + this.x = x; + + if (R3.Utils.UndefinedOrNull(y)) { + y = 0; + } + this.y = y; + + if (R3.Utils.UndefinedOrNull(z)) { + z = 0; + } + this.z = z; + + if (R3.Utils.UndefinedOrNull(w)) { + w = 0; + } + this.w = w; - return new R3.API.Vector4( - objectVector.x, - objectVector.y, - objectVector.z, - objectVector.w - ) }; diff --git a/src/r3-api-video.js b/src/r3-api-video.js index eec1ead..4f562e4 100644 --- a/src/r3-api-video.js +++ b/src/r3-api-video.js @@ -2,7 +2,7 @@ * R3.API.Video * @param id * @param name - * @param parentEntity + * @param parent * @param autoUpdateSize * @param width * @param height @@ -13,7 +13,7 @@ R3.API.Video = function( id, name, - parentEntity, + parent, autoUpdateSize, width, height, @@ -60,7 +60,7 @@ R3.API.Video = function( R3.API.Component.call( this, R3.Component.VIDEO, - parentEntity + parent ); }; diff --git a/src/r3-box3.js b/src/r3-box3.js index a2f8524..453b88c 100644 --- a/src/r3-box3.js +++ b/src/r3-box3.js @@ -1,49 +1,46 @@ /** * R3.Box3 - * @param implementation * @param apiBox3 - * @param parentObject * @constructor */ -R3.Box3 = function ( - implementation, - apiBox3, - parentObject +R3.Box3 = function( + apiBox3 ) { - this.implementation = implementation; - this.implementation.isNotThreeThrow(); - - if (R3.Utils.UndefinedOrNull(parentObject)) { - parentObject = null; - } - this.parentObject = parentObject; - if (R3.Utils.UndefinedOrNull(apiBox3)) { apiBox3 = {}; } - R3.API.Box3.call( + R3.API.Box3.call( this, - apiBox3.id, - apiBox3.name, - apiBox3.parentEntity, + apiBox3, apiBox3.min, apiBox3.max ); this.min = new R3.Vector3( - this.implementation, + this, this.min, - this ); this.max = new R3.Vector3( - this.implementation, - this.max, - this + this, + this.max ); + this.graphics = null; + this.physics = null; + + R3.Event.Emit( + R3.Event.GET_RUNTIME, + function(runtime) { + this.graphics = runtime.graphics; + this.physics = runtime.physics; + }.bind(this) + ); + + this.componentRuntime = R3.Component.GetComponentRuntime(parent); + this.createInstance(); }; @@ -56,10 +53,22 @@ R3.Box3.prototype.constructor = R3.Box3; */ R3.Box3.prototype.createInstance = function() { - this.instance = new THREE.Box3( - this.min.instance, - this.max.instance - ); + switch (this.componentRuntime) { + case R3.Component.GRAPHICS_RUNTIME : + this.instance = this.graphics.Box3( + this.min, + this.max + ); + break; + case R3.Component.PHYSICS_RUNTIME : + this.instance = this.physics.Box3( + this.min, + this.max + ); + break; + default: + throw new Error('unhandled component runtime: ' + this.componentRuntime); + } }; @@ -88,9 +97,11 @@ R3.Box3.prototype.updateInstance = function(property) { */ R3.Box3.prototype.toApiObject = function() { return new R3.API.Box3( - this.id, - this.name, - R3.Utils.IdOrNull(this.parentEntity), + new R3.API.Component( + this.parent, + this.id, + this.name + ), this.min.toApiObject(), this.max.toApiObject() ); diff --git a/src/r3-canvas.js b/src/r3-canvas.js index f766141..beb76b9 100644 --- a/src/r3-canvas.js +++ b/src/r3-canvas.js @@ -19,7 +19,7 @@ R3.Canvas = function( this, apiCanvas.id, apiCanvas.name, - apiCanvas.parentEntity, + apiCanvas.parent, apiCanvas.parentTexture, apiCanvas.autoUpdateSize, apiCanvas.width, @@ -163,7 +163,7 @@ R3.Canvas.prototype.toApiObject = function() { return new R3.API.Canvas( this.id, this.name, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), R3.Utils.IdOrNull(this.parentTexture), this.autoUpdateSize, this.width, diff --git a/src/r3-clock.js b/src/r3-clock.js index e04fe0c..fe3a9a0 100644 --- a/src/r3-clock.js +++ b/src/r3-clock.js @@ -20,7 +20,7 @@ R3.Clock = function( this, apiClock.id, apiClock.name, - apiClock.parentEntity + apiClock.parent ); R3.Component.call(this); @@ -72,7 +72,7 @@ R3.Clock.prototype.toApiObject = function() { return new R3.API.Clock( this.id, this.name, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-color.js b/src/r3-color.js index a7a5683..cc214b4 100644 --- a/src/r3-color.js +++ b/src/r3-color.js @@ -6,7 +6,7 @@ * @param grain Number * @constructor */ -R3.Color = function ( +R3.Color = function( graphics, apiColor, parentObject, @@ -76,7 +76,7 @@ R3.Color.prototype.updateInstance = function(property) { * @returns {R3.API.Color} */ R3.Color.prototype.toApiObject = function() { - return new R3.API.Color( + return new R3.API.Color(this, this.r, this.g, this.b, diff --git a/src/r3-controls-0.js b/src/r3-controls-0.js index 0fbaee7..3c2e715 100644 --- a/src/r3-controls-0.js +++ b/src/r3-controls-0.js @@ -4,7 +4,7 @@ * @property controlsType * @constructor */ -R3.Controls = function ( +R3.Controls = function( apiControls ) { @@ -16,9 +16,8 @@ R3.Controls = function ( this, apiControls.id, apiControls.name, - apiControls.controlsType, apiControls.canvas, - apiControls.parentEntity + apiControls.parent ); var linkedObjects = { @@ -93,7 +92,7 @@ R3.Controls.prototype.toApiObject = function() { this.name, this.controlsType, R3.Utils.IdOrNull(this.canvas), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); return apiControls; diff --git a/src/r3-controls-d3-editor.js b/src/r3-controls-d3-editor.js index 344be21..5854336 100644 --- a/src/r3-controls-d3-editor.js +++ b/src/r3-controls-d3-editor.js @@ -4,7 +4,7 @@ * @param apiEditorControls * @constructor */ -R3.Controls.D3.Editor = function ( +R3.Controls.D3.Editor = function( graphics, apiEditorControls ) { diff --git a/src/r3-controls-d3-first-person.js b/src/r3-controls-d3-first-person.js index 2f4ecfa..0d8d581 100644 --- a/src/r3-controls-d3-first-person.js +++ b/src/r3-controls-d3-first-person.js @@ -4,7 +4,7 @@ * @param apiFirstPersonControls * @constructor */ -R3.Controls.D3.FirstPerson = function ( +R3.Controls.D3.FirstPerson = function( graphics, apiFirstPersonControls ) { diff --git a/src/r3-controls-d3-orbit.js b/src/r3-controls-d3-orbit.js index 52b6454..cfdbaed 100644 --- a/src/r3-controls-d3-orbit.js +++ b/src/r3-controls-d3-orbit.js @@ -4,7 +4,7 @@ * @param apiOrbitControls * @constructor */ -R3.Controls.D3.Orbit = function ( +R3.Controls.D3.Orbit = function( graphics, apiOrbitControls ) { diff --git a/src/r3-controls-keyboard.js b/src/r3-controls-keyboard.js index 3c4630e..c949be4 100644 --- a/src/r3-controls-keyboard.js +++ b/src/r3-controls-keyboard.js @@ -3,7 +3,7 @@ * @param apiKeyboardControls R3.API.Controls * @constructor */ -R3.Controls.Keyboard = function ( +R3.Controls.Keyboard = function( apiKeyboardControls ) { diff --git a/src/r3-controls-mouse.js b/src/r3-controls-mouse.js index c8fa81d..ff52f7a 100644 --- a/src/r3-controls-mouse.js +++ b/src/r3-controls-mouse.js @@ -3,7 +3,7 @@ * @param apiMouseControls R3.API.Controls * @constructor */ -R3.Controls.Mouse = function ( +R3.Controls.Mouse = function( apiMouseControls ) { diff --git a/src/r3-controls-touch.js b/src/r3-controls-touch.js index 4fe08f0..4770d55 100644 --- a/src/r3-controls-touch.js +++ b/src/r3-controls-touch.js @@ -3,7 +3,7 @@ * @constructor * @param apiTouchControls */ -R3.Controls.Touch = function ( +R3.Controls.Touch = function( apiTouchControls ) { diff --git a/src/r3-curve-a.js b/src/r3-curve-a.js index c9e4a7c..d09347b 100644 --- a/src/r3-curve-a.js +++ b/src/r3-curve-a.js @@ -22,7 +22,7 @@ R3.Curve = function( apiCurve.id, apiCurve.name, apiCurve.curveType, - apiCurve.parentEntity, + apiCurve.parent, apiCurve.arcLenghDivisions ); @@ -80,7 +80,7 @@ R3.Curve.prototype.toApiObject = function() { this.id, this.name, this.curveType, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), this.arcLenghDivisions ); diff --git a/src/r3-custom-code.js b/src/r3-custom-code.js index 147e85c..3bad8d1 100644 --- a/src/r3-custom-code.js +++ b/src/r3-custom-code.js @@ -17,7 +17,7 @@ R3.CustomCode = function( apiCustomCode.name, apiCustomCode.eventId, apiCustomCode.code, - apiCustomCode.parentEntity + apiCustomCode.parent ); this.editor = null; @@ -62,7 +62,7 @@ R3.CustomCode.prototype.updateInstance = function(property) { try { this.instance = new Function('data', this.code).bind(this); - this.publish( + this.emit( R3.Event.COMPILE_SUCCESS, { component: this @@ -70,7 +70,7 @@ R3.CustomCode.prototype.updateInstance = function(property) { ) } catch (error) { this.instance = new Function('data', "console.log('compilation update failed for : " + this.name + "');").bind(this); - this.publish( + this.emit( R3.Event.COMPILE_FAILED, { component: this @@ -82,7 +82,7 @@ R3.CustomCode.prototype.updateInstance = function(property) { } if (property === 'eventId') { - this.publish( + this.emit( R3.Event.EVENT_ID_UPDATE, { component : this @@ -104,7 +104,7 @@ R3.CustomCode.prototype.toApiObject = function() { this.name, this.eventId, this.code, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-d3-api-a-object.js b/src/r3-d3-api-a-object.js index 5c313e6..aa5fbb1 100644 --- a/src/r3-d3-api-a-object.js +++ b/src/r3-d3-api-a-object.js @@ -3,7 +3,7 @@ * @param id * @param name * @param objectType - * @param parentEntity + * @param parent * @param useQuaternion * @param position * @param quaternion @@ -17,7 +17,7 @@ R3.D3.API.Object = function( id, name, objectType, - parentEntity, + parent, useQuaternion, position, quaternion, @@ -115,7 +115,7 @@ R3.D3.API.Object = function( R3.API.Component.call( this, R3.D3.API.Object.GetComponentType(this.objectType), - parentEntity + parent ); }; diff --git a/src/r3-d3-api-animation.js b/src/r3-d3-api-animation.js index 4c7979f..4ad3222 100644 --- a/src/r3-d3-api-animation.js +++ b/src/r3-d3-api-animation.js @@ -11,10 +11,10 @@ * @param blocking * @param applyToMeshWhenDone * @param meshes - * @param parentEntity + * @param parent * @constructor */ -R3.D3.API.Animation = function ( +R3.D3.API.Animation = function( id, name, rotationSpeed, @@ -26,7 +26,7 @@ R3.D3.API.Animation = function ( blocking, applyToMeshWhenDone, meshes, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); @@ -90,7 +90,7 @@ R3.D3.API.Animation = function ( R3.API.Component.call( this, R3.Component.ANIMATION, - parentEntity + parent ); }; @@ -116,6 +116,6 @@ R3.D3.API.Animation.FromObject = function(objectComponent) { objectComponent.blocking, objectComponent.applyToMeshWhenDone, objectComponent.meshes, - objectComponent.parentEntity + objectComponent.parent ); }; diff --git a/src/r3-d3-api-audio.js b/src/r3-d3-api-audio.js index eb193d1..acb3dbf 100644 --- a/src/r3-d3-api-audio.js +++ b/src/r3-d3-api-audio.js @@ -8,7 +8,7 @@ * @param camera * @param overplay * @param paused - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Audio = function( @@ -20,7 +20,7 @@ R3.D3.API.Audio = function( camera, overplay, paused, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -66,7 +66,7 @@ R3.D3.API.Audio = function( R3.API.Component.call( this, R3.Component.AUDIO, - parentEntity + parent ); }; @@ -98,7 +98,7 @@ R3.D3.API.Audio.FromObject = function(objectAudio) { apiCamera, objectAudio.overplay, objectAudio.paused, - objectAudio.parentEntity + objectAudio.parent ); }; diff --git a/src/r3-d3-api-bone-weight.js b/src/r3-d3-api-bone-weight.js index 0a65279..9e44156 100644 --- a/src/r3-d3-api-bone-weight.js +++ b/src/r3-d3-api-bone-weight.js @@ -4,7 +4,7 @@ * @param weight float * @constructor */ -R3.D3.API.BoneWeight = function ( +R3.D3.API.BoneWeight = function( boneIndex, weight ) { diff --git a/src/r3-d3-api-bone.js b/src/r3-d3-api-bone.js index 77327cb..dd16415 100644 --- a/src/r3-d3-api-bone.js +++ b/src/r3-d3-api-bone.js @@ -5,7 +5,7 @@ * @param parentBoneIds * @constructor */ -R3.D3.API.Bone = function ( +R3.D3.API.Bone = function( apiD3Object, childBoneIds, parentBoneIds @@ -36,7 +36,7 @@ R3.D3.API.Bone = function ( apiD3Object.id, apiD3Object.name, apiD3Object.objectType, - apiD3Object.parentEntity, + apiD3Object.parent, apiD3Object.useQuaternion, apiD3Object.position, apiD3Object.quaternion, diff --git a/src/r3-d3-api-broadphase.js b/src/r3-d3-api-broadphase.js index 70bdab0..63e46bc 100644 --- a/src/r3-d3-api-broadphase.js +++ b/src/r3-d3-api-broadphase.js @@ -3,14 +3,14 @@ * @param id * @param name * @param broadphaseType - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Broadphase = function( id, name, broadphaseType, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -31,7 +31,7 @@ R3.D3.API.Broadphase = function( R3.API.Component.call( this, R3.Component.BROADPHASE, - parentEntity + parent ); }; @@ -48,7 +48,7 @@ R3.D3.API.Broadphase.FromObject = function(objectBroadphase) { objectBroadphase.id, objectBroadphase.name, objectBroadphase.broadphaseType, - objectBroadphase.parentEntity + objectBroadphase.parent ); }; diff --git a/src/r3-d3-api-camera-a.js b/src/r3-d3-api-camera-a.js index 54ca09a..4a3e0e2 100644 --- a/src/r3-d3-api-camera-a.js +++ b/src/r3-d3-api-camera-a.js @@ -37,7 +37,7 @@ R3.D3.API.Camera = function( apiD3Object.id, apiD3Object.name, apiD3Object.objectType, - apiD3Object.parentEntity, + apiD3Object.parent, apiD3Object.useQuaternion, apiD3Object.position, apiD3Object.quaternion, diff --git a/src/r3-d3-api-composer.js b/src/r3-d3-api-composer.js index 8852e0d..f846a24 100644 --- a/src/r3-d3-api-composer.js +++ b/src/r3-d3-api-composer.js @@ -2,7 +2,7 @@ * R3.D3.API.Composer * @param id * @param name - * @param parentEntity + * @param parent * @param autoUpdateSize * @param width * @param height @@ -11,10 +11,10 @@ * @param passes * @constructor */ -R3.D3.API.Composer = function ( +R3.D3.API.Composer = function( + parent, id, name, - parentEntity, autoUpdateSize, width, height, @@ -22,6 +22,12 @@ R3.D3.API.Composer = function ( renderTarget, passes ) { + + if (R3.Utils.UndefinedOrNull(parent)) { + parent = null; + } + this.parent = parent; + if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); } @@ -48,7 +54,13 @@ R3.D3.API.Composer = function ( this.height = height; if (R3.Utils.UndefinedOrNull(renderer)) { - renderer = null; + + if (this.parent && this.parent.parent.renderer) { + renderer = this.parent.parent.renderer; + } else { + renderer = null; + } + } this.renderer = renderer; @@ -65,7 +77,7 @@ R3.D3.API.Composer = function ( R3.API.Component.call( this, R3.Component.COMPOSER, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-effect-a.js b/src/r3-d3-api-effect-a.js index 151219e..0688bf3 100644 --- a/src/r3-d3-api-effect-a.js +++ b/src/r3-d3-api-effect-a.js @@ -3,7 +3,7 @@ * @param id * @param name * @param effectType - * @param parentEntity + * @param parent * @param renderer * @param width * @param height @@ -16,7 +16,7 @@ R3.D3.API.Effect = function( id, name, effectType, - parentEntity, + parent, renderer, width, height @@ -87,7 +87,7 @@ R3.D3.API.Effect = function( R3.API.Component.call( this, componentType, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-effect-anaglyph.js b/src/r3-d3-api-effect-anaglyph.js index 1d3288d..509f471 100644 --- a/src/r3-d3-api-effect-anaglyph.js +++ b/src/r3-d3-api-effect-anaglyph.js @@ -22,7 +22,7 @@ R3.D3.API.Effect.Anaglyph = function( apiEffect.id, apiEffect.name, apiEffect.effectType, - apiEffect.parentEntity, + apiEffect.parent, apiEffect.renderer, apiEffect.width, apiEffect.height diff --git a/src/r3-d3-api-effect-parallax.js b/src/r3-d3-api-effect-parallax.js index 7725d57..868cfe6 100644 --- a/src/r3-d3-api-effect-parallax.js +++ b/src/r3-d3-api-effect-parallax.js @@ -22,7 +22,7 @@ R3.D3.API.Effect.Parallax = function( apiEffect.id, apiEffect.name, apiEffect.effectType, - apiEffect.parentEntity, + apiEffect.parent, apiEffect.renderer, apiEffect.width, apiEffect.height diff --git a/src/r3-d3-api-effect-stereo.js b/src/r3-d3-api-effect-stereo.js index ab37ecb..319ab88 100644 --- a/src/r3-d3-api-effect-stereo.js +++ b/src/r3-d3-api-effect-stereo.js @@ -29,7 +29,7 @@ R3.D3.API.Effect.Stereo = function( apiEffect.id, apiEffect.name, apiEffect.effectType, - apiEffect.parentEntity, + apiEffect.parent, apiEffect.renderer, apiEffect.width, apiEffect.height diff --git a/src/r3-d3-api-face.js b/src/r3-d3-api-face.js index 1c7deed..86255ea 100644 --- a/src/r3-d3-api-face.js +++ b/src/r3-d3-api-face.js @@ -13,7 +13,7 @@ * @param normal * @param selected * @param parentGeometry - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Face = function( @@ -30,7 +30,7 @@ R3.D3.API.Face = function( normal, selected, parentGeometry, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -69,15 +69,15 @@ R3.D3.API.Face = function( this.uvs = uvs; if (R3.Utils.UndefinedOrNull(color)) { - color = new R3.API.Color(); + color = new R3.API.Color(this); } this.color = color; if (R3.Utils.UndefinedOrNull(vertexColors)) { vertexColors = [ - new R3.API.Color(), - new R3.API.Color(), - new R3.API.Color() + new R3.API.Color(this), + new R3.API.Color(this), + new R3.API.Color(this) ]; } this.vertexColors = vertexColors; @@ -105,7 +105,7 @@ R3.D3.API.Face = function( R3.API.Component.call( this, R3.Component.FACE, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-fog.js b/src/r3-d3-api-fog.js index 34e0df4..47cbb5f 100644 --- a/src/r3-d3-api-fog.js +++ b/src/r3-d3-api-fog.js @@ -7,7 +7,7 @@ * @param near * @param far * @param density - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Fog = function( @@ -18,7 +18,7 @@ R3.D3.API.Fog = function( near, far, density, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -37,7 +37,7 @@ R3.D3.API.Fog = function( this.exponential = exponential; if (R3.Utils.UndefinedOrNull(color)) { - color = new R3.API.Color(1, 1, 1, 1) + color = new R3.API.Color(this, 1, 1, 1, 1) } this.color = color; @@ -59,7 +59,7 @@ R3.D3.API.Fog = function( R3.API.Component.call( this, R3.Component.FOG, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-font.js b/src/r3-d3-api-font.js index aeca15c..2c586d1 100644 --- a/src/r3-d3-api-font.js +++ b/src/r3-d3-api-font.js @@ -3,14 +3,14 @@ * @param id * @param name * @param url - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Font = function( id, name, url, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); @@ -30,7 +30,7 @@ R3.D3.API.Font = function( R3.API.Component.call( this, R3.Component.FONT, - parentEntity + parent ); }; @@ -47,6 +47,6 @@ R3.D3.API.Font.FromObject = function(objectFont) { objectFont.id, objectFont.name, objectFont.url, - objectFont.parentEntity + objectFont.parent ); }; diff --git a/src/r3-d3-api-friction-contact-material.js b/src/r3-d3-api-friction-contact-material.js index 6259c77..ef6d3fd 100644 --- a/src/r3-d3-api-friction-contact-material.js +++ b/src/r3-d3-api-friction-contact-material.js @@ -9,7 +9,7 @@ * @param contactEquationRelaxation * @param frictionEquationStiffness * @param frictionEquationRelaxation - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.FrictionContactMaterial = function( @@ -22,7 +22,7 @@ R3.D3.API.FrictionContactMaterial = function( contactEquationRelaxation, frictionEquationStiffness, frictionEquationRelaxation, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -73,7 +73,7 @@ R3.D3.API.FrictionContactMaterial = function( R3.API.Component.call( this, R3.Component.FRICTION_CONTACT_MATERIAL, - parentEntity + parent ); }; @@ -96,7 +96,7 @@ R3.D3.API.FrictionContactMaterial.FromObject = function(objectFrictionContactMat objectFrictionContactMaterial.contactEquationRelaxation, objectFrictionContactMaterial.frictionEquationStiffness, objectFrictionContactMaterial.frictionEquationRelaxation, - objectFrictionContactMaterial.parentEntity + objectFrictionContactMaterial.parent ); }; diff --git a/src/r3-d3-api-friction-material.js b/src/r3-d3-api-friction-material.js index 17f6193..1846ae4 100644 --- a/src/r3-d3-api-friction-material.js +++ b/src/r3-d3-api-friction-material.js @@ -4,7 +4,7 @@ * @param name * @param friction * @param restitution - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.FrictionMaterial = function( @@ -12,7 +12,7 @@ R3.D3.API.FrictionMaterial = function( name, friction, restitution, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -38,7 +38,7 @@ R3.D3.API.FrictionMaterial = function( R3.API.Component.call( this, R3.Component.FRICTION_MATERIAL, - parentEntity + parent ); }; @@ -56,7 +56,7 @@ R3.D3.API.FrictionMaterial.FromObject = function(objectFrictionMaterial) { objectFrictionMaterial.name, objectFrictionMaterial.friction, objectFrictionMaterial.restitution, - objectFrictionMaterial.parentEntity + objectFrictionMaterial.parent ); }; diff --git a/src/r3-d3-api-geometry-a.js b/src/r3-d3-api-geometry-a.js index 8f31a6e..650fa3d 100644 --- a/src/r3-d3-api-geometry-a.js +++ b/src/r3-d3-api-geometry-a.js @@ -3,7 +3,7 @@ * @param id * @param name * @param geometryType - * @param parentEntity + * @param parent * @param parentMesh * @param boundingBox * @param boundingSphere @@ -15,7 +15,7 @@ R3.D3.API.Geometry = function( id, name, geometryType, - parentEntity, + parent, parentMesh, boundingBox, boundingSphere, @@ -207,7 +207,7 @@ R3.D3.API.Geometry = function( R3.API.Component.call( this, R3.D3.API.Geometry.GetComponentType(this.geometryType), - parentEntity + parent ); }; diff --git a/src/r3-d3-api-geometry-buffer-a.js b/src/r3-d3-api-geometry-buffer-a.js index 7d03872..8ef9c9c 100644 --- a/src/r3-d3-api-geometry-buffer-a.js +++ b/src/r3-d3-api-geometry-buffer-a.js @@ -56,7 +56,7 @@ R3.D3.API.Geometry.Buffer = function( apiGeometry.id, apiGeometry.name, apiGeometry.geometryType, - apiGeometry.parentEntity, + apiGeometry.parent, apiGeometry.parentMesh, apiGeometry.boundingBox, apiGeometry.boundingSphere, diff --git a/src/r3-d3-api-geometry-normal-a.js b/src/r3-d3-api-geometry-normal-a.js index fe3eb33..c355d35 100644 --- a/src/r3-d3-api-geometry-normal-a.js +++ b/src/r3-d3-api-geometry-normal-a.js @@ -112,7 +112,7 @@ R3.D3.API.Geometry.Normal = function( apiGeometry.id, apiGeometry.name, apiGeometry.geometryType, - apiGeometry.parentEntity, + apiGeometry.parent, apiGeometry.parentMesh, apiGeometry.boundingBox, apiGeometry.boundingSphere, diff --git a/src/r3-d3-api-light-a.js b/src/r3-d3-api-light-a.js index 930ce81..6adff86 100644 --- a/src/r3-d3-api-light-a.js +++ b/src/r3-d3-api-light-a.js @@ -6,7 +6,7 @@ * @param color * @param intensity * @param parentScene - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Light = function( @@ -16,7 +16,7 @@ R3.D3.API.Light = function( color, intensity, parentScene, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); @@ -59,7 +59,7 @@ R3.D3.API.Light = function( this.name = name; if (R3.Utils.UndefinedOrNull(color)) { - color = new R3.API.Color(1,1,1); + color = new R3.API.Color(this, 1,1,1); } this.color = color; @@ -78,7 +78,7 @@ R3.D3.API.Light = function( R3.API.Component.call( this, componentType, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-light-ambient.js b/src/r3-d3-api-light-ambient.js index ba0ef28..8966584 100644 --- a/src/r3-d3-api-light-ambient.js +++ b/src/r3-d3-api-light-ambient.js @@ -25,7 +25,7 @@ R3.D3.API.Light.Ambient = function( apiLight.color, apiLight.intensity, apiLight.parentScene, - apiLight.parentEntity + apiLight.parent ); }; diff --git a/src/r3-d3-api-light-directional.js b/src/r3-d3-api-light-directional.js index 09d99da..56f5eea 100644 --- a/src/r3-d3-api-light-directional.js +++ b/src/r3-d3-api-light-directional.js @@ -60,7 +60,7 @@ R3.D3.API.Light.Directional = function( apiLight.color, apiLight.intensity, apiLight.parentScene, - apiLight.parentEntity + apiLight.parent ); }; diff --git a/src/r3-d3-api-light-hemisphere.js b/src/r3-d3-api-light-hemisphere.js index 2676096..a4d9dda 100644 --- a/src/r3-d3-api-light-hemisphere.js +++ b/src/r3-d3-api-light-hemisphere.js @@ -30,7 +30,7 @@ R3.D3.API.Light.Hemisphere = function( this.position = position; if (R3.Utils.UndefinedOrNull(groundColor)) { - groundColor = new R3.API.Color(1,1,1); + groundColor = new R3.API.Color(this, 1,1,1); } this.groundColor = groundColor; @@ -42,7 +42,7 @@ R3.D3.API.Light.Hemisphere = function( apiLight.color, apiLight.intensity, apiLight.parentScene, - apiLight.parentEntity + apiLight.parent ); }; diff --git a/src/r3-d3-api-light-point.js b/src/r3-d3-api-light-point.js index 4caadca..b5afe88 100644 --- a/src/r3-d3-api-light-point.js +++ b/src/r3-d3-api-light-point.js @@ -72,7 +72,7 @@ R3.D3.API.Light.Point = function( apiLight.color, apiLight.intensity, apiLight.parentScene, - apiLight.parentEntity + apiLight.parent ); }; diff --git a/src/r3-d3-api-light-rect-area.js b/src/r3-d3-api-light-rect-area.js index f0e0760..ea9200f 100644 --- a/src/r3-d3-api-light-rect-area.js +++ b/src/r3-d3-api-light-rect-area.js @@ -83,7 +83,7 @@ R3.D3.API.Light.RectArea = function( apiLight.color, apiLight.intensity, apiLight.parentScene, - apiLight.parentEntity + apiLight.parent ); }; diff --git a/src/r3-d3-api-light-spot.js b/src/r3-d3-api-light-spot.js index 10a7437..f88e83e 100644 --- a/src/r3-d3-api-light-spot.js +++ b/src/r3-d3-api-light-spot.js @@ -103,7 +103,7 @@ R3.D3.API.Light.Spot = function( apiLight.color, apiLight.intensity, apiLight.parentScene, - apiLight.parentEntity + apiLight.parent ); }; diff --git a/src/r3-d3-api-material-a.js b/src/r3-d3-api-material-a.js index 6ceb115..c06ca8f 100644 --- a/src/r3-d3-api-material-a.js +++ b/src/r3-d3-api-material-a.js @@ -3,7 +3,7 @@ * @param id * @param name * @param materialType - * @param parentEntity + * @param parent * @param parentMeshes * @param alphaTest * @param blendDst @@ -44,7 +44,7 @@ R3.D3.API.Material = function( id, name, materialType, - parentEntity, + parent, parentMeshes, alphaTest, blendDst, @@ -308,7 +308,7 @@ R3.D3.API.Material = function( R3.API.Component.call( this, componentType, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-material-basic.js b/src/r3-d3-api-material-basic.js index d4f4d5a..1dc31ad 100644 --- a/src/r3-d3-api-material-basic.js +++ b/src/r3-d3-api-material-basic.js @@ -69,7 +69,7 @@ R3.D3.API.Material.Basic = function( this.aoMapIntensity = aoMapIntensity; if (R3.Utils.UndefinedOrNull(color)) { - color = new R3.API.Color(1, 1, 1, 1) + color = new R3.API.Color(this, 1, 1, 1, 1) } this.color = color; @@ -148,7 +148,7 @@ R3.D3.API.Material.Basic = function( apiMaterial.id, apiMaterial.name, apiMaterial.materialType, - apiMaterial.parentEntity, + apiMaterial.parent, apiMaterial.parentMeshes, apiMaterial.alphaTest, apiMaterial.blendDst, diff --git a/src/r3-d3-api-material-phong.js b/src/r3-d3-api-material-phong.js index a99b362..87ebf44 100644 --- a/src/r3-d3-api-material-phong.js +++ b/src/r3-d3-api-material-phong.js @@ -105,7 +105,7 @@ R3.D3.API.Material.Phong = function( this.bumpScale = bumpScale; if (R3.Utils.UndefinedOrNull(color)) { - color = new R3.API.Color(1, 1, 1, 1); + color = new R3.API.Color(this, 1, 1, 1, 1); } this.color = color; @@ -130,7 +130,7 @@ R3.D3.API.Material.Phong = function( this.displacementScale = displacementScale; if (R3.Utils.UndefinedOrNull(emissive)) { - emissive = new R3.API.Color(0, 0, 0, 0); + emissive = new R3.API.Color(this, 0, 0, 0, 0); } this.emissive = emissive; @@ -205,7 +205,7 @@ R3.D3.API.Material.Phong = function( this.skinning = skinning; if (R3.Utils.UndefinedOrNull(specular)) { - specular = new R3.API.Color(0.06, 0.06, 0.06, 0); + specular = new R3.API.Color(this, 0.06, 0.06, 0.06, 0); } this.specular = specular; @@ -239,7 +239,7 @@ R3.D3.API.Material.Phong = function( apiMaterial.id, apiMaterial.name, apiMaterial.materialType, - apiMaterial.parentEntity, + apiMaterial.parent, apiMaterial.parentMeshes, apiMaterial.alphaTest, apiMaterial.blendDst, diff --git a/src/r3-d3-api-material-points.js b/src/r3-d3-api-material-points.js index e07fc61..6349ee0 100644 --- a/src/r3-d3-api-material-points.js +++ b/src/r3-d3-api-material-points.js @@ -26,7 +26,7 @@ R3.D3.API.Material.Points = function( } if (R3.Utils.UndefinedOrNull(color)) { - color = new R3.API.Color(1, 1, 1, 1) + color = new R3.API.Color(this, 1, 1, 1, 1) } this.color = color; @@ -50,7 +50,7 @@ R3.D3.API.Material.Points = function( apiMaterial.id, apiMaterial.name, apiMaterial.materialType, - apiMaterial.parentEntity, + apiMaterial.parent, apiMaterial.parentMeshes, apiMaterial.alphaTest, apiMaterial.blendDst, diff --git a/src/r3-d3-api-material-shader-a.js b/src/r3-d3-api-material-shader-a.js index b34ab57..13fc2c7 100644 --- a/src/r3-d3-api-material-shader-a.js +++ b/src/r3-d3-api-material-shader-a.js @@ -127,7 +127,7 @@ R3.D3.API.Material.Shader = function( apiMaterial.id, apiMaterial.name, apiMaterial.materialType, - apiMaterial.parentEntity, + apiMaterial.parent, apiMaterial.parentMeshes, apiMaterial.alphaTest, apiMaterial.blendDst, diff --git a/src/r3-d3-api-material-standard.js b/src/r3-d3-api-material-standard.js index 98f71b0..5513e19 100644 --- a/src/r3-d3-api-material-standard.js +++ b/src/r3-d3-api-material-standard.js @@ -105,7 +105,7 @@ R3.D3.API.Material.Standard = function( this.bumpScale = bumpScale; if (R3.Utils.UndefinedOrNull(color)) { - color = new R3.API.Color(1, 1, 1, 1) + color = new R3.API.Color(this, 1, 1, 1, 1) } this.color = color; @@ -125,7 +125,7 @@ R3.D3.API.Material.Standard = function( this.displacementScale = displacementScale; if (R3.Utils.UndefinedOrNull(emissive)) { - emissive = new R3.API.Color(0, 0, 0, 0); + emissive = new R3.API.Color(this, 0, 0, 0, 0); } this.emissive = emissive; @@ -239,7 +239,7 @@ R3.D3.API.Material.Standard = function( apiMaterial.id, apiMaterial.name, apiMaterial.materialType, - apiMaterial.parentEntity, + apiMaterial.parent, apiMaterial.parentMeshes, apiMaterial.alphaTest, apiMaterial.blendDst, diff --git a/src/r3-d3-api-mesh-0.js b/src/r3-d3-api-mesh-0.js index 0d36907..f796171 100644 --- a/src/r3-d3-api-mesh-0.js +++ b/src/r3-d3-api-mesh-0.js @@ -5,7 +5,7 @@ * @param materials * @param parentMesh * @param parentScene - * @param excludeFromEnvironment + * @param excludeFromEnvironmentMapMap * @param skeleton * @param renderOrder * @param visible @@ -23,7 +23,7 @@ R3.D3.API.Mesh = function( materials, parentMesh, parentScene, - excludeFromEnvironment, + excludeFromEnvironmentMapMap, skeleton, renderOrder, visible, @@ -79,10 +79,10 @@ R3.D3.API.Mesh = function( } this.parentScene = parentScene; - if (R3.Utils.UndefinedOrNull(excludeFromEnvironment)) { - excludeFromEnvironment = false; + if (R3.Utils.UndefinedOrNull(excludeFromEnvironmentMapMap)) { + excludeFromEnvironmentMapMap = false; } - this.excludeFromEnvironment = excludeFromEnvironment; + this.excludeFromEnvironmentMapMap = excludeFromEnvironmentMapMap; if (R3.Utils.UndefinedOrNull(skeleton)) { skeleton = null; @@ -134,7 +134,7 @@ R3.D3.API.Mesh = function( apiD3Object.id, apiD3Object.name, apiD3Object.objectType, - apiD3Object.parentEntity, + apiD3Object.parent, apiD3Object.useQuaternion, apiD3Object.position, apiD3Object.quaternion, diff --git a/src/r3-d3-api-particle-engine.js b/src/r3-d3-api-particle-engine.js index 25d2fcd..b22afa3 100644 --- a/src/r3-d3-api-particle-engine.js +++ b/src/r3-d3-api-particle-engine.js @@ -12,7 +12,7 @@ * @param camera * @param pulse * @param fired - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.ParticleEngine = function( @@ -28,7 +28,7 @@ R3.D3.API.ParticleEngine = function( camera, pulse, fired, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -94,7 +94,7 @@ R3.D3.API.ParticleEngine = function( R3.API.Component.call( this, R3.Component.PARTICLE_ENGINE, - parentEntity + parent ); }; @@ -150,7 +150,7 @@ R3.D3.API.ParticleEngine.FromObject = function(objectParticleEngine) { objectParticleEngine.elapsed, apiCamera, objectParticleEngine.pulse, - objectParticleEngine.parentEntity + objectParticleEngine.parent ); diff --git a/src/r3-d3-api-particle.js b/src/r3-d3-api-particle.js index 02562dc..15b3b38 100644 --- a/src/r3-d3-api-particle.js +++ b/src/r3-d3-api-particle.js @@ -25,7 +25,7 @@ * @param rotationType * @param rotationFn * @param parentParticleEngine - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Particle = function( @@ -54,7 +54,7 @@ R3.D3.API.Particle = function( rotation, rotationFn, parentParticleEngine, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -185,7 +185,7 @@ R3.D3.API.Particle = function( R3.API.Component.call( this, R3.Component.PARTICLE, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-pass-0.js b/src/r3-d3-api-pass-0.js index c9e5872..9bf09c3 100644 --- a/src/r3-d3-api-pass-0.js +++ b/src/r3-d3-api-pass-0.js @@ -3,15 +3,15 @@ * @param id * @param name * @param passType - * @param parentEntity + * @param parent * @param renderToScreen * @constructor */ -R3.D3.API.Pass = function ( +R3.D3.API.Pass = function( id, name, passType, - parentEntity, + parent, renderToScreen ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -57,7 +57,7 @@ R3.D3.API.Pass = function ( R3.API.Component.call( this, componentType, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-pass-bloom.js b/src/r3-d3-api-pass-bloom.js index 934947c..c0396a4 100644 --- a/src/r3-d3-api-pass-bloom.js +++ b/src/r3-d3-api-pass-bloom.js @@ -9,7 +9,7 @@ * @param threshold * @constructor */ -R3.D3.API.Pass.Bloom = function ( +R3.D3.API.Pass.Bloom = function( apiPass, autoUpdateSize, width, @@ -63,7 +63,7 @@ R3.D3.API.Pass.Bloom = function ( apiPass.id, apiPass.name, apiPass.passType, - apiPass.parentEntity, + apiPass.parent, apiPass.renderToScreen ) }; diff --git a/src/r3-d3-api-pass-fxaa.js b/src/r3-d3-api-pass-fxaa.js index ffedbd4..82c9305 100644 --- a/src/r3-d3-api-pass-fxaa.js +++ b/src/r3-d3-api-pass-fxaa.js @@ -6,7 +6,7 @@ * @param height * @constructor */ -R3.D3.API.Pass.FXAA = function ( +R3.D3.API.Pass.FXAA = function( apiPass, autoUpdateSize, width, @@ -42,7 +42,7 @@ R3.D3.API.Pass.FXAA = function ( apiPass.id, apiPass.name, apiPass.passType, - apiPass.parentEntity, + apiPass.parent, apiPass.renderToScreen ) }; diff --git a/src/r3-d3-api-pass-render.js b/src/r3-d3-api-pass-render.js index d239964..f4d0785 100644 --- a/src/r3-d3-api-pass-render.js +++ b/src/r3-d3-api-pass-render.js @@ -5,7 +5,7 @@ * @param scene * @constructor */ -R3.D3.API.Pass.Render = function ( +R3.D3.API.Pass.Render = function( apiPass, scene, camera @@ -35,7 +35,7 @@ R3.D3.API.Pass.Render = function ( apiPass.id, apiPass.name, apiPass.passType, - apiPass.parentEntity, + apiPass.parent, apiPass.renderToScreen ) }; diff --git a/src/r3-d3-api-pass-ssao.js b/src/r3-d3-api-pass-ssao.js index f2cc805..7ca7698 100644 --- a/src/r3-d3-api-pass-ssao.js +++ b/src/r3-d3-api-pass-ssao.js @@ -9,7 +9,7 @@ * @param lumInfluence * @constructor */ -R3.D3.API.Pass.SSAO = function ( +R3.D3.API.Pass.SSAO = function( apiPass, scene, camera, @@ -63,7 +63,7 @@ R3.D3.API.Pass.SSAO = function ( apiPass.id, apiPass.name, apiPass.passType, - apiPass.parentEntity, + apiPass.parent, apiPass.renderToScreen ) }; diff --git a/src/r3-d3-api-physics-world.js b/src/r3-d3-api-physics-world.js index 8e88bb2..1244d49 100644 --- a/src/r3-d3-api-physics-world.js +++ b/src/r3-d3-api-physics-world.js @@ -9,7 +9,7 @@ * @param contactMaterials * @param allowSleep * @param defaultContactMaterial - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.PhysicsWorld = function( @@ -22,7 +22,7 @@ R3.D3.API.PhysicsWorld = function( contactMaterials, allowSleep, defaultContactMaterial, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -82,7 +82,7 @@ R3.D3.API.PhysicsWorld = function( R3.API.Component.call( this, R3.Component.PHYSICS_WORLD, - parentEntity + parent ); }; @@ -105,7 +105,7 @@ R3.D3.API.PhysicsWorld.FromObject = function(objectWorld) { objectWorld.contactMaterials, objectWorld.allowSleep, objectWorld.defaultContactMaterial, - objectWorld.parentEntity + objectWorld.parent ); }; diff --git a/src/r3-d3-api-raycast-vehicle.js b/src/r3-d3-api-raycast-vehicle.js index 02983de..4c89ac5 100644 --- a/src/r3-d3-api-raycast-vehicle.js +++ b/src/r3-d3-api-raycast-vehicle.js @@ -6,7 +6,7 @@ * @param wheels * @param raycastWheels * @param parentPhysicsWorld - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.RaycastVehicle = function( @@ -16,7 +16,7 @@ R3.D3.API.RaycastVehicle = function( wheels, raycastWheels, parentPhysicsWorld, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -52,7 +52,7 @@ R3.D3.API.RaycastVehicle = function( R3.API.Component.call( this, R3.Component.RAYCAST_VEHICLE, - parentEntity + parent ); }; @@ -72,7 +72,7 @@ R3.D3.API.RaycastVehicle.FromObject = function(objectRaycastVehicle) { objectRaycastVehicle.wheels, objectRaycastVehicle.raycastWheels, objectRaycastVehicle.parentPhysicsWorld, - objectRaycastVehicle.parentEntity + objectRaycastVehicle.parent ); }; diff --git a/src/r3-d3-api-raycast-wheel.js b/src/r3-d3-api-raycast-wheel.js index 8f1b6d4..d98301a 100644 --- a/src/r3-d3-api-raycast-wheel.js +++ b/src/r3-d3-api-raycast-wheel.js @@ -16,7 +16,7 @@ * @param maxSuspensionTravel * @param customSlidingRotationalSpeed * @param useCustomSlidingRotationalSpeed - * @param parentEntity + * @param parent * @param parentMesh * @constructor */ @@ -38,7 +38,7 @@ R3.D3.API.RaycastWheel = function( customSlidingRotationalSpeed, useCustomSlidingRotationalSpeed, parentMesh, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -129,7 +129,7 @@ R3.D3.API.RaycastWheel = function( R3.API.Component.call( this, R3.Component.RAYCAST_WHEEL, - parentEntity + parent ); }; @@ -160,7 +160,7 @@ R3.D3.API.RaycastWheel.FromObject = function(objectRaycastWheel) { objectRaycastWheel.customSlidingRotationalSpeed, objectRaycastWheel.useCustomSlidingRotationalSpeed, objectRaycastWheel.parentMesh, - objectRaycastWheel.parentEntity + objectRaycastWheel.parent ); }; diff --git a/src/r3-d3-api-raycaster.js b/src/r3-d3-api-raycaster.js index c1c7fd2..e812906 100644 --- a/src/r3-d3-api-raycaster.js +++ b/src/r3-d3-api-raycaster.js @@ -4,13 +4,13 @@ * @param name * @param position R3.API.Vector3 * @param direction R3.API.Vector3 - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Raycaster = function( id, name, - parentEntity, + parent, position, direction ) { @@ -38,7 +38,7 @@ R3.D3.API.Raycaster = function( R3.API.Component.call( this, R3.Component.RAYCASTER, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-render-target-a.js b/src/r3-d3-api-render-target-a.js index 686473f..591d010 100644 --- a/src/r3-d3-api-render-target-a.js +++ b/src/r3-d3-api-render-target-a.js @@ -3,7 +3,7 @@ * @param id * @param name * @param renderTargetType - * @param parentEntity + * @param parent * @param autoUpdateSize * @param width * @param height @@ -17,11 +17,11 @@ * @param textureParameters * @constructor */ -R3.D3.API.RenderTarget = function ( +R3.D3.API.RenderTarget = function( id, name, renderTargetType, - parentEntity, + parent, autoUpdateSize, width, height, @@ -85,7 +85,7 @@ R3.D3.API.RenderTarget = function ( this.scissorTest = scissorTest; if (R3.Utils.UndefinedOrNull(viewport)) { - viewport = new R3.D3.API.Viewport(null, 'Viewport RT ' + this.id); + viewport = null; } this.viewport = viewport; @@ -119,7 +119,7 @@ R3.D3.API.RenderTarget = function ( R3.API.Component.call( this, componentType, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-render-target-cube.js b/src/r3-d3-api-render-target-cube.js index a82f922..5742c34 100644 --- a/src/r3-d3-api-render-target-cube.js +++ b/src/r3-d3-api-render-target-cube.js @@ -3,7 +3,7 @@ * @constructor * @param apiRenderTarget */ -R3.D3.API.RenderTarget.Cube = function ( +R3.D3.API.RenderTarget.Cube = function( apiRenderTarget ) { @@ -32,7 +32,7 @@ R3.D3.API.RenderTarget.Cube = function ( apiRenderTarget.id, apiRenderTarget.name, apiRenderTarget.renderTargetType, - apiRenderTarget.parentEntity, + apiRenderTarget.parent, apiRenderTarget.autoUpdateSize, apiRenderTarget.width, apiRenderTarget.height, diff --git a/src/r3-d3-api-rigid-body.js b/src/r3-d3-api-rigid-body.js index f1d4d89..63c15d0 100644 --- a/src/r3-d3-api-rigid-body.js +++ b/src/r3-d3-api-rigid-body.js @@ -20,7 +20,7 @@ * @param kinematic * @param parentMesh * @param parentPhysicsWorld - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.RigidBody = function( @@ -44,7 +44,7 @@ R3.D3.API.RigidBody = function( kinematic, parentMesh, parentPhysicsWorld, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -150,7 +150,7 @@ R3.D3.API.RigidBody = function( R3.API.Component.call( this, R3.Component.RIGID_BODY, - parentEntity + parent ); }; @@ -184,7 +184,7 @@ R3.D3.API.RigidBody.FromObject = function(objectRigidBody) { objectRigidBody.kinematic, objectRigidBody.parentMesh, objectRigidBody.parentPhysicsWorld, - objectRigidBody.parentEntity + objectRigidBody.parent ); }; diff --git a/src/r3-d3-api-scene.js b/src/r3-d3-api-scene.js index 03549c0..07f4db5 100644 --- a/src/r3-d3-api-scene.js +++ b/src/r3-d3-api-scene.js @@ -12,8 +12,7 @@ * @param showAxis * @param gridSize * @param gridColor - * @param camera - this overrides the renderer camera - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Scene = function( @@ -29,8 +28,7 @@ R3.D3.API.Scene = function( showAxis, gridSize, gridColor, - camera, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -89,19 +87,14 @@ R3.D3.API.Scene = function( this.gridSize = gridSize; if (R3.Utils.UndefinedOrNull(gridColor)) { - gridColor = new R3.API.Color(0.14117641, 0.576470588, 0.882352941); + gridColor = new R3.API.Color(this, 0.14117641, 0.576470588, 0.882352941); } this.gridColor = gridColor; - if (R3.Utils.UndefinedOrNull(camera)) { - camera = null; - } - this.camera = camera; - R3.API.Component.call( this, R3.Component.SCENE, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-shader-a.js b/src/r3-d3-api-shader-a.js index b0bcd2a..f8db4b5 100644 --- a/src/r3-d3-api-shader-a.js +++ b/src/r3-d3-api-shader-a.js @@ -3,7 +3,7 @@ * @param id * @param name * @param shaderType - * @param parentEntity + * @param parent * @param parentMaterialShader * @param code * @constructor @@ -12,7 +12,7 @@ R3.D3.API.Shader = function( id, name, shaderType, - parentEntity, + parent, parentMaterialShader, code ) { @@ -72,7 +72,7 @@ R3.D3.API.Shader = function( R3.API.Component.call( this, R3.D3.API.Shader.GetComponentType(this.shaderType), - parentEntity + parent ); }; diff --git a/src/r3-d3-api-shader-fragment.js b/src/r3-d3-api-shader-fragment.js index 79cd367..312f6b3 100644 --- a/src/r3-d3-api-shader-fragment.js +++ b/src/r3-d3-api-shader-fragment.js @@ -22,7 +22,7 @@ R3.D3.API.Shader.Fragment = function( apiShader.id, apiShader.name, apiShader.shaderType, - apiShader.parentEntity, + apiShader.parent, apiShader.parentMaterialShader, apiShader.code ); diff --git a/src/r3-d3-api-shader-vertex.js b/src/r3-d3-api-shader-vertex.js index 0842171..ffcbebc 100644 --- a/src/r3-d3-api-shader-vertex.js +++ b/src/r3-d3-api-shader-vertex.js @@ -22,7 +22,7 @@ R3.D3.API.Shader.Vertex = function( apiShader.id, apiShader.name, apiShader.shaderType, - apiShader.parentEntity, + apiShader.parent, apiShader.parentMaterialShader, apiShader.code ); diff --git a/src/r3-d3-api-shadow-a.js b/src/r3-d3-api-shadow-a.js index 4d38c1e..ba73e68 100644 --- a/src/r3-d3-api-shadow-a.js +++ b/src/r3-d3-api-shadow-a.js @@ -7,7 +7,7 @@ * @param bias * @param mapSize * @param radius - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Shadow = function( @@ -18,7 +18,7 @@ R3.D3.API.Shadow = function( bias, mapSize, radius, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); @@ -116,7 +116,7 @@ R3.D3.API.Shadow = function( R3.API.Component.call( this, componentType, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-shadow-directional.js b/src/r3-d3-api-shadow-directional.js index a27d2b3..df81ab7 100644 --- a/src/r3-d3-api-shadow-directional.js +++ b/src/r3-d3-api-shadow-directional.js @@ -26,7 +26,7 @@ R3.D3.API.Shadow.Directional = function( apiDirectionalShadow.bias, apiDirectionalShadow.mapSize, apiDirectionalShadow.radius, - apiDirectionalShadow.parentEntity + apiDirectionalShadow.parent ); }; diff --git a/src/r3-d3-api-shadow-spot.js b/src/r3-d3-api-shadow-spot.js index 15efa15..30b7452 100644 --- a/src/r3-d3-api-shadow-spot.js +++ b/src/r3-d3-api-shadow-spot.js @@ -39,7 +39,7 @@ R3.D3.API.Shadow.Spot = function( apiSpotShadow.bias, apiSpotShadow.mapSize, apiSpotShadow.radius, - apiSpotShadow.parentEntity + apiSpotShadow.parent ); }; diff --git a/src/r3-d3-api-shape.js b/src/r3-d3-api-shape.js index dacf8dc..fa80b46 100644 --- a/src/r3-d3-api-shape.js +++ b/src/r3-d3-api-shape.js @@ -7,7 +7,7 @@ * @param collisionResponse * @param frictionMaterial * @param parentMesh - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Shape = function( @@ -18,7 +18,7 @@ R3.D3.API.Shape = function( collisionResponse, frictionMaterial, parentMesh, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -118,7 +118,7 @@ R3.D3.API.Shape = function( R3.API.Component.call( this, componentType, - parentEntity + parent ); }; @@ -148,7 +148,7 @@ R3.D3.API.Shape.FromObject = function(objectShape) { objectShape.collisionResponse, objectShape.frictionMaterial, objectShape.parentMesh, - objectShape.parentEntity + objectShape.parent ); }; diff --git a/src/r3-d3-api-skeleton.js b/src/r3-d3-api-skeleton.js index 757280c..888012a 100644 --- a/src/r3-d3-api-skeleton.js +++ b/src/r3-d3-api-skeleton.js @@ -9,10 +9,10 @@ * @param boneTextureHeight Number * @param boneMatrices R3.API.Matrix4[] * @param boneTexture null (not implemented) - * @param parentEntity + * @param parent * @constructor */ -R3.D3.API.Skeleton = function ( +R3.D3.API.Skeleton = function( id, name, bones, @@ -22,7 +22,7 @@ R3.D3.API.Skeleton = function ( boneTextureHeight, boneMatrices, boneTexture, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); @@ -81,7 +81,7 @@ R3.D3.API.Skeleton = function ( R3.API.Component.call( this, R3.Component.SKELETON, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-solver.js b/src/r3-d3-api-solver.js index a3e1e88..e29affd 100644 --- a/src/r3-d3-api-solver.js +++ b/src/r3-d3-api-solver.js @@ -5,7 +5,7 @@ * @param solverType * @param iterations * @param tolerance - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Solver = function( @@ -14,7 +14,7 @@ R3.D3.API.Solver = function( solverType, iterations, tolerance, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -45,7 +45,7 @@ R3.D3.API.Solver = function( R3.API.Component.call( this, R3.Component.SOLVER, - parentEntity + parent ); }; @@ -71,7 +71,7 @@ R3.D3.API.Solver.FromObject = function(objectSolver) { objectSolver.solverType, objectSolver.iterations, objectSolver.tolerance, - objectSolver.parentEntity + objectSolver.parent ); }; diff --git a/src/r3-d3-api-spline.js b/src/r3-d3-api-spline.js index ef041f0..b7c8bc9 100644 --- a/src/r3-d3-api-spline.js +++ b/src/r3-d3-api-spline.js @@ -3,14 +3,14 @@ * @param id String * @param name String * @param vertices R3.API.Vector3[] - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Spline = function( id, name, vertices, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); @@ -30,7 +30,7 @@ R3.D3.API.Spline = function( R3.API.Component.call( this, R3.Component.SPLINE, - parentEntity + parent ); }; @@ -47,10 +47,10 @@ R3.D3.API.Spline.FromObject = function(objectComponent) { objectComponent.id, objectComponent.name, objectComponent.vertices.map( - function (objectVertex) { + function(objectVertex) { return R3.API.Vector3.FromObject(objectVertex); } ), - objectComponent.parentEntity + objectComponent.parent ); }; diff --git a/src/r3-d3-api-text.js b/src/r3-d3-api-text.js index 9a2a859..2ce15ab 100644 --- a/src/r3-d3-api-text.js +++ b/src/r3-d3-api-text.js @@ -7,7 +7,7 @@ * @param fillStyle * @param value * @param parentCanvas - * @param parentEntity + * @param parent * @constructor */ R3.D3.API.Text = function( @@ -18,7 +18,7 @@ R3.D3.API.Text = function( fillStyle, value, parentCanvas, - parentEntity + parent ) { if (R3.Utils.UndefinedOrNull(id)) { id = R3.Utils.RandomId(); @@ -58,7 +58,7 @@ R3.D3.API.Text = function( R3.API.Component.call( this, R3.Component.TEXT, - parentEntity + parent ); }; diff --git a/src/r3-d3-api-texture-a.js b/src/r3-d3-api-texture-a.js index 1f57713..0730c1c 100644 --- a/src/r3-d3-api-texture-a.js +++ b/src/r3-d3-api-texture-a.js @@ -3,7 +3,7 @@ * @param id * @param name * @param textureType - * @param parentEntity + * @param parent * @param parentMaterials * @param mipmaps * @param mapping @@ -34,7 +34,7 @@ R3.D3.API.Texture = function( id, name, textureType, - parentEntity, + parent, parentMaterials, mipmaps, mapping, @@ -217,7 +217,7 @@ R3.D3.API.Texture = function( R3.API.Component.call( this, R3.D3.API.Texture.GetComponentType(this.textureType), - parentEntity + parent ); }; diff --git a/src/r3-d3-api-texture-canvas.js b/src/r3-d3-api-texture-canvas.js index a4b0f62..8971f91 100644 --- a/src/r3-d3-api-texture-canvas.js +++ b/src/r3-d3-api-texture-canvas.js @@ -29,7 +29,7 @@ R3.D3.API.Texture.Canvas = function( apiTexture.id, apiTexture.name, apiTexture.textureType, - apiTexture.parentEntity, + apiTexture.parent, apiTexture.parentMaterials, apiTexture.mipmaps, apiTexture.mapping, diff --git a/src/r3-d3-api-texture-cube.js b/src/r3-d3-api-texture-cube.js index 4e41098..0554e0a 100644 --- a/src/r3-d3-api-texture-cube.js +++ b/src/r3-d3-api-texture-cube.js @@ -36,7 +36,7 @@ R3.D3.API.Texture.Cube = function( apiTexture.id, apiTexture.name, apiTexture.textureType, - apiTexture.parentEntity, + apiTexture.parent, apiTexture.parentMaterials, apiTexture.mipmaps, apiTexture.mapping, diff --git a/src/r3-d3-api-texture-image.js b/src/r3-d3-api-texture-image.js index 15f231c..6d1d0c5 100644 --- a/src/r3-d3-api-texture-image.js +++ b/src/r3-d3-api-texture-image.js @@ -29,7 +29,7 @@ R3.D3.API.Texture.Image = function( apiTexture.id, apiTexture.name, apiTexture.textureType, - apiTexture.parentEntity, + apiTexture.parent, apiTexture.parentMaterials, apiTexture.mipmaps, apiTexture.mapping, diff --git a/src/r3-d3-api-viewport-fixed-aspect.js b/src/r3-d3-api-viewport-fixed-aspect.js new file mode 100644 index 0000000..9d27d4c --- /dev/null +++ b/src/r3-d3-api-viewport-fixed-aspect.js @@ -0,0 +1,41 @@ +/** + * Raw Viewport API object - should always correspond with the Viewport Schema + * @constructor + * @param apiViewport + * @param aspectRatio + */ +R3.D3.API.Viewport.FixedAspect = function( + apiViewport, + aspectRatio +) { + + if (R3.Utils.UndefinedOrNull(apiViewport)) { + apiViewport = { + viewportType: R3.D3.API.Viewport.VIEWPORT_TYPE_FIXED_ASPECT + }; + } + + if (R3.Utils.UndefinedOrNull(apiViewport.viewportType)) { + apiViewport.viewportType = R3.D3.API.Viewport.VIEWPORT_TYPE_FIXED_ASPECT; + } + + if (R3.Utils.UndefinedOrNull(aspectRatio)) { + aspectRatio = R3.D3.API.Viewport.ASPECT_RATIO_16_9; + } + this.aspectRatio = aspectRatio; + + R3.D3.API.Viewport.call( + this, + apiViewport.id, + apiViewport.name, + apiViewport.viewportType, + apiViewport.parent, + apiViewport.width, + apiViewport.height, + apiViewport.x, + apiViewport.y + ); +}; + +R3.D3.API.Viewport.FixedAspect.prototype = Object.create(R3.D3.API.Viewport.prototype); +R3.D3.API.Viewport.FixedAspect.prototype.constructor = R3.D3.API.Viewport.FixedAspect; diff --git a/src/r3-d3-api-viewport-zoomed-aspect.js b/src/r3-d3-api-viewport-zoomed-aspect.js new file mode 100644 index 0000000..8353d70 --- /dev/null +++ b/src/r3-d3-api-viewport-zoomed-aspect.js @@ -0,0 +1,55 @@ +/** + * Raw Viewport API object - should always correspond with the Viewport Schema + * @constructor + * @param apiViewport + * @param aspectRatio + * @param expandWidth + * @param expandHeight + */ +R3.D3.API.Viewport.ZoomedAspect = function( + apiViewport, + aspectRatio, + expandWidth, + expandHeight +) { + + if (R3.Utils.UndefinedOrNull(apiViewport)) { + apiViewport = { + viewportType: R3.D3.API.Viewport.VIEWPORT_TYPE_ZOOMED_ASPECT + }; + } + + if (R3.Utils.UndefinedOrNull(apiViewport.viewportType)) { + apiViewport.viewportType = R3.D3.API.Viewport.VIEWPORT_TYPE_ZOOMED_ASPECT; + } + + if (R3.Utils.UndefinedOrNull(aspectRatio)) { + aspectRatio = R3.D3.API.Viewport.ASPECT_RATIO_16_9; + } + this.aspectRatio = aspectRatio; + + if (R3.Utils.UndefinedOrNull(expandWidth)) { + expandWidth = true; + } + this.expandWidth = expandWidth; + + if (R3.Utils.UndefinedOrNull(expandHeight)) { + expandHeight = true; + } + this.expandHeight = expandHeight; + + R3.D3.API.Viewport.call( + this, + apiViewport.id, + apiViewport.name, + apiViewport.viewportType, + apiViewport.parent, + apiViewport.width, + apiViewport.height, + apiViewport.x, + apiViewport.y + ); +}; + +R3.D3.API.Viewport.ZoomedAspect.prototype = Object.create(R3.D3.API.Viewport.prototype); +R3.D3.API.Viewport.ZoomedAspect.prototype.constructor = R3.D3.API.Viewport.ZoomedAspect; diff --git a/src/r3-d3-api-viewport.js b/src/r3-d3-api-viewport.js index 6adf18c..b9e6421 100644 --- a/src/r3-d3-api-viewport.js +++ b/src/r3-d3-api-viewport.js @@ -2,21 +2,39 @@ * Raw Viewport API object - should always correspond with the Viewport Schema * @param id * @param name + * @param viewportType * @param width * @param height * @param x * @param y - * @param parentEntity + * @param parent + * @param scene + * @param controls + * @param cameraIndexEdit + * @param cameraIndexRun + * @param composer + * @param effect + * @param enableComposer + * @param enableEffect * @constructor */ R3.D3.API.Viewport = function( id, name, + viewportType, + parent, width, height, x, y, - parentEntity + scene, + cameraIndexEdit, + cameraIndexRun, + controls, + composer, + effect, + enableComposer, + enableEffect ) { if (R3.Utils.UndefinedOrNull(id)) { @@ -24,8 +42,26 @@ R3.D3.API.Viewport = function( } this.id = id; + if (R3.Utils.UndefinedOrNull(viewportType)) { + viewportType = R3.D3.API.Viewport.VIEWPORT_TYPE_NORMAL; + } + this.viewportType = viewportType; + if (R3.Utils.UndefinedOrNull(name)) { - name = 'Viewport (' + this.id + ')'; + + switch (this.viewportType) { + case R3.D3.API.Viewport.VIEWPORT_TYPE_FIXED_ASPECT : + name = 'Fixed Aspect Viewport'; + break; + case R3.D3.API.Viewport.VIEWPORT_TYPE_ZOOMED_ASPECT : + name = 'Zoomed Aspect Viewport'; + break; + default: + name = 'Viewport'; + break; + } + + name += ' (' + id + ')'; } this.name = name; @@ -49,10 +85,55 @@ R3.D3.API.Viewport = function( } this.y = y; + if (R3.Utils.UndefinedOrNull(scene)) { + scene = new R3.D3.API.Scene(); + } + this.scene = scene; + + if (R3.Utils.UndefinedOrNull(cameraIndexEdit)) { + cameraIndexEdit = R3.API.Project.CAMERA_INDEX_EDIT; + } + this.cameraIndexEdit = cameraIndexEdit; + + if (R3.Utils.UndefinedOrNull(cameraIndexRun)) { + cameraIndexRun = R3.API.Project.CAMERA_INDEX_RUN; + } + this.cameraIndexRun = cameraIndexRun; + + if (R3.Utils.UndefinedOrNull(controls)) { + controls = new R3.API.Controls.D3.Orbit( + { + canvas: this.parent.canvas + }, + this.parent.parent.cameras[this.cameraIndexEdit] + ) + } + this.controls = controls; + + if (R3.Utils.UndefinedOrNull(composer)) { + composer = new R3.API.Composer(); + } + this.composer = composer; + + if (R3.Utils.UndefinedOrNull(effect)) { + effect = new R3.API.Effect(); + } + this.effect = effect; + + if (R3.Utils.UndefinedOrNull(enableComposer)) { + enableComposer = false; + } + this.enableComposer = enableComposer; + + if (R3.Utils.UndefinedOrNull(enableEffect)) { + enableEffect = false; + } + this.enableEffect = enableEffect; + R3.API.Component.call( this, - R3.Component.VIEWPORT, - parentEntity + R3.D3.API.Texture.GetComponentType(this.viewportType), + parent ); }; @@ -60,19 +141,67 @@ R3.D3.API.Viewport.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.Viewport.prototype.constructor = R3.D3.API.Viewport; /** - * Creates an API Viewport from an Object Viewport - * @param objectViewport + * Returns Component type based on Viewport type + * @param viewportType + * @returns {number} * @constructor */ -R3.D3.API.Viewport.FromObject = function(objectViewport) { - return new R3.D3.API.Viewport( - objectViewport.id, - objectViewport.name, - objectViewport.width, - objectViewport.height, - objectViewport.x, - objectViewport.y, - objectViewport.parentEntity - ); +R3.D3.API.Viewport.GetComponentType = function(viewportType) { + + var componentType = null; + + switch (viewportType) { + case R3.D3.API.Viewport.VIEWPORT_TYPE_NORMAL : + componentType = R3.Component.VIEWPORT; + break; + case R3.D3.API.Viewport.VIEWPORT_TYPE_FIXED_ASPECT : + componentType = R3.Component.VIEWPORT_FIXED_ASPECT; + break; + case R3.D3.API.Viewport.VIEWPORT_TYPE_ZOOMED_ASPECT: + componentType = R3.Component.VIEWPORT_ZOOMED_ASPECT; + break; + default : + throw new Error('unhandled texture type: ' + viewportType); + } + + return componentType; }; +/** + * VIEWPORT_TYPE_NORMAL = ignore aspect ratio and make viewport respect x,y,width and height as is + * VIEWPORT_TYPE_FIXED_ASPECT = respect the aspectRatio setting and adjust viewport x,y,width and height accordingly + * - entire viewport remains visible at all times + * - will have empty space above or below viewport depending on canvas size (if canvas ratio != viewport ratio) + * VIEWPORT_TYPE_ZOOMED_ASPECT = respect the aspectRatio setting and adjust viewport x,y,width and height - however + * - viewport remains centered around origin (0.5), but can be 'panned' using viewport.x + viewport.y offsets + * - with widescreen aspect ratios (w > h) : height is respected and width is cut off on edges + * - if the width of the canvas is greater than the width of the viewport - the viewport can be instructed to + * expand to the full width (default), or remain fixed (introducing spaces on the left and right edges), for + * this use the expandWidth boolean + * - with portrait aspect ratios (h > w) : width is respected and height is cut off above and below + * - if the height of the canvas is greater than the height of the viewport - the viewport can be instructed to + * expand to the full height (default), or remain fixed (introducing spaced on the top and bottom edges), for + * this use the expandHeight boolean. + * + * - when an 'expand' happens (either vertically or horizontally) - an R3.Event.VIEWPORT_EXPAND event will be + * triggered. This will allow you to create a 'zoom' effect by listening for this event and bringing the + * 'camera' associated to the zoom viewport closer to the scene. Exactly how much the camera would have to + * come closer to the scene in 3D coordinates, in order to keep the entire 2D space occupied, is out of the + * scope of this comment - but for orthogonal cameras this could be relatively simple + * + * - with 'expandHeight' and 'expandWidth' turned off, the VIEWPORT_TYPE_ZOOMED_ASPECT essentially behaves + * similar to a VIEWPORT_TYPE_FIXED_ASPECT in the case that the entire viewport actually fits into the canvas + * (when did this ever happen? wouldn't live have been great?) + * + * @type {number} + */ +R3.D3.API.Viewport.VIEWPORT_TYPE_NORMAL = 0x1; +R3.D3.API.Viewport.VIEWPORT_TYPE_FIXED_ASPECT = 0x2; +R3.D3.API.Viewport.VIEWPORT_TYPE_ZOOMED_ASPECT = 0x3; + +R3.D3.API.Viewport.ASPECT_RATIO_NONE = 0x1; +R3.D3.API.Viewport.ASPECT_RATIO_4_3 = 0x2; +R3.D3.API.Viewport.ASPECT_RATIO_3_2 = 0x3; +R3.D3.API.Viewport.ASPECT_RATIO_16_10 = 0x4; +R3.D3.API.Viewport.ASPECT_RATIO_17_10 = 0x5; +R3.D3.API.Viewport.ASPECT_RATIO_16_9 = 0x6; \ No newline at end of file diff --git a/src/r3-d3-api-z-animation.js b/src/r3-d3-api-z-animation.js index 1321480..c1057d1 100644 --- a/src/r3-d3-api-z-animation.js +++ b/src/r3-d3-api-z-animation.js @@ -24,7 +24,7 @@ R3.D3.Animation = function( apiAnimation.blocking, apiAnimation.applyToMeshWhenDone, apiAnimation.meshes, - apiAnimation.parentEntity + apiAnimation.parent ); this.functionType = R3.D3.Animation.ANIMATION_FUNCTION_TYPE_ROTATION; @@ -83,7 +83,7 @@ R3.D3.Animation.prototype.createInstance = function() { } } catch (error) { console.error(error); - this.publish( + this.emit( R3.Event.ANIMATION_COMPILE_FAILED, { component : this @@ -102,7 +102,7 @@ R3.D3.Animation.prototype.updateInstance = function(property, item) { if (property === 'rotationFn') { try { this.instance.rotation = new Function('data', this.rotationFn).bind(this); - this.publish( + this.emit( R3.Event.ANIMATION_COMPILE_SUCCESS, { component : this, @@ -111,7 +111,7 @@ R3.D3.Animation.prototype.updateInstance = function(property, item) { ) } catch (error) { console.error(error); - this.publish( + this.emit( R3.Event.ANIMATION_COMPILE_FAILED, { component : this @@ -123,7 +123,7 @@ R3.D3.Animation.prototype.updateInstance = function(property, item) { if (property === 'translationFn') { try { this.instance.translation = new Function('data', this.translationFn).bind(this); - this.publish( + this.emit( R3.Event.ANIMATION_COMPILE_SUCCESS, { component : this, @@ -132,7 +132,7 @@ R3.D3.Animation.prototype.updateInstance = function(property, item) { ); } catch (error) { console.error(error); - this.publish( + this.emit( R3.Event.ANIMATION_COMPILE_FAILED, { component : this @@ -144,7 +144,7 @@ R3.D3.Animation.prototype.updateInstance = function(property, item) { if (property === 'scaleFn') { try { this.instance.scale = new Function('data', this.scaleFn).bind(this); - this.publish( + this.emit( R3.Event.ANIMATION_COMPILE_SUCCESS, { component : this, @@ -153,7 +153,7 @@ R3.D3.Animation.prototype.updateInstance = function(property, item) { ) } catch (error) { console.error(error); - this.publish( + this.emit( R3.Event.ANIMATION_COMPILE_FAILED, { component : this @@ -198,7 +198,7 @@ R3.D3.Animation.prototype.toApiObject = function() { return R3.Utils.IdOrNull(mesh); } ), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-d3-api-z-object.js b/src/r3-d3-api-z-object.js index 340e6e6..ebcbcd4 100644 --- a/src/r3-d3-api-z-object.js +++ b/src/r3-d3-api-z-object.js @@ -5,7 +5,7 @@ * @property objectType * @constructor */ -R3.D3.Object = function ( +R3.D3.Object = function( graphics, apiObject ) { @@ -23,7 +23,7 @@ R3.D3.Object = function ( apiObject.id, apiObject.name, apiObject.objectType, - apiObject.parentEntity, + apiObject.parent, apiObject.useQuaternion, apiObject.position, apiObject.quaternion, @@ -317,7 +317,7 @@ R3.D3.Object.prototype.toApiObject = function() { this.id, this.name, this.objectType, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), this.useQuaternion, this.position.toApiObject(), this.quaternion.toApiObject(), diff --git a/src/r3-d3-audio.js b/src/r3-d3-audio.js index 7c2d8aa..b10d0cd 100644 --- a/src/r3-d3-audio.js +++ b/src/r3-d3-audio.js @@ -26,7 +26,7 @@ R3.D3.Audio = function( apiAudio.camera, apiAudio.overplay, apiAudio.pause, - apiAudio.parentEntity + apiAudio.parent ); R3.Component.call( @@ -79,7 +79,7 @@ R3.D3.Audio.prototype.createInstance = function() { try { audioLoader.load( this.apiUrl + this.path + '?ts=' + Date.now(), - function (buffer) { + function(buffer) { console.log('loaded audio: ' + this.name); @@ -136,7 +136,7 @@ R3.D3.Audio.prototype.toApiObject = function() { R3.Utils.IdOrNull(this.camera), this.overplay, this.paused, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-d3-bone-weight.js b/src/r3-d3-bone-weight.js index 3cd53a8..e7b6330 100644 --- a/src/r3-d3-bone-weight.js +++ b/src/r3-d3-bone-weight.js @@ -4,7 +4,7 @@ * @param graphics R3.GraphicsRuntime * @param apiBoneWeight R3.D3.API.BoneWeight */ -R3.D3.BoneWeight = function ( +R3.D3.BoneWeight = function( graphics, apiBoneWeight ) { diff --git a/src/r3-d3-bone.js b/src/r3-d3-bone.js index f9f6bc7..4c37414 100644 --- a/src/r3-d3-bone.js +++ b/src/r3-d3-bone.js @@ -4,7 +4,7 @@ * @param graphics R3.GraphicsRuntime * @param apiD3ObjectBone */ -R3.D3.Bone = function ( +R3.D3.Bone = function( graphics, apiD3ObjectBone ) { diff --git a/src/r3-d3-broadphase.js b/src/r3-d3-broadphase.js index 14c4779..02a7d2e 100644 --- a/src/r3-d3-broadphase.js +++ b/src/r3-d3-broadphase.js @@ -4,7 +4,7 @@ * @param apiBroadphase R3.D3.API.Broadphase * @constructor */ -R3.D3.Broadphase = function ( +R3.D3.Broadphase = function( physics, apiBroadphase ) { @@ -21,7 +21,7 @@ R3.D3.Broadphase = function ( apiBroadphase.id, apiBroadphase.name, apiBroadphase.broadphaseType, - apiBroadphase.parentEntity + apiBroadphase.parent ); R3.Component.call(this); @@ -94,7 +94,7 @@ R3.D3.Broadphase.prototype.toApiObject = function() { this.id, this.name, this.broadphaseType, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); return apiBroadphase; diff --git a/src/r3-d3-composer.js b/src/r3-d3-composer.js index bfe9a11..8a9a517 100644 --- a/src/r3-d3-composer.js +++ b/src/r3-d3-composer.js @@ -4,7 +4,7 @@ * @param apiComposer R3.D3.API.Composer * @constructor */ -R3.D3.Composer = function ( +R3.D3.Composer = function( graphics, apiComposer ) { @@ -20,7 +20,7 @@ R3.D3.Composer = function ( this, apiComposer.id, apiComposer.name, - apiComposer.parentEntity, + apiComposer.parent, apiComposer.autoUpdateSize, apiComposer.width, apiComposer.height, @@ -186,6 +186,23 @@ R3.D3.Composer.prototype.render = function() { this.instance.render(); }; +R3.D3.Composer.prototype.ready = function() { + + if (this.passes.length === 0) { + return false; + } + + return this.passes.reduce( + function(result, pass) { + if (!pass.instance) { + result = false; + } + return result; + }, + true + ) +}; + /** * R3.D3.Composer to R3.D3.API.Composer * @returns {R3.D3.API.Composer} @@ -195,7 +212,7 @@ R3.D3.Composer.prototype.toApiObject = function() { var apiComposer = new R3.D3.API.Composer( this.id, this.name, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), this.autoUpdateSize, this.width, this.height, diff --git a/src/r3-d3-effect-a.js b/src/r3-d3-effect-a.js index 241b4cf..2750549 100644 --- a/src/r3-d3-effect-a.js +++ b/src/r3-d3-effect-a.js @@ -21,12 +21,29 @@ R3.D3.Effect = function( apiEffect.id, apiEffect.name, apiEffect.effectType, - apiEffect.parentEntity, + apiEffect.parent, apiEffect.renderer, apiEffect.width, apiEffect.height ); + if (R3.Utils.UndefinedOrNull(this.render)) { + /** + * We don't have a renderer - get a handle on the project and initialize the renderer from there + */ + R3.Event.Emit( + R3.Event.GET_PROJECT, + function(project) { + + /** + * Assign the last created renderer to this effect + */ + this.renderer = project.renderers[project.renderers.length - 1]; + + }.bind(this) + ); + } + var linkedObjects = { renderer : R3.Renderer }; @@ -136,6 +153,29 @@ R3.D3.Effect.prototype.render = function(scene, camera) { ); }; +/** + * + * @param scene + * @param camera + * @returns {boolean} + */ +R3.D3.Effect.prototype.ready = function(scene, camera) { + + if (!this.instance) { + return false; + } + + if (!scene.instance) { + return false; + } + + if (!camera.instance) { + return false; + } + + return true; +}; + /** * Converts a R3.D3.Effect to a new R3.D3.API.Effect * @returns {R3.D3.API.Effect} @@ -146,7 +186,7 @@ R3.D3.Effect.prototype.toApiObject = function() { this.id, this.name, this.effectType, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), R3.Utils.IdOrNull(this.renderer), this.width, this.height diff --git a/src/r3-d3-face.js b/src/r3-d3-face.js index c57f494..ad682dc 100644 --- a/src/r3-d3-face.js +++ b/src/r3-d3-face.js @@ -37,7 +37,7 @@ R3.D3.Face = function( apiFace.normal, apiFace.selected, apiFace.parentGeometry, - apiFace.parentEntity + apiFace.parent ); if (this.implementation instanceof R3.GraphicsRuntime) { diff --git a/src/r3-d3-fog.js b/src/r3-d3-fog.js index 9eca435..6146657 100644 --- a/src/r3-d3-fog.js +++ b/src/r3-d3-fog.js @@ -5,7 +5,7 @@ * @param apiFog R3.D3.API.Fog * @constructor */ -R3.D3.Fog = function ( +R3.D3.Fog = function( graphics, apiFog ) { @@ -25,7 +25,7 @@ R3.D3.Fog = function ( apiFog.near, apiFog.far, apiFog.density, - apiFog.parentEntity + apiFog.parent ); this.color = new R3.Color( @@ -128,7 +128,7 @@ R3.D3.Fog.prototype.toApiObject = function() { this.near, this.far, this.density, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-d3-font.js b/src/r3-d3-font.js index 096d22e..403e3e8 100644 --- a/src/r3-d3-font.js +++ b/src/r3-d3-font.js @@ -20,7 +20,7 @@ R3.D3.Font = function( apiFont.id, apiFont.name, apiFont.url, - apiFont.parentEntity + apiFont.parent ); R3.Component.call(this); @@ -77,7 +77,7 @@ R3.D3.Font.prototype.toApiObject = function() { this.id, this.name, this.url, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-d3-friction-contact-material.js b/src/r3-d3-friction-contact-material.js index 992d22e..0247b01 100644 --- a/src/r3-d3-friction-contact-material.js +++ b/src/r3-d3-friction-contact-material.js @@ -4,7 +4,7 @@ * @param apiFrictionContactMaterial R3.D3.API.FrictionContactMaterial * @constructor */ -R3.D3.FrictionContactMaterial = function ( +R3.D3.FrictionContactMaterial = function( physics, apiFrictionContactMaterial ) { @@ -27,7 +27,7 @@ R3.D3.FrictionContactMaterial = function ( apiFrictionContactMaterial.contactEquationRelaxation, apiFrictionContactMaterial.frictionEquationStiffness, apiFrictionContactMaterial.frictionEquationRelaxation, - apiFrictionContactMaterial.parentEntity + apiFrictionContactMaterial.parent ); R3.Component.call( @@ -106,7 +106,7 @@ R3.D3.FrictionContactMaterial.prototype.toApiObject = function() { this.contactEquationRelaxation, this.frictionEquationStiffness, this.frictionEquationRelaxation, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); return apiFrictionContactMaterial; }; diff --git a/src/r3-d3-friction-material.js b/src/r3-d3-friction-material.js index 2ce462b..0e7b3e1 100644 --- a/src/r3-d3-friction-material.js +++ b/src/r3-d3-friction-material.js @@ -4,7 +4,7 @@ * @param apiFrictionMaterial R3.D3.API.FrictionMaterial * @constructor */ -R3.D3.FrictionMaterial = function ( +R3.D3.FrictionMaterial = function( physics, apiFrictionMaterial ) { @@ -22,7 +22,7 @@ R3.D3.FrictionMaterial = function ( apiFrictionMaterial.name, apiFrictionMaterial.friction, apiFrictionMaterial.restitution, - apiFrictionMaterial.parentEntity + apiFrictionMaterial.parent ); R3.Component.call(this); @@ -66,7 +66,7 @@ R3.D3.FrictionMaterial.prototype.toApiObject = function() { this.name, this.friction, this.restitution, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); return apiFrictionMaterial; diff --git a/src/r3-d3-geometry-a.js b/src/r3-d3-geometry-a.js index b0290a7..c9f07c1 100644 --- a/src/r3-d3-geometry-a.js +++ b/src/r3-d3-geometry-a.js @@ -24,7 +24,7 @@ R3.D3.Geometry = function( apiGeometry.id, apiGeometry.name, apiGeometry.geometryType, - apiGeometry.parentEntity, + apiGeometry.parent, apiGeometry.parentMesh, apiGeometry.boundingBox, apiGeometry.boundingSphere, @@ -191,7 +191,7 @@ R3.D3.Geometry.prototype.toApiObject = function() { this.id, this.name, this.geometryType, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), R3.Utils.IdOrNull(this.parentMesh), this.boundingBox.toApiObject(), this.boundingSphere.toApiObject(), @@ -201,7 +201,7 @@ R3.D3.Geometry.prototype.toApiObject = function() { } ), this.vertices.map( - function (vertex) { + function(vertex) { return vertex.toApiObject(); } ) diff --git a/src/r3-d3-geometry-normal-a.js b/src/r3-d3-geometry-normal-a.js index 76aece3..1ea5516 100644 --- a/src/r3-d3-geometry-normal-a.js +++ b/src/r3-d3-geometry-normal-a.js @@ -346,7 +346,7 @@ R3.D3.Geometry.Normal.prototype.updateFromInstance = function() { ]], new R3.Color( this.graphics, - new R3.API.Color( + new R3.API.Color(this, face.color.r, face.color.g, face.color.b @@ -355,7 +355,7 @@ R3.D3.Geometry.Normal.prototype.updateFromInstance = function() { face.vertexColors.map(function(vertexColor){ return new R3.Color( this.graphics, - new R3.API.Color( + new R3.API.Color(this, vertexColor.r, vertexColor.g, vertexColor.b @@ -427,12 +427,12 @@ R3.D3.Geometry.Normal.prototype.applyToInstance = function(property) { * Now setup each face and collect UV information during this process */ this.instance.faces = this.faces.map( - function (face) { + function(face) { if (face.uvs[0].length > 0) { standardUvs.push( face.uvs[0].map( - function (uv) { + function(uv) { return uv.instance; } ) @@ -459,7 +459,7 @@ R3.D3.Geometry.Normal.prototype.applyToInstance = function(property) { if (property === 'vertices') { this.instance.vertices = this.vertices.map( - function (vertex) { + function(vertex) { return vertex.position.instance; } ); @@ -488,7 +488,7 @@ R3.D3.Geometry.Normal.prototype.computeFaceNormals = function() { R3.D3.Geometry.Normal.prototype.invertWindingOrder = function() { this.faces.forEach( - function (face) { + function(face) { var tmpV1 = face.v1; face.v1 = face.v2; diff --git a/src/r3-d3-helper.js b/src/r3-d3-helper.js index 3ecef8d..b6fb7c9 100644 --- a/src/r3-d3-helper.js +++ b/src/r3-d3-helper.js @@ -5,7 +5,7 @@ * @param name * @param object * @param helperType - * @param parentEntity + * @param parent * @constructor */ R3.D3.Helper = function( @@ -14,7 +14,7 @@ R3.D3.Helper = function( name, object, helperType, - parentEntity + parent ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); @@ -66,10 +66,10 @@ R3.D3.Helper = function( } this.helperType = helperType; - if (R3.Utils.UndefinedOrNull(parentEntity)) { - parentEntity = null; + if (R3.Utils.UndefinedOrNull(parent)) { + parent = null; } - this.parentEntity = parentEntity; + this.parent = parent; this.createInstance(); /** diff --git a/src/r3-d3-light-a.js b/src/r3-d3-light-a.js index 4bb5dc2..7987883 100644 --- a/src/r3-d3-light-a.js +++ b/src/r3-d3-light-a.js @@ -24,7 +24,7 @@ R3.D3.Light = function( apiLight.color, apiLight.intensity, apiLight.parentScene, - apiLight.parentEntity + apiLight.parent ); this.color = new R3.Color( @@ -125,6 +125,6 @@ R3.D3.Light.prototype.toApiObject = function() { this.color.toApiObject(), this.intensity, R3.Utils.IdOrNull(this.parentScene), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-d3-material-a.js b/src/r3-d3-material-a.js index ed59129..fa96484 100644 --- a/src/r3-d3-material-a.js +++ b/src/r3-d3-material-a.js @@ -26,7 +26,7 @@ R3.D3.Material = function( apiMaterial.id, apiMaterial.name, apiMaterial.materialType, - apiMaterial.parentEntity, + apiMaterial.parent, apiMaterial.parentMeshes, apiMaterial.alphaTest, apiMaterial.blendDst, @@ -374,7 +374,7 @@ R3.D3.Material.prototype.toApiObject = function() { this.id, this.name, this.materialType, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), this.parentMeshes.map( function(mesh) { return R3.Utils.IdOrNull(mesh); @@ -771,7 +771,7 @@ R3.D3.Material.prototype.getTextures = function() { // } // // if (textureChanged) { -// this.publish( +// this.emit( // R3.Event.MATERIAL_TEXTURES_UPDATED, // { // material : this diff --git a/src/r3-d3-mesh-0.js b/src/r3-d3-mesh-0.js index e6eba13..69288ec 100644 --- a/src/r3-d3-mesh-0.js +++ b/src/r3-d3-mesh-0.js @@ -5,7 +5,7 @@ * @property geometry * @constructor */ -R3.D3.Mesh = function ( +R3.D3.Mesh = function( graphics, apiD3ObjectMesh ) { @@ -25,7 +25,7 @@ R3.D3.Mesh = function ( apiD3ObjectMesh.materials, apiD3ObjectMesh.parentMesh, apiD3ObjectMesh.parentScene, - apiD3ObjectMesh.excludeFromEnvironment, + apiD3ObjectMesh.excludeFromEnvironmentMapMap, apiD3ObjectMesh.skeleton, apiD3ObjectMesh.renderOrder, apiD3ObjectMesh.visible, @@ -249,7 +249,7 @@ R3.D3.Mesh.prototype.updateInstance = function(property) { return; } - if (property === 'excludeFromEnvironment') { + if (property === 'excludeFromEnvironmentMapMap') { R3.Event.Emit( R3.Event.EXCLUDE_FROM_ENVIRONMENT, { @@ -413,7 +413,7 @@ R3.D3.Mesh.prototype.toApiObject = function() { ), R3.Utils.IdOrNull(this.parentMesh), R3.Utils.IdOrNull(this.parentScene), - this.excludeFromEnvironment, + this.excludeFromEnvironmentMapMap, R3.Utils.IdOrNull(this.skeleton), this.renderOrder, this.visible, diff --git a/src/r3-d3-particle-engine.js b/src/r3-d3-particle-engine.js index 3df577a..17d42ca 100644 --- a/src/r3-d3-particle-engine.js +++ b/src/r3-d3-particle-engine.js @@ -30,7 +30,7 @@ R3.D3.ParticleEngine = function( apiParticleEngine.camera, apiParticleEngine.pulse, apiParticleEngine.fired, - apiParticleEngine.parentEntity + apiParticleEngine.parent ); this.position = new R3.Vector3( @@ -266,7 +266,7 @@ R3.D3.ParticleEngine.prototype.toApiObject = function() { R3.Utils.IdOrNull(this.camera), this.pulse, this.fired, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-d3-particle.js b/src/r3-d3-particle.js index c1e2e9a..13bd2d5 100644 --- a/src/r3-d3-particle.js +++ b/src/r3-d3-particle.js @@ -43,7 +43,7 @@ R3.D3.Particle = function( apiParticle.rotation, apiParticle.rotationFn, apiParticle.parentParticleEngine, - apiParticle.parentEntity + apiParticle.parent ); if (this.mesh instanceof R3.D3.API.Mesh) { @@ -348,7 +348,7 @@ R3.D3.Particle.prototype.toApiObject = function() { this.rotation.toApiObject(), this.rotationFn, R3.Utils.IdOrNull(this.parentParticleEngine), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-d3-pass-0.js b/src/r3-d3-pass-0.js index a9e90ce..e4b5ca8 100644 --- a/src/r3-d3-pass-0.js +++ b/src/r3-d3-pass-0.js @@ -5,7 +5,7 @@ * @property passType * @constructor */ -R3.D3.Pass = function ( +R3.D3.Pass = function( graphics, apiPass ) { @@ -24,7 +24,7 @@ R3.D3.Pass = function ( apiPass.id, apiPass.name, apiPass.passType, - apiPass.parentEntity, + apiPass.parent, apiPass.renderToScreen ); @@ -106,7 +106,7 @@ R3.D3.Pass.prototype.toApiObject = function() { this.id, this.name, this.passType, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), this.renderToScreen ); diff --git a/src/r3-d3-pass-bloom.js b/src/r3-d3-pass-bloom.js index 66766ca..8725c1c 100644 --- a/src/r3-d3-pass-bloom.js +++ b/src/r3-d3-pass-bloom.js @@ -4,7 +4,7 @@ * @param apiPassBloom R3.D3.API.Pass.Bloom * @constructor */ -R3.D3.Pass.Bloom = function ( +R3.D3.Pass.Bloom = function( graphics, apiPassBloom ) { diff --git a/src/r3-d3-pass-fxaa.js b/src/r3-d3-pass-fxaa.js index 7f7a4bc..5c22618 100644 --- a/src/r3-d3-pass-fxaa.js +++ b/src/r3-d3-pass-fxaa.js @@ -4,7 +4,7 @@ * @param apiPassFXAA R3.D3.API.Pass.FXAA * @constructor */ -R3.D3.Pass.FXAA = function ( +R3.D3.Pass.FXAA = function( graphics, apiPassFXAA ) { diff --git a/src/r3-d3-pass-render.js b/src/r3-d3-pass-render.js index 00b5ecf..be32d0c 100644 --- a/src/r3-d3-pass-render.js +++ b/src/r3-d3-pass-render.js @@ -4,7 +4,7 @@ * @param apiPassRender R3.D3.API.Pass.Render * @constructor */ -R3.D3.Pass.Render = function ( +R3.D3.Pass.Render = function( graphics, apiPassRender ) { diff --git a/src/r3-d3-pass-ssao.js b/src/r3-d3-pass-ssao.js index 92b5001..5bd213b 100644 --- a/src/r3-d3-pass-ssao.js +++ b/src/r3-d3-pass-ssao.js @@ -4,7 +4,7 @@ * @param apiPassSSAO R3.D3.API.Pass.SSAO * @constructor */ -R3.D3.Pass.SSAO = function ( +R3.D3.Pass.SSAO = function( graphics, apiPassSSAO ) { diff --git a/src/r3-d3-physics-world.js b/src/r3-d3-physics-world.js index e278f0a..c1105e8 100644 --- a/src/r3-d3-physics-world.js +++ b/src/r3-d3-physics-world.js @@ -27,7 +27,7 @@ R3.D3.PhysicsWorld = function( apiWorld.contactMaterials, apiWorld.allowSleep, apiWorld.defaultContactMaterial, - apiWorld.parentEntity + apiWorld.parent ); if (this.gravity instanceof R3.API.Vector3) { @@ -127,7 +127,7 @@ R3.D3.PhysicsWorld.prototype.createInstance = function() { this.instance.allowSleep = this.allowSleep; this.contactMaterials.map( - function (contactMaterial) { + function(contactMaterial) { if (R3.Utils.UndefinedOrNull(contactMaterial)) { throw new Error('no contact material'); @@ -143,7 +143,7 @@ R3.D3.PhysicsWorld.prototype.createInstance = function() { ); this.rigidBodies.map( - function (rigidBody) { + function(rigidBody) { if (R3.Utils.UndefinedOrNull(rigidBody)) { throw new Error('no rigidbody'); @@ -282,7 +282,7 @@ R3.D3.PhysicsWorld.prototype.toApiObject = function() { }), this.allowSleep, R3.Utils.IdOrNull(this.defaultContactMaterial), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); return apiWorld; diff --git a/src/r3-d3-raycast-vehicle.js b/src/r3-d3-raycast-vehicle.js index 0d78718..433291d 100644 --- a/src/r3-d3-raycast-vehicle.js +++ b/src/r3-d3-raycast-vehicle.js @@ -4,7 +4,7 @@ * @param apiRaycastVehicle R3.D3.API.RaycastVehicle * @constructor */ -R3.D3.RaycastVehicle = function ( +R3.D3.RaycastVehicle = function( physics, apiRaycastVehicle ) { @@ -24,7 +24,7 @@ R3.D3.RaycastVehicle = function ( apiRaycastVehicle.wheels, apiRaycastVehicle.raycastWheels, apiRaycastVehicle.parentPhysicsWorld, - apiRaycastVehicle.parentEntity + apiRaycastVehicle.parent ); if (this.chassis instanceof R3.D3.API.RaycastVehicle) { @@ -149,7 +149,7 @@ R3.D3.RaycastVehicle.prototype.toApiObject = function() { return R3.Utils.IdOrNull(raycastWheel); }), R3.Utils.IdOrNull(this.parentPhysicsWorld), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); return apiRaycastVehicle; diff --git a/src/r3-d3-raycast-wheel.js b/src/r3-d3-raycast-wheel.js index 790e30b..a64edaa 100644 --- a/src/r3-d3-raycast-wheel.js +++ b/src/r3-d3-raycast-wheel.js @@ -4,7 +4,7 @@ * @param apiRaycastWheel R3.D3.API.RaycastWheel * @constructor */ -R3.D3.RaycastWheel = function ( +R3.D3.RaycastWheel = function( physics, apiRaycastWheel ) { @@ -35,7 +35,7 @@ R3.D3.RaycastWheel = function ( apiRaycastWheel.customSlidingRotationalSpeed, apiRaycastWheel.useCustomSlidingRotationalSpeed, apiRaycastWheel.parentMesh, - apiRaycastWheel.parentEntity + apiRaycastWheel.parent ); this.directionLocal = new R3.Vector3( @@ -134,7 +134,7 @@ R3.D3.RaycastWheel.prototype.toApiObject = function() { this.customSlidingRotationalSpeed, this.useCustomSlidingRotationalSpeed, R3.Utils.IdOrNull(this.parentMesh), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); return apiRaycastWheel; diff --git a/src/r3-d3-raycaster.js b/src/r3-d3-raycaster.js index 21e45f8..efb6170 100644 --- a/src/r3-d3-raycaster.js +++ b/src/r3-d3-raycaster.js @@ -20,7 +20,7 @@ R3.D3.Raycaster = function( this, apiRaycaster.id, apiRaycaster.name, - apiRaycaster.parentEntity, + apiRaycaster.parent, apiRaycaster.position, apiRaycaster.direction ); @@ -82,7 +82,7 @@ R3.D3.Raycaster.prototype.toApiObject = function() { return new R3.D3.API.Raycaster( this.id, this.name, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), this.position.toApiObject(), this.direction.toApiObject() ) @@ -167,7 +167,7 @@ R3.D3.Raycaster.prototype.setFromCamera = function( R3.D3.Raycaster.prototype.getIntersectedObjects = function(meshes) { return meshes.reduce( - function (result, mesh) { + function(result, mesh) { var intersects = this.instance.intersectObject(mesh.instance); diff --git a/src/r3-d3-render-target-a.js b/src/r3-d3-render-target-a.js index c085061..256c1f9 100644 --- a/src/r3-d3-render-target-a.js +++ b/src/r3-d3-render-target-a.js @@ -4,7 +4,7 @@ * @param apiRenderTarget R3.D3.API.RenderTarget * @constructor */ -R3.D3.RenderTarget = function ( +R3.D3.RenderTarget = function( graphics, apiRenderTarget ) { @@ -23,7 +23,7 @@ R3.D3.RenderTarget = function ( apiRenderTarget.id, apiRenderTarget.name, apiRenderTarget.renderTargetType, - apiRenderTarget.parentEntity, + apiRenderTarget.parent, apiRenderTarget.autoUpdateSize, apiRenderTarget.width, apiRenderTarget.height, @@ -96,7 +96,7 @@ R3.D3.RenderTarget.prototype.applyToInstance = function() { this.texture.applyToInstance(); } - this.publish( + this.emit( R3.Event.TEXTURE_INSTANCE_UPDATED, { texture : this.texture @@ -115,7 +115,7 @@ R3.D3.RenderTarget.prototype.applyToInstance = function() { this.depthTexture.applyToInstance(); } - this.publish( + this.emit( R3.Event.TEXTURE_INSTANCE_UPDATED, { texture : this.depthTexture @@ -205,8 +205,8 @@ R3.D3.RenderTarget.prototype.updateInstance = function(property) { return; } - if (property === 'parentEntity') { - console.warn('todo : update parentEntity'); + if (property === 'parent') { + console.warn('todo : update parent'); return; } @@ -274,7 +274,7 @@ R3.D3.RenderTarget.prototype.toApiObject = function() { this.id, this.name, this.renderTargetType, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), this.autoUpdateSize, this.width, this.height, diff --git a/src/r3-d3-render-target-cube.js b/src/r3-d3-render-target-cube.js index 0254f79..1dbc312 100644 --- a/src/r3-d3-render-target-cube.js +++ b/src/r3-d3-render-target-cube.js @@ -4,7 +4,7 @@ * @param apiRenderTargetCube R3.D3.API.RenderTarget.Cube * @constructor */ -R3.D3.RenderTarget.Cube = function ( +R3.D3.RenderTarget.Cube = function( graphics, apiRenderTargetCube ) { diff --git a/src/r3-d3-rigid-body.js b/src/r3-d3-rigid-body.js index 8127368..ed67bc5 100644 --- a/src/r3-d3-rigid-body.js +++ b/src/r3-d3-rigid-body.js @@ -4,7 +4,7 @@ * @param apiRigidBody R3.D3.API.RigidBody * @constructor */ -R3.D3.RigidBody = function ( +R3.D3.RigidBody = function( physics, apiRigidBody ) { @@ -38,7 +38,7 @@ R3.D3.RigidBody = function ( apiRigidBody.kinematic, apiRigidBody.parentMesh, apiRigidBody.parentPhysicsWorld, - apiRigidBody.parentEntity + apiRigidBody.parent ); this.position = new R3.Vector3( @@ -249,7 +249,7 @@ R3.D3.RigidBody.prototype.toApiObject = function() { this.kinematic, R3.Utils.IdOrNull(this.parentMesh), R3.Utils.IdOrNull(this.parentPhysicsWorld), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); return apiRigidBody; diff --git a/src/r3-d3-scene.js b/src/r3-d3-scene.js index e97a611..5a1ce71 100644 --- a/src/r3-d3-scene.js +++ b/src/r3-d3-scene.js @@ -1,14 +1,12 @@ /** - * Scene Superset - The apiScene properties get moved into the Scene object itself, and then the instance is - * created + * R3.D3.Scene * @param graphics * @param apiScene R3.D3.API.Scene * @constructor */ -R3.D3.Scene = function ( +R3.D3.Scene = function( graphics, - apiScene, - instance + apiScene ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); @@ -31,8 +29,7 @@ R3.D3.Scene = function ( apiScene.showAxis, apiScene.gridSize, apiScene.gridColor, - apiScene.camera, - apiScene.parentEntity + apiScene.parent ); this.textures = this.textures.map( @@ -85,7 +82,7 @@ R3.D3.Scene = function ( this.graphics, this.fog ) - }; + } this.gridColor = new R3.Color( this.graphics, @@ -117,8 +114,7 @@ R3.D3.Scene = function ( 'textures' : [R3.D3.Texture], 'materials' : [R3.D3.Material], 'images' : [R3.Image], - 'fog' : R3.D3.Fog, - 'camera' : R3.D3.Camera + 'fog' : R3.D3.Fog } ); }; @@ -218,7 +214,7 @@ R3.D3.Scene.prototype.updateInstance = function(property) { * Add missing meshes */ this.meshes.map( - function (mesh) { + function(mesh) { if (this.instance.children.indexOf(mesh.instance === -1)) { this.instance.add(mesh.instance); } @@ -232,7 +228,7 @@ R3.D3.Scene.prototype.updateInstance = function(property) { * Add missing lights */ this.lights.map( - function (light) { + function(light) { if (this.instance.children.indexOf(light.instance) === -1) { this.instance.add(light.instance); } @@ -248,16 +244,16 @@ R3.D3.Scene.prototype.updateInstance = function(property) { * Remove extra meshes and lights */ this.instance.children.map( - function (instanceObject) { + function(instanceObject) { var instanceMeshes = this.meshes.map( - function (mesh) { + function(mesh) { return mesh.instance; } ); var instanceLights = this.lights.map( - function (light) { + function(light) { return light.instance; } ); @@ -313,7 +309,7 @@ R3.D3.Scene.prototype.toApiObject = function() { if (this.storeClones) { this.clones.map( - function (clone) { + function(clone) { R3.Utils.PushUnique( apiMeshes, R3.Utils.IdOrNull(clone) @@ -360,8 +356,7 @@ R3.D3.Scene.prototype.toApiObject = function() { this.showAxis, this.gridSize, this.gridColor.toApiObject(), - R3.Utils.IdOrNull(this.camera), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; @@ -396,8 +391,8 @@ R3.D3.Scene.prototype.addObject = function(object) { // console.warn('either scene or mesh instance not ready'); } - // if (this.parentEntity) { - // this.parentEntity.addComponent(object); + // if (this.parent) { + // this.parent.addComponent(object); // } }; @@ -474,8 +469,8 @@ R3.D3.Scene.prototype.removeObject = function(object) { object.parentScene = null; } // - // if (this.parentEntity) { - // this.parentEntity.removeComponent(object); + // if (this.parent) { + // this.parent.removeComponent(object); // } // this.buildIdToObject(); }; diff --git a/src/r3-d3-shader-a.js b/src/r3-d3-shader-a.js index 3f594e5..f815f40 100644 --- a/src/r3-d3-shader-a.js +++ b/src/r3-d3-shader-a.js @@ -21,7 +21,7 @@ R3.D3.Shader = function( apiShader.id, apiShader.name, apiShader.shaderType, - apiShader.parentEntity, + apiShader.parent, apiShader.parentMaterialShader, apiShader.code ); @@ -90,7 +90,7 @@ R3.D3.Shader.prototype.toApiObject = function() { this.id, this.name, this.shaderType, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), R3.Utils.IdOrNull(this.parentMaterialShader), this.code ); diff --git a/src/r3-d3-shadow-a.js b/src/r3-d3-shadow-a.js index 44522a9..227bc22 100644 --- a/src/r3-d3-shadow-a.js +++ b/src/r3-d3-shadow-a.js @@ -27,7 +27,7 @@ R3.D3.Shadow = function( apiShadow.bias, apiShadow.mapSize, apiShadow.radius, - apiShadow.parentEntity + apiShadow.parent ); if (this.camera instanceof R3.D3.API.Camera.Perspective) { @@ -122,7 +122,7 @@ R3.D3.Shadow.prototype.toApiObject = function() { this.bias, this.mapSize.toApiObject(), this.radius, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-d3-shape-0.js b/src/r3-d3-shape-0.js index 061f96c..a866d45 100644 --- a/src/r3-d3-shape-0.js +++ b/src/r3-d3-shape-0.js @@ -4,7 +4,7 @@ * @param apiShape R3.D3.API.Shape * @constructor */ -R3.D3.Shape = function ( +R3.D3.Shape = function( physics, apiShape ) { @@ -26,7 +26,7 @@ R3.D3.Shape = function ( apiShape.collisionResponse, apiShape.frictionMaterial, apiShape.parentMesh, - apiShape.parentEntity + apiShape.parent ); var linkedObjects = { @@ -73,7 +73,7 @@ R3.D3.Shape.prototype.toApiObject = function() { this.collisionResponse, R3.Utils.IdOrNull(this.frictionMaterial), R3.Utils.IdOrNull(this.parentMesh), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); return apiShape; diff --git a/src/r3-d3-shape-box.js b/src/r3-d3-shape-box.js index 64c6ab9..d324bf2 100644 --- a/src/r3-d3-shape-box.js +++ b/src/r3-d3-shape-box.js @@ -5,7 +5,7 @@ * @param halfExtents * @constructor */ -R3.D3.Shape.Box = function ( +R3.D3.Shape.Box = function( physics, apiShape, halfExtents diff --git a/src/r3-d3-shape-convex-hull-0.js b/src/r3-d3-shape-convex-hull-0.js index 5e246ec..a6fdcfd 100644 --- a/src/r3-d3-shape-convex-hull-0.js +++ b/src/r3-d3-shape-convex-hull-0.js @@ -8,7 +8,7 @@ * @param vertices * @constructor */ -R3.D3.Shape.ConvexHull = function ( +R3.D3.Shape.ConvexHull = function( physics, apiShape, vertices, diff --git a/src/r3-d3-shape-convex-hull-cylinder.js b/src/r3-d3-shape-convex-hull-cylinder.js index 56b99ca..179b6ba 100644 --- a/src/r3-d3-shape-convex-hull-cylinder.js +++ b/src/r3-d3-shape-convex-hull-cylinder.js @@ -8,7 +8,7 @@ * @param numSegments * @constructor */ -R3.D3.Shape.ConvexHull.Cylinder = function ( +R3.D3.Shape.ConvexHull.Cylinder = function( physics, apiShape, radiusTop, diff --git a/src/r3-d3-shape-height-map.js b/src/r3-d3-shape-height-map.js index 4a79ff9..3361b42 100644 --- a/src/r3-d3-shape-height-map.js +++ b/src/r3-d3-shape-height-map.js @@ -8,7 +8,7 @@ * @param elementSize * @constructor */ -R3.D3.Shape.HeightMap = function ( +R3.D3.Shape.HeightMap = function( physics, apiShape, heightData, diff --git a/src/r3-d3-shape-plane.js b/src/r3-d3-shape-plane.js index c7d1151..f40d8f5 100644 --- a/src/r3-d3-shape-plane.js +++ b/src/r3-d3-shape-plane.js @@ -4,7 +4,7 @@ * @param apiShape R3.D3.API.Shape * @constructor */ -R3.D3.Shape.Plane = function ( +R3.D3.Shape.Plane = function( physics, apiShape ) { diff --git a/src/r3-d3-shape-sphere.js b/src/r3-d3-shape-sphere.js index 3a9f3b6..9045f01 100644 --- a/src/r3-d3-shape-sphere.js +++ b/src/r3-d3-shape-sphere.js @@ -5,7 +5,7 @@ * @param radius * @constructor */ -R3.D3.Shape.Sphere = function ( +R3.D3.Shape.Sphere = function( physics, apiShape, radius diff --git a/src/r3-d3-shape-tri-mesh.js b/src/r3-d3-shape-tri-mesh.js index 4777627..2e31911 100644 --- a/src/r3-d3-shape-tri-mesh.js +++ b/src/r3-d3-shape-tri-mesh.js @@ -6,7 +6,7 @@ * @param indices * @constructor */ -R3.D3.Shape.TriMesh = function ( +R3.D3.Shape.TriMesh = function( physics, apiShape, vertices, diff --git a/src/r3-d3-skeleton.js b/src/r3-d3-skeleton.js index 223f186..f2747e6 100644 --- a/src/r3-d3-skeleton.js +++ b/src/r3-d3-skeleton.js @@ -26,7 +26,7 @@ R3.D3.Skeleton = function Skeleton( apiSkeleton.boneTextureHeight, apiSkeleton.boneMatrices, apiSkeleton.boneTexture, - apiSkeleton.parentEntity + apiSkeleton.parent ); @@ -95,7 +95,7 @@ R3.D3.Skeleton.prototype.constructor = R3.D3.Skeleton; R3.D3.Skeleton.prototype.createInstance = function(update) { var boneInstances = this.bones.map ( - function (bone) { + function(bone) { if (R3.Utils.UndefinedOrNull(bone)) { throw new Error('no bone'); @@ -111,7 +111,7 @@ R3.D3.Skeleton.prototype.createInstance = function(update) { var parentBoneInstance = this.bones.reduce( - function (result, bone) { + function(result, bone) { if (result) { return result; @@ -139,7 +139,7 @@ R3.D3.Skeleton.prototype.createInstance = function(update) { this.boneIdToBone = {}; this.bones.map( - function (bone) { + function(bone) { this.boneIdToBone[bone.id] = bone; }.bind(this) ); @@ -148,10 +148,10 @@ R3.D3.Skeleton.prototype.createInstance = function(update) { * TODO: check if this code does what its supposed to */ this.bones.map( - function (__parentBoneInstance) { + function(__parentBoneInstance) { return function(bone) { bone.childBoneIds.map( - function (childBoneId) { + function(childBoneId) { __parentBoneInstance.add(this.boneIdToBone[childBoneId].instance); }.bind(this) ); @@ -183,12 +183,12 @@ R3.D3.Skeleton.prototype.toApiObject = function() { this.id, this.name, this.bones.map( - function (bone) { + function(bone) { return bone.toApiObject(); } ), this.boneInverses.map( - function (boneInverse) { + function(boneInverse) { return boneInverse.toApiObject(); } ), @@ -196,12 +196,12 @@ R3.D3.Skeleton.prototype.toApiObject = function() { this.boneTextureWidth, this.boneTextureHeight, this.boneMatrices.map( - function (boneMatrix) { + function(boneMatrix) { return boneMatrix.toApiObject(); } ), this.boneTexture, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); return apiSkeleton; diff --git a/src/r3-d3-solver.js b/src/r3-d3-solver.js index 61aba53..8067e27 100644 --- a/src/r3-d3-solver.js +++ b/src/r3-d3-solver.js @@ -4,7 +4,7 @@ * @param apiSolver R3.D3.API.Solver * @constructor */ -R3.D3.Solver = function ( +R3.D3.Solver = function( physics, apiSolver ) { @@ -23,7 +23,7 @@ R3.D3.Solver = function ( apiSolver.solverType, apiSolver.iterations, apiSolver.tolerance, - apiSolver.parentEntity + apiSolver.parent ); R3.Component.call(this); @@ -87,7 +87,7 @@ R3.D3.Solver.prototype.toApiObject = function() { this.solverType, this.iterations, this.tolerance, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); return apiSolver; diff --git a/src/r3-d3-spline.js b/src/r3-d3-spline.js index 859ee8a..cabba0e 100644 --- a/src/r3-d3-spline.js +++ b/src/r3-d3-spline.js @@ -4,7 +4,7 @@ * @param apiSpline R3.D3.API.Spline * @constructor */ -R3.D3.Spline = function ( +R3.D3.Spline = function( graphics, apiSpline ) { @@ -20,11 +20,11 @@ R3.D3.Spline = function ( apiSpline.id, apiSpline.name, apiSpline.vertices, - apiSpline.parentEntity + apiSpline.parent ); this.vertices = this.vertices.map( - function (vertex) { + function(vertex) { return new R3.Vector3( graphics, vertex, @@ -45,7 +45,7 @@ R3.D3.Spline.prototype.constructor = R3.D3.Spline; R3.D3.Spline.prototype.createInstance = function() { var vertices = this.vertices.map( - function (vertex) { + function(vertex) { if (R3.Utils.UndefinedOrNull(vertex)) { throw new Error('no vertex') @@ -70,7 +70,7 @@ R3.D3.Spline.prototype.createInstance = function() { R3.D3.Spline.prototype.updateInstance = function(property) { var vertices = this.vertices.map( - function (vertex) { + function(vertex) { if (R3.Utils.UndefinedOrNull(vertex)) { throw new Error('no vertex') @@ -99,11 +99,11 @@ R3.D3.Spline.prototype.toApiObject = function() { this.id, this.name, this.vertices.map( - function (vertex) { + function(vertex) { return vertex.toApiObject() } ), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-d3-text.js b/src/r3-d3-text.js index b4df960..284f9d5 100644 --- a/src/r3-d3-text.js +++ b/src/r3-d3-text.js @@ -25,7 +25,7 @@ R3.D3.Text = function( apiText.fillStyle, apiText.value, apiText.parentCanvas, - apiText.parentEntity + apiText.parent ); this.offset = new R3.Vector2( @@ -111,6 +111,6 @@ R3.D3.Text.prototype.toApiObject = function() { this.fillStyle, this.value, R3.Utils.IdOrNull(this.parentCanvas), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; \ No newline at end of file diff --git a/src/r3-d3-texture-a.js b/src/r3-d3-texture-a.js index 219455b..e79e783 100644 --- a/src/r3-d3-texture-a.js +++ b/src/r3-d3-texture-a.js @@ -31,7 +31,7 @@ R3.D3.Texture = function( apiTexture.id, apiTexture.name, apiTexture.textureType, - apiTexture.parentEntity, + apiTexture.parent, apiTexture.parentMaterials, apiTexture.mipmaps, apiTexture.mapping, @@ -319,7 +319,7 @@ R3.D3.Texture.prototype.toApiObject = function() { this.id, this.name, this.textureType, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), this.parentMaterials.map( function(parentMaterial) { return R3.Utils.IdOrNull(parentMaterial); diff --git a/src/r3-d3-texture-cube.js b/src/r3-d3-texture-cube.js index e1c2da6..3956edc 100644 --- a/src/r3-d3-texture-cube.js +++ b/src/r3-d3-texture-cube.js @@ -106,7 +106,7 @@ R3.D3.Texture.Cube.prototype.updateInstance = function(property) { this.image = imageInstances; } - this.publish( + this.emit( R3.Event.TEXTURE_INSTANCE_UPDATED, { texture : this diff --git a/src/r3-d3-texture-image.js b/src/r3-d3-texture-image.js index b22543e..b950064 100644 --- a/src/r3-d3-texture-image.js +++ b/src/r3-d3-texture-image.js @@ -93,7 +93,7 @@ R3.D3.Texture.Image.prototype.updateInstance = function(property) { this.instance.needsUpdate = true; } - this.publish( + this.emit( R3.Event.TEXTURE_INSTANCE_UPDATED, { texture : this diff --git a/src/r3-d3-viewport.js b/src/r3-d3-viewport.js index 35e7980..b90dcac 100644 --- a/src/r3-d3-viewport.js +++ b/src/r3-d3-viewport.js @@ -4,7 +4,7 @@ * @param apiViewport R3.D3.API.Viewport * @constructor */ -R3.D3.Viewport = function ( +R3.D3.Viewport = function( graphics, apiViewport ) { @@ -18,13 +18,15 @@ R3.D3.Viewport = function ( R3.D3.API.Viewport.call( this, - apiViewport.id, - apiViewport.name, - apiViewport.width, - apiViewport.height, - apiViewport.x, - apiViewport.y, - apiViewport.parentEntity + apiViewport.id, + apiViewport.name, + apiViewport.viewportType, + apiViewport.parent, + apiViewport.scenes, + apiViewport.width, + apiViewport.height, + apiViewport.x, + apiViewport.y ); R3.Component.call(this); @@ -74,15 +76,21 @@ R3.D3.Viewport.prototype.updateInstance = function(property) { */ R3.D3.Viewport.prototype.toApiObject = function() { - var apiViewport = new R3.D3.API.Viewport( + return new R3.D3.API.Viewport( this.id, this.name, + this.viewportType, + R3.Utils.IdOrNull(this.parent), + this.scenes.reduce( + function(result, scene){ + result.push(R3.Utils.IdOrNull(scene)); + }, + [] + ), this.width, this.height, this.x, - this.y, - R3.Utils.IdOrNull(this.parentEntity) + this.y ); - return apiViewport; }; diff --git a/src/r3-dom-element.js b/src/r3-dom-element.js index cf6c68a..8706d17 100644 --- a/src/r3-dom-element.js +++ b/src/r3-dom-element.js @@ -3,7 +3,7 @@ * @param apiDomElement R3.API.DomElement * @constructor */ -R3.DomElement = function (apiDomElement) { +R3.DomElement = function(apiDomElement) { if (R3.Utils.UndefinedOrNull(apiDomElement)) { apiDomElement = {}; @@ -14,7 +14,7 @@ R3.DomElement = function (apiDomElement) { apiDomElement.id, apiDomElement.name, apiDomElement.domElementId, - apiDomElement.parentEntity + apiDomElement.parent ); this.fullscreen = false; @@ -54,7 +54,7 @@ R3.DomElement.prototype.toApiObject = function() { this.id, this.name, this.domElementId, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-draw-range.js b/src/r3-draw-range.js index 1075c17..5ced0fe 100644 --- a/src/r3-draw-range.js +++ b/src/r3-draw-range.js @@ -5,7 +5,7 @@ * @param parentGeometry * @constructor */ -R3.DrawRange = function ( +R3.DrawRange = function( implementation, apiDrawRange, parentGeometry @@ -34,7 +34,7 @@ R3.DrawRange = function ( this, apiDrawRange.id, apiDrawRange.name, - apiDrawRange.parentEntity, + apiDrawRange.parent, apiDrawRange.start, apiDrawRange.count ); @@ -82,7 +82,7 @@ R3.DrawRange.prototype.toApiObject = function() { return new R3.API.DrawRange( this.id, this.name, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), this.start, this.count ); diff --git a/src/r3-entity-manager.js b/src/r3-entity-manager.js index d98ae1c..a6ad6cd 100644 --- a/src/r3-entity-manager.js +++ b/src/r3-entity-manager.js @@ -14,7 +14,7 @@ R3.EntityManager = function(apiEntityManager) { apiEntityManager.name, apiEntityManager.entities, apiEntityManager.defaultEntity, - apiEntityManager.parentEntity + apiEntityManager.parent ); /** @@ -387,7 +387,7 @@ R3.EntityManager.prototype.queryComponentsByConstructor = function(constructors) R3.EntityManager.prototype.toApiObject = function() { var apiEntities = this.entities.map( - function (entity) { + function(entity) { return R3.Utils.IdOrNull(entity); } ); @@ -397,7 +397,7 @@ R3.EntityManager.prototype.toApiObject = function() { this.name, apiEntities, this.defaultEntity, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); return apiEntityManager; diff --git a/src/r3-entity.js b/src/r3-entity.js index 4a37aad..9f25715 100644 --- a/src/r3-entity.js +++ b/src/r3-entity.js @@ -3,7 +3,7 @@ * @param apiEntity R3.D3.API.Entity * @constructor */ -R3.Entity = function ( +R3.Entity = function( apiEntity ) { if (R3.Utils.UndefinedOrNull(apiEntity)) { @@ -15,7 +15,7 @@ R3.Entity = function ( apiEntity.id, apiEntity.name, apiEntity.components, - apiEntity.parentEntity + apiEntity.parent ); this.instanceCreatedEventSubscription = this.subscribe( @@ -33,7 +33,7 @@ R3.Entity = function ( var components = []; this.components.map( - function (component) { + function(component) { if (component instanceof R3.API.Component) { components.push(R3.Component.ConstructFromObject(component)); } else { @@ -68,7 +68,7 @@ R3.Entity.prototype.instanceCreatedEvent = function(data) { } - if (data.component.parentEntity === this.id) { + if (data.component.parent === this.id) { this.addComponent(data.component); } }; @@ -82,7 +82,7 @@ R3.Entity.prototype.removeComponentEvent = function(data) { return; } - if (data.component.parentEntity === this) { + if (data.component.parent === this) { this.removeComponent(data.component); } }; @@ -94,12 +94,12 @@ R3.Entity.prototype.createInstance = function() { this.components.map( function(component) { - component.parentEntity = this; + component.parent = this; Object.keys(component.idToObject).map( function(componentId) { R3.Utils.PushUnique(this.components, component.idToObject[componentId]); - component.idToObject[componentId].parentEntity = this; + component.idToObject[componentId].parent = this; }.bind(this) ); @@ -119,7 +119,7 @@ R3.Entity.prototype.createInstance = function() { */ R3.Entity.prototype.addComponent = function(component) { - component.parentEntity = this; + component.parent = this; /** * Could be that this entity is not loaded and needs to be linked still @@ -152,7 +152,7 @@ R3.Entity.prototype.addComponent = function(component) { R3.Entity.prototype.removeComponent = function(component) { - component.parentEntity = null; + component.parent = null; var index = this.components.indexOf(component); @@ -283,7 +283,7 @@ R3.Entity.prototype.toApiObject = function() { this.id, this.name, apiComponents, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-graphics-runtime-a.js b/src/r3-graphics-runtime-a.js index 27dfe6e..66ef6de 100644 --- a/src/r3-graphics-runtime-a.js +++ b/src/r3-graphics-runtime-a.js @@ -1,71 +1,28 @@ /** - * Graphics + * R3.GraphicsRuntime * @constructor - * @param apiGraphics */ -R3.GraphicsRuntime = function( - apiGraphics -) { +R3.GraphicsRuntime = function() {}; - if (R3.Utils.UndefinedOrNull(apiGraphics)) { - apiGraphics = { - graphicsType : R3.API.GraphicsRuntime.GRAPHICS_TYPE_NONE - }; - } - - R3.API.GraphicsRuntime.call( - this, - apiGraphics.id, - apiGraphics.name, - apiGraphics.graphicsType, - apiGraphics.parentEntity - ); - - R3.Component.call(this); +R3.GraphicsRuntime.prototype.Vector2 = function(x,y) { + console.warn('override Vector2 in child class'); }; -R3.GraphicsRuntime.prototype = Object.create(R3.Component.prototype); -R3.GraphicsRuntime.prototype.constructor = R3.GraphicsRuntime; - -R3.GraphicsRuntime.prototype.createInstance = function() { - console.log(this.graphicsType + ' graphics runtime created'); - R3.Component.prototype.createInstance.call(this); +R3.GraphicsRuntime.prototype.Vector3 = function(x,y,z) { + console.warn('override Vector3 in child class'); }; -R3.GraphicsRuntime.prototype.updateInstance = function(property) { - - if (property === 'graphicsType') { - var componentType = R3.API.Renderer.GetComponentType(this.graphicsType); - - this.replace(componentType); - - return; - } - - R3.Component.prototype.updateInstance.call(this, property); +R3.GraphicsRuntime.prototype.Vector4 = function(x,y,z,w) { + console.warn('override Vector4 in child class'); }; -R3.GraphicsRuntime.prototype.toApiObject = function(property) { - - return new R3.API.GraphicsRuntime( - this.id, - this.name, - this.graphicsType, - R3.Utils.IdOrNull(this.parentEntity) - ); - +R3.GraphicsRuntime.prototype.Box3 = function(x,y,z) { + console.warn('override Box3 in child class'); }; + /** - * Logs a warning and throws an error if not cannon + * R3.GraphicsRuntime Types + * @type {number} */ -R3.GraphicsRuntime.prototype.isNotThreeThrow = function() { - if (this.instance !== THREE) { - console.error('Only THREE supported'); - throw new Error('Only THREE supported'); - } -}; - -R3.GraphicsRuntime.prototype.isThree = function() { - return (this.instance === THREE); -}; \ No newline at end of file +R3.GraphicsRuntime.TYPE_THREE = 0x1; \ No newline at end of file diff --git a/src/r3-graphics-runtime-three.js b/src/r3-graphics-runtime-three.js index 1c49685..dfee0d5 100644 --- a/src/r3-graphics-runtime-three.js +++ b/src/r3-graphics-runtime-three.js @@ -1,28 +1,14 @@ /** * R3.GraphicsRuntime.Three - * @param apiGraphicsRuntimeThree * @constructor */ -R3.GraphicsRuntime.Three = function ( - apiGraphicsRuntimeThree -) { - - if (R3.Utils.UndefinedOrNull(apiGraphicsRuntimeThree)) { - apiGraphicsRuntimeThree = { - graphicsType : R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS - }; - } - - R3.API.GraphicsRuntime.Three.call( - this, - apiGraphicsRuntimeThree - ); +R3.GraphicsRuntime.Three = function() { R3.GraphicsRuntime.call( - this, this ); + this.createInstance(); }; R3.GraphicsRuntime.Three.prototype = Object.create(R3.GraphicsRuntime.prototype); @@ -33,31 +19,28 @@ R3.GraphicsRuntime.Three.prototype.constructor = R3.GraphicsRuntime.Three; * @returns {*} */ R3.GraphicsRuntime.Three.prototype.createInstance = function() { - this.instance = THREE; +}; - R3.GraphicsRuntime.prototype.createInstance.call(this); +R3.GraphicsRuntime.Three.prototype.Vector2 = function(x,y) { + return new this.instance.Vector2(x,y,z); +}; + +R3.GraphicsRuntime.Three.prototype.Vector3 = function(x,y,z) { + return new this.instance.Vector3(x,y,z); +}; + +R3.GraphicsRuntime.Three.prototype.Vector4 = function(x,y,z,w) { + return new this.instance.Quaternion(x,y,z,w); }; /** - * Update GraphicsRuntime.Three Instance + * R3.GraphicsRuntime.Three.prototype.Box3 + * @param min {R3.Vector3|R3.API.Vector3} + * @param max {R3.Vector3|R3.API.Vector3} + * @returns {*|R3.Box3|R3.API.Box3|R3.API.Box3|R3.Box3|R3.API.Box3} + * @constructor */ -R3.GraphicsRuntime.Three.prototype.updateInstance = function(property) { - - R3.GraphicsRuntime.prototype.updateInstance.call(this, property); -}; - -/** - * - * @returns {R3.API.GraphicsRuntime.Three} - */ -R3.GraphicsRuntime.Three.prototype.toApiObject = function() { - - var apiGraphicsRuntime = R3.GraphicsRuntime.prototype.toApiObject.call(this); - - var apiGraphicsRuntimeThree = new R3.API.GraphicsRuntime.Three( - apiGraphicsRuntime - ); - - return apiGraphicsRuntimeThree; +R3.GraphicsRuntime.Three.prototype.Box3 = function(min,max) { + return new this.instance.Box3(min.instance, max.instance); }; diff --git a/src/r3-group.js b/src/r3-group.js index 90421ff..5c3a9de 100644 --- a/src/r3-group.js +++ b/src/r3-group.js @@ -5,7 +5,7 @@ * @param parentGeometry * @constructor */ -R3.Group = function ( +R3.Group = function( implementation, apiGroup, parentGeometry @@ -27,7 +27,7 @@ R3.Group = function ( this, apiGroup.id, apiGroup.name, - apiGroup.parentEntity, + apiGroup.parent, apiGroup.start, apiGroup.count, apiGroup.materialIndex @@ -89,7 +89,7 @@ R3.Group.prototype.toApiObject = function() { return new R3.API.Group( this.id, this.name, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), this.start, this.count, this.materialIndex diff --git a/src/r3-gui.js b/src/r3-gui.js index 49d87ae..0572480 100644 --- a/src/r3-gui.js +++ b/src/r3-gui.js @@ -20,7 +20,7 @@ R3.GUI = function( apiGUI.id, apiGUI.name, apiGUI.domElement, - apiGUI.parentEntity + apiGUI.parent ); R3.Component.call( @@ -59,7 +59,7 @@ R3.GUI.prototype.toApiObject = function() { this.id, this.name, R3.Utils.IdOrNull(this.domElement), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-image.js b/src/r3-image.js index 03302b4..8369a66 100644 --- a/src/r3-image.js +++ b/src/r3-image.js @@ -15,7 +15,7 @@ R3.Image = function( this, apiImage.id, apiImage.name, - apiImage.parentEntity, + apiImage.parent, apiImage.parentTexture, apiImage.fileName, apiImage.extension, @@ -122,7 +122,7 @@ R3.Image.prototype.toApiObject = function() { var apiImage = new R3.API.Image( this.id, this.name, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), R3.Utils.IdOrNull(this.parentTexture), this.fileName, this.extension, diff --git a/src/r3-matrix-4.js b/src/r3-matrix-4.js index 9ec6eec..54b33f1 100644 --- a/src/r3-matrix-4.js +++ b/src/r3-matrix-4.js @@ -144,7 +144,7 @@ R3.Matrix4.prototype.updateInstance = function() { * R3.Matrix4 to R3.API.Matrix4 * @returns {*} */ -R3.Matrix4.prototype.toApiObject = function () { +R3.Matrix4.prototype.toApiObject = function() { return new R3.API.Matrix4( this.rows[0].toApiObject(), @@ -181,7 +181,7 @@ R3.Matrix4.FromObject = function(graphics, objectMatrix, parentObject) { * @param up * @returns {R3.Matrix4} */ -R3.Matrix4.prototype.lookAt = function (position, target, up) { +R3.Matrix4.prototype.lookAt = function(position, target, up) { var pv = new R3.API.Vector3(position.x, position.y, position.z); @@ -232,7 +232,7 @@ R3.Matrix4.prototype.lookAt = function (position, target, up) { /** * Identity */ -R3.Matrix4.prototype.identity = function () { +R3.Matrix4.prototype.identity = function() { this.rows = [ new R3.Vector4( this.graphics, @@ -265,7 +265,7 @@ R3.Matrix4.prototype.identity = function () { * Transpose * @returns {R3.Matrix4} */ -R3.Matrix4.prototype.transpose = function () { +R3.Matrix4.prototype.transpose = function() { this.temp[0].x = this.rows[0].x; this.temp[0].y = this.rows[1].x; diff --git a/src/r3-mouse.js b/src/r3-mouse.js index 6f7b69f..ae61a37 100644 --- a/src/r3-mouse.js +++ b/src/r3-mouse.js @@ -4,7 +4,7 @@ * @returns {R3.Mouse} * @constructor */ -R3.Mouse = function (apiMouse) { +R3.Mouse = function(apiMouse) { if (R3.Utils.UndefinedOrNull(apiMouse)){ apiMouse = {}; @@ -14,7 +14,7 @@ R3.Mouse = function (apiMouse) { this, apiMouse.id, apiMouse.name, - apiMouse.parentEntity, + apiMouse.parent, apiMouse.x, apiMouse.y ); @@ -60,7 +60,7 @@ R3.Mouse.prototype.toApiObject = function() { return new R3.API.Mouse( this.id, this.name, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), this.x, this.y ); diff --git a/src/r3-physics-runtime-cannon.js b/src/r3-physics-runtime-cannon.js new file mode 100644 index 0000000..ae3f5b9 --- /dev/null +++ b/src/r3-physics-runtime-cannon.js @@ -0,0 +1,37 @@ +/** + * R3.PhysicsRuntime.Cannon + * @constructor + */ +R3.PhysicsRuntime.Cannon = function() { + this.createInstance(); +}; + +R3.PhysicsRuntime.Cannon.prototype = Object.create(R3.PhysicsRuntime.prototype); +R3.PhysicsRuntime.Cannon.prototype.constructor = R3.PhysicsRuntime.Cannon; + +R3.PhysicsRuntime.Cannon.prototype.createInstance = function() { + this.instance = CANNON; +}; + +R3.PhysicsRuntime.Cannon.prototype.Vector2 = function(x,y) { + return new this.instance.Vec2(x,y,z); +}; + +R3.PhysicsRuntime.Cannon.prototype.Vector3 = function(x,y,z) { + return new this.instance.Vec3(x,y,z); +}; + +R3.PhysicsRuntime.Cannon.prototype.Vector4 = function(x,y,z,w) { + return new this.instance.Vec4(x,y,z,w); +}; + +/** + * R3.GraphicsRuntime.Three.prototype.Box3 + * @param min + * @param max + * @returns {*|R3.Box3|R3.API.Box3|R3.API.Box3|R3.Box3|R3.API.Box3} + * @constructor + */ +R3.PhysicsRuntime.Cannon.prototype.Box3 = function(min,max) { + console.log('return cannon implementation of box3') +}; \ No newline at end of file diff --git a/src/r3-physics-runtime.js b/src/r3-physics-runtime.js index f2fb777..5e9c8bc 100644 --- a/src/r3-physics-runtime.js +++ b/src/r3-physics-runtime.js @@ -1,31 +1,19 @@ /** - * Physics - * @param id - * @param name - * @param physicsType + * R3.PhysicsRuntime * @constructor */ -R3.PhysicsRuntime = function( - id, - name, - physicsType -) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; +R3.PhysicsRuntime = function() {}; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Physics (' + id + ')'; - } - this.name = name; +R3.PhysicsRuntime.prototype.Vector2 = function(x,y) { + console.warn('override Vector2 in child class'); +}; - if (R3.Utils.UndefinedOrNull(physicsType)) { - physicsType = R3.PhysicsRuntime.TYPE_CANNON_JS; - } - this.physicsType = physicsType; +R3.PhysicsRuntime.prototype.Vector3 = function(x,y,z) { + console.warn('override Vector3 in child class'); +}; - this.createInstance(); +R3.PhysicsRuntime.prototype.Vector4 = function(x,y,z,w) { + console.warn('override Vector4 in child class'); }; /** @@ -33,27 +21,3 @@ R3.PhysicsRuntime = function( * @type {number} */ R3.PhysicsRuntime.TYPE_CANNON_JS = 0x1; - -R3.PhysicsRuntime.prototype.createInstance = function() { - if (this.physicsType === R3.PhysicsRuntime.TYPE_CANNON_JS) { - this.instance = CANNON; - } else { - this.instance = null; - } -}; - -R3.PhysicsRuntime.prototype.updateInstance = function(property) { - if (property === 'physicsType') { - this.createInstance(); - } -}; - -/** - * Logs a warning and throws an error if not cannon - */ -R3.PhysicsRuntime.prototype.isNotCannonThrow = function() { - if (this.instance !== CANNON) { - console.error('Only CANNON supported'); - throw new Error('Only CANNON supported'); - } -}; diff --git a/src/r3-plane.js b/src/r3-plane.js index 4e737bb..2428036 100644 --- a/src/r3-plane.js +++ b/src/r3-plane.js @@ -22,7 +22,7 @@ R3.Plane = function( apiPlane.name, apiPlane.normal, apiPlane.constant, - apiPlane.parentEntity + apiPlane.parent ); this.normal = new R3.Vector3( @@ -80,7 +80,7 @@ R3.Plane.prototype.toApiObject = function() { this.name, this.normal.toApiObject(), this.constant, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-project.js b/src/r3-project.js index 786be0d..52f0880 100644 --- a/src/r3-project.js +++ b/src/r3-project.js @@ -15,7 +15,7 @@ R3.Project = function( this, apiProject.id, apiProject.name, - apiProject.parentEntity, + apiProject.parent, apiProject.users, apiProject.isPublic, apiProject.entities, @@ -27,95 +27,62 @@ R3.Project = function( ); this.users = this.users.map( - function(apiUser) { + function(result, user) { - if (typeof apiUser === 'string') { - return apiUser; + if (user instanceof R3.API.User) { + user = R3.Component.ConstructFromObject(user); } - return new R3.User( - apiUser - ); + result.push(user); - }.bind(this) + return result; + }, + [] ); - this.entities = this.entities.map( - function(apiEntity) { + this.entities = this.entities.reduce( + function(result, entity) { - if (typeof apiEntity === 'string') { - return apiEntity; + if (entity instanceof R3.API.Entity) { + entity = R3.Component.ConstructFromObject(entity); } - return new R3.Entity( - apiEntity - ); + result.push(entity); - }.bind(this) + return result; + }, + [] ); - var graphics = null; + this.renderers = this.renderers.reduce( + function(result, renderer) { - R3.Event.Emit( - R3.Event.GET_RUNTIME, - function(runtime) { - graphics = runtime.graphics; - } - ); - - var renderers = []; - - this.renderers.map( - function (renderer) { - if ( - renderer instanceof R3.API.Renderer.D2 || - renderer instanceof R3.API.Renderer.D3 - ) { - /** - * We need to get the runtime - * @type {R3.Renderer.D2|R3.Renderer.D2|R3.Renderer.D2} - */ - if (graphics === null) { - throw new Error('You require a graphics runtime in order to create a renderer'); - } - - if (renderer instanceof R3.API.Renderer.D2) { - renderer = new R3.Renderer.D2(graphics, renderer) - } - - if (renderer instanceof R3.API.Renderer.D3) { - renderer = new R3.Renderer.D3(graphics, renderer) - } + if (renderer instanceof R3.API.Renderer) { + renderer = R3.Component.ConstructFromObject(renderer); } - renderers.push(renderer); - } + result.push(renderer); + + return result; + }, + [] ); - this.renderers = renderers; - var cameras = []; + this.cameras = this.cameras.reduce( + function(result, camera) { - this.cameras.map( - function(rawCamera) { - if (rawCamera instanceof R3.D3.API.Camera) { - - if (graphics === null) { - throw new Error('You require a graphics runtime in order to create a 3D camera'); - } - - cameras.push(R3.Component.ConstructFromObject(rawCamera)); + if (camera instanceof R3.D3.API.Camera) { + camera = R3.Component.ConstructFromObject(camera); } - } + + result.push(camera); + + return result; + }, + [] ); - this.cameras = cameras; - - if (this.controls instanceof R3.API.Controls.D3) { - - if (graphics === null) { - throw new Error('You require a graphics runtime in order to create 3D Controls'); - } - + if (this.controls instanceof R3.API.Controls) { this.controls = R3.Component.ConstructFromObject(this.controls); } @@ -188,40 +155,35 @@ R3.Project.prototype.updateInstance = function(property) { * @returns {R3.API.Project} */ R3.Project.prototype.toApiObject = function() { - - var apiUsers = this.users.map( - function(user) { - return R3.Utils.IdOrNull(user); - } - ); - - var apiEntities = this.users.map( - function(entity) { - return R3.Utils.IdOrNull(entity); - } - ); - - var apiRenderers = this.renderers.map( - function(renderer) { - return R3.Utils.IdOrNull(renderer); - } - ); - - var apiCameras = this.cameras.map( - function(camera) { - return R3.Utils.IdOrNull(camera); - } - ); - return new R3.API.Project( this.id, this.name, - R3.Utils.IdOrNull(this.parentEntity), - apiUsers, + R3.Utils.IdOrNull(this.parent), + this.users.reduce( + function(result, user) { + result.push(R3.Utils.IdOrNull(user)); + }, + [] + ), this.isPublic, - apiEntities, - apiRenderers, - apiCameras, + this.entities.reduce( + function(result, entity) { + result.push(R3.Utils.IdOrNull(entity)); + }, + [] + ), + this.renderers.reduce( + function(result, renderer) { + result.push(R3.Utils.IdOrNull(renderer)); + }, + [] + ), + this.cameras.reduce( + function(result, camera) { + result.push(R3.Utils.IdOrNull(camera)); + }, + [] + ), this.cameraIndex, R3.Utils.IdOrNull(this.controls), this.mode diff --git a/src/r3-quaternion.js b/src/r3-quaternion.js index abcae2a..b2a07b4 100644 --- a/src/r3-quaternion.js +++ b/src/r3-quaternion.js @@ -6,7 +6,7 @@ * @param grain Number * @constructor */ -R3.Quaternion = function ( +R3.Quaternion = function( implementation, apiQuaternion, parentObject, diff --git a/src/r3-renderer-a.js b/src/r3-renderer-a.js index 3ebb5c6..85868ed 100644 --- a/src/r3-renderer-a.js +++ b/src/r3-renderer-a.js @@ -5,7 +5,7 @@ * @property rendererType * @constructor */ -R3.Renderer = function ( +R3.Renderer = function( graphics, apiRenderer ) { @@ -25,20 +25,11 @@ R3.Renderer = function ( this, apiRenderer.id, apiRenderer.name, + apiRenderer.parent, apiRenderer.rendererType, - apiRenderer.parentEntity, - apiRenderer.width, - apiRenderer.height, - apiRenderer.offset, apiRenderer.canvas ); - this.offset = new R3.Vector2( - this.graphics, - this.offset, - this - ); - if (this.canvas instanceof R3.API.Canvas) { this.canvas = new R3.Canvas( this.graphics, @@ -67,6 +58,8 @@ R3.Renderer.GetLinkedObjects = function(rendererType) { linkedObjects.renderTarget = R3.D3.RenderTarget; linkedObjects.clippingPlanes = [R3.Plane]; linkedObjects.viewports = [R3.D3.Viewport]; + linkedObjects.composer = R3.D3.Composer; + linkedObjects.effect = R3.D3.Effect; break; } @@ -104,25 +97,6 @@ R3.Renderer.prototype.updateInstance = function(property) { return; } - if ( - property === 'width' || - property === 'height' - ) { - console.log('todo: width and height'); - return; - } - - if (property === 'offset') { - - var size = R3.Utils.GetWindowSize(); - - this.canvas.offset.x = this.offset.x * size.width; - this.canvas.offset.y = this.offset.y * size.height; - - this.canvas.updateInstance('offset'); - return; - } - if (property === 'canvas') { console.log('todo: canvas update'); return; @@ -140,17 +114,10 @@ R3.Renderer.prototype.toApiObject = function() { var apiRenderer = new R3.API.Renderer( this.id, this.name, + R3.Utils.IdOrNull(this.parent), this.rendererType, - R3.Utils.IdOrNull(this.parentEntity), - this.width, - this.height, - this.offset.toApiObject(), R3.Utils.IdOrNull(this.canvas) ); return apiRenderer; }; - -R3.Renderer.prototype.setSize = function(width, height) { - console.warn('please implement me in child class'); -}; diff --git a/src/r3-renderer-d2.js b/src/r3-renderer-d2.js index 0c51b0d..cf8798f 100644 --- a/src/r3-renderer-d2.js +++ b/src/r3-renderer-d2.js @@ -4,13 +4,13 @@ * @param apiRendererD2 R3.API.Renderer.D2 * @constructor */ -R3.Renderer.D2 = function ( +R3.Renderer.D2 = function( graphics, apiRendererD2 ) { if (R3.Utils.UndefinedOrNull(graphics)) { - graphics = R3.GraphicsRuntime(null, null, R3.GraphicsRuntime.GRAPHICS_RUNTIME_IMPACT); + graphics = null; } this.graphics = graphics; @@ -86,9 +86,3 @@ R3.Renderer.D2.prototype.toApiObject = function() { return apiRendererD2; }; -/** - * set size - */ -R3.Renderer.D2.prototype.setSize = function(width, height) { - R3.Renderer.prototype.setSize.call(this); -}; diff --git a/src/r3-renderer-d3-canvas-target.js b/src/r3-renderer-d3-canvas-target.js new file mode 100644 index 0000000..eff20b5 --- /dev/null +++ b/src/r3-renderer-d3-canvas-target.js @@ -0,0 +1,533 @@ +/** + * R3.Renderer.D3.Canvas.Target + * @param graphics R3.GraphicsRuntime + * @param apiRendererD3 R3.API.Renderer.D3 + * @constructor + */ +R3.Renderer.D3.Canvas.Target = function( + graphics, + apiRendererD3 +) { + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiRendererD3)) { + apiRendererD3 = { + rendererType : R3.API.Renderer.RENDERER_TYPE_3D + }; + } + + R3.API.Renderer.D3.call( + this, + apiRendererD3, + apiRendererD3.renderMode, + apiRendererD3.autoClear, + apiRendererD3.autoClearColor, + apiRendererD3.autoClearDepth, + apiRendererD3.autoClearStencil, + apiRendererD3.gammaFactor, + apiRendererD3.gammaInput, + apiRendererD3.gammaOutput, + apiRendererD3.maxMorphTargets, + apiRendererD3.maxMorphNormals, + apiRendererD3.physicallyCorrectLights, + apiRendererD3.shadowMapEnabled, + apiRendererD3.shadowMapAutoUpdate, + apiRendererD3.shadowMapNeedsUpdate, + apiRendererD3.shadowMapType, + apiRendererD3.shadowMapRenderReverseSided, + apiRendererD3.shadowMapRenderSingleSided, + apiRendererD3.sortObjects, + apiRendererD3.toneMapping, + apiRendererD3.toneMappingExposure, + apiRendererD3.toneMappingWhitePoint, + apiRendererD3.premultipliedAlpha, + apiRendererD3.antialias, + apiRendererD3.stencil, + apiRendererD3.preserveDrawingBuffer, + apiRendererD3.depth, + apiRendererD3.logarithmicDepthBuffer, + apiRendererD3.localClippingEnabled, + apiRendererD3.renderTarget, + apiRendererD3.clippingPlanes, + apiRendererD3.clearColor, + apiRendererD3.viewports, + apiRendererD3.alpha, + apiRendererD3.opacity, + apiRendererD3.composer, + apiRendererD3.effect, + apiRendererD3.enableComposer, + apiRendererD3.enableEffect + ); + + if (this.renderTarget instanceof R3.D3.API.RenderTarget) { + this.renderTarget = R3.Component.ConstructFromObject(this.renderTarget); + } + + this.clippingPlanes = this.clippingPlanes.reduce( + function(result, clippingPlane) { + + if (clippingPlane instanceof R3.API.Plane) { + clippingPlane = R3.Component.ConstructFromObject(clippingPlane); + } + + result.push(clippingPlane); + + return result; + }, + [] + ); + + this.clearColor = new R3.Color( + this.graphics, + this.clearColor, + this + ); + + this.viewports = this.viewports.reduce( + function(result, viewport) { + + if (viewport instanceof R3.D3.API.Viewport) { + viewport = R3.Component.ConstructFromObject(viewport); + } + + result.push(viewport); + + return result; + }, + [] + ); + + if (this.composer instanceof R3.D3.API.Composer) { + this.composer = R3.Component.ConstructFromObject(this.composer); + } + + if (this.effect instanceof R3.D3.API.Effect) { + this.effect = R3.Component.ConstructFromObject(this.effect); + } + + R3.Renderer.call( + this, + this.graphics, + this + ); + +}; + +R3.Renderer.D3.prototype = Object.create(R3.Renderer.prototype); +R3.Renderer.D3.prototype.constructor = R3.Renderer.D3; + +/** + * Create R3.Renderer.D3 Instance + * @returns {*} + */ +R3.Renderer.D3.prototype.createInstance = function() { + + if ( + R3.Utils.UndefinedOrNull(this.canvas) || + R3.Utils.UndefinedOrNull(this.canvas.instance) + ) { + console.warn('no canvas instance'); + return; + } + + this.instance = new THREE.WebGLRenderer( + { + canvas : this.canvas.instance, + alpha : this.alpha, + premultipliedAlpha : this.premultipliedAlpha, + antialias : this.antialias, + stencil : this.stencil, + preserveDrawingBuffer : this.preserveDrawingBuffer, + depth : this.depth, + logarithmicDepthBuffer : this.logarithmicDepthBuffer + } + ); + + this.instance.setPixelRatio(window.devicePixelRatio); + + this.instance.autoClear = this.autoClear; + this.instance.autoClearColor = this.autoClearColor; + this.instance.autoClearDepth = this.autoClearDepth; + this.instance.autoClearStencil = this.autoClearStencil; + + this.instance.gammaFactor = this.gammaFactor; + this.instance.gammaInput = this.gammaInput; + this.instance.gammaOutput = this.gammaOutput; + + this.instance.maxMorphTargets = this.maxMorphTargets; + this.instance.maxMorphNormals = this.maxMorphNormals; + + this.instance.physicallyCorrectLights = this.physicallyCorrectLights; + + this.instance.shadowMap.enabled = this.shadowMapEnabled; + this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate; + this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate; + this.instance.shadowMap.type = this.shadowMapType; + this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided; + this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided; + + this.instance.sortObjects = this.sortObjects; + + this.instance.toneMapping = this.toneMapping; + this.instance.toneMappingExposure = this.toneMappingExposure; + this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint; + + this.instance.premultipliedAlpha = this.premultipliedAlpha; + + this.instance.localClippingEnabled = this.localClippingEnabled; + + if (this.renderTarget) { + this.instance.setRenderTarget(this.renderTarget.instance); + } + + if (this.clippingPlanes.length > 0) { + this.instance.clippingPlanes = this.clippingPlanes.map( + function(clippingPlane) { + return clippingPlane.instance; + } + ) + } + + this.instance.setClearColor( + new THREE.Color( + this.clearColor.r, + this.clearColor.g, + this.clearColor.b + ), + this.opacity + ); + + R3.Renderer.prototype.createInstance.call(this); +}; + +/** + * Update Renderer.D3 Instance + */ +R3.Renderer.D3.prototype.updateInstance = function(property) { + + if (!property) { + throw new Error('no renderer property'); + } + + if (!this.instance) { + throw new Error('no renderer instance'); + } + + if (property === 'renderMode') { + console.log('render mode change'); + return; + } + + if (property === 'autoClear') { + this.instance.autoClear = this.autoClear; + return; + } + + if (property === 'autoClearColor') { + this.instance.autoClearColor = this.autoClearColor; + return; + } + + if (property === 'autoClearDepth') { + this.instance.autoClearDepth = this.autoClearDepth; + return; + } + + if (property === 'autoClearStencil') { + this.instance.autoClearStencil = this.autoClearStencil; + return; + } + + if (property === 'gammaFactor') { + this.instance.gammaFactor = this.gammaFactor; + return; + } + + if (property === 'gammaInput') { + this.instance.gammaInput = this.gammaInput; + return; + } + + if (property === 'gammaOutput') { + this.instance.gammaOutput = this.gammaOutput; + return; + } + + if (property === 'maxMorphTargets') { + this.instance.maxMorphTargets = this.maxMorphTargets; + return; + } + + if (property === 'maxMorphNormals') { + this.instance.maxMorphNormals = this.maxMorphNormals; + return; + } + + if (property === 'physicallyCorrectLights') { + this.instance.physicallyCorrectLights = this.physicallyCorrectLights; + return; + } + + if (property === 'shadowMapEnabled') { + this.instance.shadowMap.enabled = this.shadowMapEnabled; + return; + } + + if (property === 'shadowMapAutoUpdate') { + this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate; + return; + } + + if (property === 'shadowMapNeedsUpdate') { + this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate; + return; + } + + if (property === 'shadowMapType') { + this.instance.shadowMap.type = this.shadowMapType; + return; + } + + if (property === 'shadowMapRenderReverseSided') { + this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided; + return; + } + + if (property === 'shadowMapRenderSingleSided') { + this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided; + return; + } + + if (property === 'sortObjects') { + this.instance.sortObjects = this.sortObjects; + return; + } + + if (property === 'toneMapping') { + this.instance.toneMapping = this.toneMapping; + return; + } + + if (property === 'toneMappingExposure') { + this.instance.toneMappingExposure = this.toneMappingExposure; + return; + } + + if (property === 'toneMappingWhitePoint') { + this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint; + return; + } + + if (property === 'premultipliedAlpha') { + this.instance.premultipliedAlpha = this.premultipliedAlpha; + return; + } + + if (property === 'premultipliedAlpha') { + this.instance.premultipliedAlpha = this.premultipliedAlpha; + return; + } + + if (property === 'antialias') { + this.instance.antialias = this.antialias; + return; + } + + if (property === 'stencil') { + this.instance.stencil = this.stencil; + return; + } + + if (property === 'preserveDrawingBuffer') { + this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer; + return; + } + + if (property === 'depth') { + this.instance.depth = this.depth; + return; + } + + if (property === 'logarithmicDepthBuffer') { + this.instance.logarithmicDepthBuffer = this.logarithmicDepthBuffer; + return; + } + + if (property === 'localClippingEnabled') { + this.instance.localClippingEnabled = this.localClippingEnabled; + return; + } + + if (property === 'canvas') { + + if (R3.Utils.UndefinedOrNull(this.instance)) { + this.createInstance(); + } else { + console.warn('experimental canvas change for renderer'); + this.instance.dispose(); + this.createInstance(); + } + + return; + } + + if (property === 'renderTarget') { + + if ( + R3.Utils.Defined(this.instance) && + R3.Utils.Defined(this.renderTarget) && + R3.Utils.Defined(this.renderTarget.instance) + ) { + this.instance.setRenderTarget(this.renderTarget.instance); + console.log('updated render target on render instance'); + } + + return; + } + + if (property === 'clippingPlanes') { + console.warn('todo: clipping planes change'); + return; + } + + if ( + property === 'clearColor' || + property === 'opacity' + ) { + this.instance.setClearColor( + new THREE.Color( + this.clearColor.r, + this.clearColor.g, + this.clearColor.b + ), + this.opacity + ); + return; + } + + if (property === 'viewports') { + console.warn('todo: viewports change'); + } + + if (property === 'alpha') { + this.instance.alpha = this.alpha; + return; + } + + R3.Renderer.prototype.updateInstance.call(this, property); +}; + +/** + * Wrapper for clear() + */ +R3.Renderer.D3.prototype.clear = function() { + return this.instance.clear(); +}; + + +/** + * Convenience function to set viewport + * @param x + * @param y + * @param width + * @param height + */ +R3.Renderer.D3.prototype.setViewport = function( + x, + y, + width, + height +) { + this.instance.setViewport( + x, + y, + width, + height + ); +}; + +/** + * Renders to this.renderTarget + * @param scene + * @param camera + */ +R3.Renderer.D3.prototype.renderToTarget = function(scene, camera) { + + this.instance.render( + scene.instance, + camera.instance, + this.renderTarget.instance + ); + +}; + +/** + * Renders normally + * @param scene + * @param camera + */ +R3.Renderer.D3.prototype.render = function(scene, camera) { + this.instance.render( + scene.instance, + camera.instance + ) +}; + + +/** + * + * @returns {R3.API.Renderer.D3} + */ +R3.Renderer.D3.prototype.toApiObject = function() { + + var apiRenderer = R3.Renderer.prototype.toApiObject.call(this); + + var apiRendererD3 = new R3.API.Renderer.D3( + apiRenderer, + this.renderMode, + this.autoClear, + this.autoClearColor, + this.autoClearDepth, + this.autoClearStencil, + this.gammaFactor, + this.gammaInput, + this.gammaOutput, + this.maxMorphTargets, + this.maxMorphNormals, + this.physicallyCorrectLights, + this.shadowMapEnabled, + this.shadowMapAutoUpdate, + this.shadowMapNeedsUpdate, + this.shadowMapType, + this.shadowMapRenderReverseSided, + this.shadowMapRenderSingleSided, + this.sortObjects, + this.toneMapping, + this.toneMappingExposure, + this.toneMappingWhitePoint, + this.premultipliedAlpha, + this.antialias, + this.stencil, + this.preserveDrawingBuffer, + this.depth, + this.logarithmicDepthBuffer, + this.localClippingEnabled, + R3.Utils.IdOrNull(this.renderTarget), + this.clippingPlanes.map( + function(clippingPlane){ + return R3.Utils.IdOrNull(clippingPlane); + } + ), + this.clearColor.toApiObject(), + this.viewports.map( + function(viewport){ + return R3.Utils.IdOrNull(viewport); + } + ), + this.alpha, + this.opacity + ); + + return apiRendererD3; +}; diff --git a/src/r3-renderer-d3-canvas.js b/src/r3-renderer-d3-canvas.js new file mode 100644 index 0000000..57174e6 --- /dev/null +++ b/src/r3-renderer-d3-canvas.js @@ -0,0 +1,533 @@ +/** + * R3.Renderer.D3.Canvas + * @param graphics R3.GraphicsRuntime + * @param apiRendererD3 R3.API.Renderer.D3 + * @constructor + */ +R3.Renderer.D3.Canvas = function( + graphics, + apiRendererD3 +) { + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiRendererD3)) { + apiRendererD3 = { + rendererType : R3.API.Renderer.RENDERER_TYPE_3D + }; + } + + R3.API.Renderer.D3.call( + this, + apiRendererD3, + apiRendererD3.renderMode, + apiRendererD3.autoClear, + apiRendererD3.autoClearColor, + apiRendererD3.autoClearDepth, + apiRendererD3.autoClearStencil, + apiRendererD3.gammaFactor, + apiRendererD3.gammaInput, + apiRendererD3.gammaOutput, + apiRendererD3.maxMorphTargets, + apiRendererD3.maxMorphNormals, + apiRendererD3.physicallyCorrectLights, + apiRendererD3.shadowMapEnabled, + apiRendererD3.shadowMapAutoUpdate, + apiRendererD3.shadowMapNeedsUpdate, + apiRendererD3.shadowMapType, + apiRendererD3.shadowMapRenderReverseSided, + apiRendererD3.shadowMapRenderSingleSided, + apiRendererD3.sortObjects, + apiRendererD3.toneMapping, + apiRendererD3.toneMappingExposure, + apiRendererD3.toneMappingWhitePoint, + apiRendererD3.premultipliedAlpha, + apiRendererD3.antialias, + apiRendererD3.stencil, + apiRendererD3.preserveDrawingBuffer, + apiRendererD3.depth, + apiRendererD3.logarithmicDepthBuffer, + apiRendererD3.localClippingEnabled, + apiRendererD3.renderTarget, + apiRendererD3.clippingPlanes, + apiRendererD3.clearColor, + apiRendererD3.viewports, + apiRendererD3.alpha, + apiRendererD3.opacity, + apiRendererD3.composer, + apiRendererD3.effect, + apiRendererD3.enableComposer, + apiRendererD3.enableEffect + ); + + if (this.renderTarget instanceof R3.D3.API.RenderTarget) { + this.renderTarget = R3.Component.ConstructFromObject(this.renderTarget); + } + + this.clippingPlanes = this.clippingPlanes.reduce( + function(result, clippingPlane) { + + if (clippingPlane instanceof R3.API.Plane) { + clippingPlane = R3.Component.ConstructFromObject(clippingPlane); + } + + result.push(clippingPlane); + + return result; + }, + [] + ); + + this.clearColor = new R3.Color( + this.graphics, + this.clearColor, + this + ); + + this.viewports = this.viewports.reduce( + function(result, viewport) { + + if (viewport instanceof R3.D3.API.Viewport) { + viewport = R3.Component.ConstructFromObject(viewport); + } + + result.push(viewport); + + return result; + }, + [] + ); + + if (this.composer instanceof R3.D3.API.Composer) { + this.composer = R3.Component.ConstructFromObject(this.composer); + } + + if (this.effect instanceof R3.D3.API.Effect) { + this.effect = R3.Component.ConstructFromObject(this.effect); + } + + R3.Renderer.call( + this, + this.graphics, + this + ); + +}; + +R3.Renderer.D3.prototype = Object.create(R3.Renderer.prototype); +R3.Renderer.D3.prototype.constructor = R3.Renderer.D3; + +/** + * Create R3.Renderer.D3 Instance + * @returns {*} + */ +R3.Renderer.D3.prototype.createInstance = function() { + + if ( + R3.Utils.UndefinedOrNull(this.canvas) || + R3.Utils.UndefinedOrNull(this.canvas.instance) + ) { + console.warn('no canvas instance'); + return; + } + + this.instance = new THREE.WebGLRenderer( + { + canvas : this.canvas.instance, + alpha : this.alpha, + premultipliedAlpha : this.premultipliedAlpha, + antialias : this.antialias, + stencil : this.stencil, + preserveDrawingBuffer : this.preserveDrawingBuffer, + depth : this.depth, + logarithmicDepthBuffer : this.logarithmicDepthBuffer + } + ); + + this.instance.setPixelRatio(window.devicePixelRatio); + + this.instance.autoClear = this.autoClear; + this.instance.autoClearColor = this.autoClearColor; + this.instance.autoClearDepth = this.autoClearDepth; + this.instance.autoClearStencil = this.autoClearStencil; + + this.instance.gammaFactor = this.gammaFactor; + this.instance.gammaInput = this.gammaInput; + this.instance.gammaOutput = this.gammaOutput; + + this.instance.maxMorphTargets = this.maxMorphTargets; + this.instance.maxMorphNormals = this.maxMorphNormals; + + this.instance.physicallyCorrectLights = this.physicallyCorrectLights; + + this.instance.shadowMap.enabled = this.shadowMapEnabled; + this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate; + this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate; + this.instance.shadowMap.type = this.shadowMapType; + this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided; + this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided; + + this.instance.sortObjects = this.sortObjects; + + this.instance.toneMapping = this.toneMapping; + this.instance.toneMappingExposure = this.toneMappingExposure; + this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint; + + this.instance.premultipliedAlpha = this.premultipliedAlpha; + + this.instance.localClippingEnabled = this.localClippingEnabled; + + if (this.renderTarget) { + this.instance.setRenderTarget(this.renderTarget.instance); + } + + if (this.clippingPlanes.length > 0) { + this.instance.clippingPlanes = this.clippingPlanes.map( + function(clippingPlane) { + return clippingPlane.instance; + } + ) + } + + this.instance.setClearColor( + new THREE.Color( + this.clearColor.r, + this.clearColor.g, + this.clearColor.b + ), + this.opacity + ); + + R3.Renderer.prototype.createInstance.call(this); +}; + +/** + * Update Renderer.D3 Instance + */ +R3.Renderer.D3.prototype.updateInstance = function(property) { + + if (!property) { + throw new Error('no renderer property'); + } + + if (!this.instance) { + throw new Error('no renderer instance'); + } + + if (property === 'renderMode') { + console.log('render mode change'); + return; + } + + if (property === 'autoClear') { + this.instance.autoClear = this.autoClear; + return; + } + + if (property === 'autoClearColor') { + this.instance.autoClearColor = this.autoClearColor; + return; + } + + if (property === 'autoClearDepth') { + this.instance.autoClearDepth = this.autoClearDepth; + return; + } + + if (property === 'autoClearStencil') { + this.instance.autoClearStencil = this.autoClearStencil; + return; + } + + if (property === 'gammaFactor') { + this.instance.gammaFactor = this.gammaFactor; + return; + } + + if (property === 'gammaInput') { + this.instance.gammaInput = this.gammaInput; + return; + } + + if (property === 'gammaOutput') { + this.instance.gammaOutput = this.gammaOutput; + return; + } + + if (property === 'maxMorphTargets') { + this.instance.maxMorphTargets = this.maxMorphTargets; + return; + } + + if (property === 'maxMorphNormals') { + this.instance.maxMorphNormals = this.maxMorphNormals; + return; + } + + if (property === 'physicallyCorrectLights') { + this.instance.physicallyCorrectLights = this.physicallyCorrectLights; + return; + } + + if (property === 'shadowMapEnabled') { + this.instance.shadowMap.enabled = this.shadowMapEnabled; + return; + } + + if (property === 'shadowMapAutoUpdate') { + this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate; + return; + } + + if (property === 'shadowMapNeedsUpdate') { + this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate; + return; + } + + if (property === 'shadowMapType') { + this.instance.shadowMap.type = this.shadowMapType; + return; + } + + if (property === 'shadowMapRenderReverseSided') { + this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided; + return; + } + + if (property === 'shadowMapRenderSingleSided') { + this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided; + return; + } + + if (property === 'sortObjects') { + this.instance.sortObjects = this.sortObjects; + return; + } + + if (property === 'toneMapping') { + this.instance.toneMapping = this.toneMapping; + return; + } + + if (property === 'toneMappingExposure') { + this.instance.toneMappingExposure = this.toneMappingExposure; + return; + } + + if (property === 'toneMappingWhitePoint') { + this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint; + return; + } + + if (property === 'premultipliedAlpha') { + this.instance.premultipliedAlpha = this.premultipliedAlpha; + return; + } + + if (property === 'premultipliedAlpha') { + this.instance.premultipliedAlpha = this.premultipliedAlpha; + return; + } + + if (property === 'antialias') { + this.instance.antialias = this.antialias; + return; + } + + if (property === 'stencil') { + this.instance.stencil = this.stencil; + return; + } + + if (property === 'preserveDrawingBuffer') { + this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer; + return; + } + + if (property === 'depth') { + this.instance.depth = this.depth; + return; + } + + if (property === 'logarithmicDepthBuffer') { + this.instance.logarithmicDepthBuffer = this.logarithmicDepthBuffer; + return; + } + + if (property === 'localClippingEnabled') { + this.instance.localClippingEnabled = this.localClippingEnabled; + return; + } + + if (property === 'canvas') { + + if (R3.Utils.UndefinedOrNull(this.instance)) { + this.createInstance(); + } else { + console.warn('experimental canvas change for renderer'); + this.instance.dispose(); + this.createInstance(); + } + + return; + } + + if (property === 'renderTarget') { + + if ( + R3.Utils.Defined(this.instance) && + R3.Utils.Defined(this.renderTarget) && + R3.Utils.Defined(this.renderTarget.instance) + ) { + this.instance.setRenderTarget(this.renderTarget.instance); + console.log('updated render target on render instance'); + } + + return; + } + + if (property === 'clippingPlanes') { + console.warn('todo: clipping planes change'); + return; + } + + if ( + property === 'clearColor' || + property === 'opacity' + ) { + this.instance.setClearColor( + new THREE.Color( + this.clearColor.r, + this.clearColor.g, + this.clearColor.b + ), + this.opacity + ); + return; + } + + if (property === 'viewports') { + console.warn('todo: viewports change'); + } + + if (property === 'alpha') { + this.instance.alpha = this.alpha; + return; + } + + R3.Renderer.prototype.updateInstance.call(this, property); +}; + +/** + * Wrapper for clear() + */ +R3.Renderer.D3.prototype.clear = function() { + return this.instance.clear(); +}; + + +/** + * Convenience function to set viewport + * @param x + * @param y + * @param width + * @param height + */ +R3.Renderer.D3.prototype.setViewport = function( + x, + y, + width, + height +) { + this.instance.setViewport( + x, + y, + width, + height + ); +}; + +/** + * Renders to this.renderTarget + * @param scene + * @param camera + */ +R3.Renderer.D3.prototype.renderToTarget = function(scene, camera) { + + this.instance.render( + scene.instance, + camera.instance, + this.renderTarget.instance + ); + +}; + +/** + * Renders normally + * @param scene + * @param camera + */ +R3.Renderer.D3.prototype.render = function(scene, camera) { + this.instance.render( + scene.instance, + camera.instance + ) +}; + + +/** + * + * @returns {R3.API.Renderer.D3} + */ +R3.Renderer.D3.prototype.toApiObject = function() { + + var apiRenderer = R3.Renderer.prototype.toApiObject.call(this); + + var apiRendererD3 = new R3.API.Renderer.D3( + apiRenderer, + this.renderMode, + this.autoClear, + this.autoClearColor, + this.autoClearDepth, + this.autoClearStencil, + this.gammaFactor, + this.gammaInput, + this.gammaOutput, + this.maxMorphTargets, + this.maxMorphNormals, + this.physicallyCorrectLights, + this.shadowMapEnabled, + this.shadowMapAutoUpdate, + this.shadowMapNeedsUpdate, + this.shadowMapType, + this.shadowMapRenderReverseSided, + this.shadowMapRenderSingleSided, + this.sortObjects, + this.toneMapping, + this.toneMappingExposure, + this.toneMappingWhitePoint, + this.premultipliedAlpha, + this.antialias, + this.stencil, + this.preserveDrawingBuffer, + this.depth, + this.logarithmicDepthBuffer, + this.localClippingEnabled, + R3.Utils.IdOrNull(this.renderTarget), + this.clippingPlanes.map( + function(clippingPlane){ + return R3.Utils.IdOrNull(clippingPlane); + } + ), + this.clearColor.toApiObject(), + this.viewports.map( + function(viewport){ + return R3.Utils.IdOrNull(viewport); + } + ), + this.alpha, + this.opacity + ); + + return apiRendererD3; +}; diff --git a/src/r3-renderer-d3-target.js b/src/r3-renderer-d3-target.js new file mode 100644 index 0000000..93cd86d --- /dev/null +++ b/src/r3-renderer-d3-target.js @@ -0,0 +1,533 @@ +/** + * R3.Renderer.D3.Target + * @param graphics R3.GraphicsRuntime + * @param apiRendererD3 R3.API.Renderer.D3 + * @constructor + */ +R3.Renderer.D3.Target = function( + graphics, + apiRendererD3 +) { + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiRendererD3)) { + apiRendererD3 = { + rendererType : R3.API.Renderer.RENDERER_TYPE_3D + }; + } + + R3.API.Renderer.D3.call( + this, + apiRendererD3, + apiRendererD3.renderMode, + apiRendererD3.autoClear, + apiRendererD3.autoClearColor, + apiRendererD3.autoClearDepth, + apiRendererD3.autoClearStencil, + apiRendererD3.gammaFactor, + apiRendererD3.gammaInput, + apiRendererD3.gammaOutput, + apiRendererD3.maxMorphTargets, + apiRendererD3.maxMorphNormals, + apiRendererD3.physicallyCorrectLights, + apiRendererD3.shadowMapEnabled, + apiRendererD3.shadowMapAutoUpdate, + apiRendererD3.shadowMapNeedsUpdate, + apiRendererD3.shadowMapType, + apiRendererD3.shadowMapRenderReverseSided, + apiRendererD3.shadowMapRenderSingleSided, + apiRendererD3.sortObjects, + apiRendererD3.toneMapping, + apiRendererD3.toneMappingExposure, + apiRendererD3.toneMappingWhitePoint, + apiRendererD3.premultipliedAlpha, + apiRendererD3.antialias, + apiRendererD3.stencil, + apiRendererD3.preserveDrawingBuffer, + apiRendererD3.depth, + apiRendererD3.logarithmicDepthBuffer, + apiRendererD3.localClippingEnabled, + apiRendererD3.renderTarget, + apiRendererD3.clippingPlanes, + apiRendererD3.clearColor, + apiRendererD3.viewports, + apiRendererD3.alpha, + apiRendererD3.opacity, + apiRendererD3.composer, + apiRendererD3.effect, + apiRendererD3.enableComposer, + apiRendererD3.enableEffect + ); + + if (this.renderTarget instanceof R3.D3.API.RenderTarget) { + this.renderTarget = R3.Component.ConstructFromObject(this.renderTarget); + } + + this.clippingPlanes = this.clippingPlanes.reduce( + function(result, clippingPlane) { + + if (clippingPlane instanceof R3.API.Plane) { + clippingPlane = R3.Component.ConstructFromObject(clippingPlane); + } + + result.push(clippingPlane); + + return result; + }, + [] + ); + + this.clearColor = new R3.Color( + this.graphics, + this.clearColor, + this + ); + + this.viewports = this.viewports.reduce( + function(result, viewport) { + + if (viewport instanceof R3.D3.API.Viewport) { + viewport = R3.Component.ConstructFromObject(viewport); + } + + result.push(viewport); + + return result; + }, + [] + ); + + if (this.composer instanceof R3.D3.API.Composer) { + this.composer = R3.Component.ConstructFromObject(this.composer); + } + + if (this.effect instanceof R3.D3.API.Effect) { + this.effect = R3.Component.ConstructFromObject(this.effect); + } + + R3.Renderer.call( + this, + this.graphics, + this + ); + +}; + +R3.Renderer.D3.prototype = Object.create(R3.Renderer.prototype); +R3.Renderer.D3.prototype.constructor = R3.Renderer.D3; + +/** + * Create R3.Renderer.D3 Instance + * @returns {*} + */ +R3.Renderer.D3.prototype.createInstance = function() { + + if ( + R3.Utils.UndefinedOrNull(this.canvas) || + R3.Utils.UndefinedOrNull(this.canvas.instance) + ) { + console.warn('no canvas instance'); + return; + } + + this.instance = new THREE.WebGLRenderer( + { + canvas : this.canvas.instance, + alpha : this.alpha, + premultipliedAlpha : this.premultipliedAlpha, + antialias : this.antialias, + stencil : this.stencil, + preserveDrawingBuffer : this.preserveDrawingBuffer, + depth : this.depth, + logarithmicDepthBuffer : this.logarithmicDepthBuffer + } + ); + + this.instance.setPixelRatio(window.devicePixelRatio); + + this.instance.autoClear = this.autoClear; + this.instance.autoClearColor = this.autoClearColor; + this.instance.autoClearDepth = this.autoClearDepth; + this.instance.autoClearStencil = this.autoClearStencil; + + this.instance.gammaFactor = this.gammaFactor; + this.instance.gammaInput = this.gammaInput; + this.instance.gammaOutput = this.gammaOutput; + + this.instance.maxMorphTargets = this.maxMorphTargets; + this.instance.maxMorphNormals = this.maxMorphNormals; + + this.instance.physicallyCorrectLights = this.physicallyCorrectLights; + + this.instance.shadowMap.enabled = this.shadowMapEnabled; + this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate; + this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate; + this.instance.shadowMap.type = this.shadowMapType; + this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided; + this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided; + + this.instance.sortObjects = this.sortObjects; + + this.instance.toneMapping = this.toneMapping; + this.instance.toneMappingExposure = this.toneMappingExposure; + this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint; + + this.instance.premultipliedAlpha = this.premultipliedAlpha; + + this.instance.localClippingEnabled = this.localClippingEnabled; + + if (this.renderTarget) { + this.instance.setRenderTarget(this.renderTarget.instance); + } + + if (this.clippingPlanes.length > 0) { + this.instance.clippingPlanes = this.clippingPlanes.map( + function(clippingPlane) { + return clippingPlane.instance; + } + ) + } + + this.instance.setClearColor( + new THREE.Color( + this.clearColor.r, + this.clearColor.g, + this.clearColor.b + ), + this.opacity + ); + + R3.Renderer.prototype.createInstance.call(this); +}; + +/** + * Update Renderer.D3 Instance + */ +R3.Renderer.D3.prototype.updateInstance = function(property) { + + if (!property) { + throw new Error('no renderer property'); + } + + if (!this.instance) { + throw new Error('no renderer instance'); + } + + if (property === 'renderMode') { + console.log('render mode change'); + return; + } + + if (property === 'autoClear') { + this.instance.autoClear = this.autoClear; + return; + } + + if (property === 'autoClearColor') { + this.instance.autoClearColor = this.autoClearColor; + return; + } + + if (property === 'autoClearDepth') { + this.instance.autoClearDepth = this.autoClearDepth; + return; + } + + if (property === 'autoClearStencil') { + this.instance.autoClearStencil = this.autoClearStencil; + return; + } + + if (property === 'gammaFactor') { + this.instance.gammaFactor = this.gammaFactor; + return; + } + + if (property === 'gammaInput') { + this.instance.gammaInput = this.gammaInput; + return; + } + + if (property === 'gammaOutput') { + this.instance.gammaOutput = this.gammaOutput; + return; + } + + if (property === 'maxMorphTargets') { + this.instance.maxMorphTargets = this.maxMorphTargets; + return; + } + + if (property === 'maxMorphNormals') { + this.instance.maxMorphNormals = this.maxMorphNormals; + return; + } + + if (property === 'physicallyCorrectLights') { + this.instance.physicallyCorrectLights = this.physicallyCorrectLights; + return; + } + + if (property === 'shadowMapEnabled') { + this.instance.shadowMap.enabled = this.shadowMapEnabled; + return; + } + + if (property === 'shadowMapAutoUpdate') { + this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate; + return; + } + + if (property === 'shadowMapNeedsUpdate') { + this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate; + return; + } + + if (property === 'shadowMapType') { + this.instance.shadowMap.type = this.shadowMapType; + return; + } + + if (property === 'shadowMapRenderReverseSided') { + this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided; + return; + } + + if (property === 'shadowMapRenderSingleSided') { + this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided; + return; + } + + if (property === 'sortObjects') { + this.instance.sortObjects = this.sortObjects; + return; + } + + if (property === 'toneMapping') { + this.instance.toneMapping = this.toneMapping; + return; + } + + if (property === 'toneMappingExposure') { + this.instance.toneMappingExposure = this.toneMappingExposure; + return; + } + + if (property === 'toneMappingWhitePoint') { + this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint; + return; + } + + if (property === 'premultipliedAlpha') { + this.instance.premultipliedAlpha = this.premultipliedAlpha; + return; + } + + if (property === 'premultipliedAlpha') { + this.instance.premultipliedAlpha = this.premultipliedAlpha; + return; + } + + if (property === 'antialias') { + this.instance.antialias = this.antialias; + return; + } + + if (property === 'stencil') { + this.instance.stencil = this.stencil; + return; + } + + if (property === 'preserveDrawingBuffer') { + this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer; + return; + } + + if (property === 'depth') { + this.instance.depth = this.depth; + return; + } + + if (property === 'logarithmicDepthBuffer') { + this.instance.logarithmicDepthBuffer = this.logarithmicDepthBuffer; + return; + } + + if (property === 'localClippingEnabled') { + this.instance.localClippingEnabled = this.localClippingEnabled; + return; + } + + if (property === 'canvas') { + + if (R3.Utils.UndefinedOrNull(this.instance)) { + this.createInstance(); + } else { + console.warn('experimental canvas change for renderer'); + this.instance.dispose(); + this.createInstance(); + } + + return; + } + + if (property === 'renderTarget') { + + if ( + R3.Utils.Defined(this.instance) && + R3.Utils.Defined(this.renderTarget) && + R3.Utils.Defined(this.renderTarget.instance) + ) { + this.instance.setRenderTarget(this.renderTarget.instance); + console.log('updated render target on render instance'); + } + + return; + } + + if (property === 'clippingPlanes') { + console.warn('todo: clipping planes change'); + return; + } + + if ( + property === 'clearColor' || + property === 'opacity' + ) { + this.instance.setClearColor( + new THREE.Color( + this.clearColor.r, + this.clearColor.g, + this.clearColor.b + ), + this.opacity + ); + return; + } + + if (property === 'viewports') { + console.warn('todo: viewports change'); + } + + if (property === 'alpha') { + this.instance.alpha = this.alpha; + return; + } + + R3.Renderer.prototype.updateInstance.call(this, property); +}; + +/** + * Wrapper for clear() + */ +R3.Renderer.D3.prototype.clear = function() { + return this.instance.clear(); +}; + + +/** + * Convenience function to set viewport + * @param x + * @param y + * @param width + * @param height + */ +R3.Renderer.D3.prototype.setViewport = function( + x, + y, + width, + height +) { + this.instance.setViewport( + x, + y, + width, + height + ); +}; + +/** + * Renders to this.renderTarget + * @param scene + * @param camera + */ +R3.Renderer.D3.prototype.renderToTarget = function(scene, camera) { + + this.instance.render( + scene.instance, + camera.instance, + this.renderTarget.instance + ); + +}; + +/** + * Renders normally + * @param scene + * @param camera + */ +R3.Renderer.D3.prototype.render = function(scene, camera) { + this.instance.render( + scene.instance, + camera.instance + ) +}; + + +/** + * + * @returns {R3.API.Renderer.D3} + */ +R3.Renderer.D3.prototype.toApiObject = function() { + + var apiRenderer = R3.Renderer.prototype.toApiObject.call(this); + + var apiRendererD3 = new R3.API.Renderer.D3( + apiRenderer, + this.renderMode, + this.autoClear, + this.autoClearColor, + this.autoClearDepth, + this.autoClearStencil, + this.gammaFactor, + this.gammaInput, + this.gammaOutput, + this.maxMorphTargets, + this.maxMorphNormals, + this.physicallyCorrectLights, + this.shadowMapEnabled, + this.shadowMapAutoUpdate, + this.shadowMapNeedsUpdate, + this.shadowMapType, + this.shadowMapRenderReverseSided, + this.shadowMapRenderSingleSided, + this.sortObjects, + this.toneMapping, + this.toneMappingExposure, + this.toneMappingWhitePoint, + this.premultipliedAlpha, + this.antialias, + this.stencil, + this.preserveDrawingBuffer, + this.depth, + this.logarithmicDepthBuffer, + this.localClippingEnabled, + R3.Utils.IdOrNull(this.renderTarget), + this.clippingPlanes.map( + function(clippingPlane){ + return R3.Utils.IdOrNull(clippingPlane); + } + ), + this.clearColor.toApiObject(), + this.viewports.map( + function(viewport){ + return R3.Utils.IdOrNull(viewport); + } + ), + this.alpha, + this.opacity + ); + + return apiRendererD3; +}; diff --git a/src/r3-renderer-d3.js b/src/r3-renderer-d3.js index b415ae7..d81bfa0 100644 --- a/src/r3-renderer-d3.js +++ b/src/r3-renderer-d3.js @@ -4,7 +4,7 @@ * @param apiRendererD3 R3.API.Renderer.D3 * @constructor */ -R3.Renderer.D3 = function ( +R3.Renderer.D3 = function( graphics, apiRendererD3 ) { @@ -53,26 +53,30 @@ R3.Renderer.D3 = function ( apiRendererD3.clearColor, apiRendererD3.viewports, apiRendererD3.alpha, - apiRendererD3.opacity + apiRendererD3.opacity, + apiRendererD3.composer, + apiRendererD3.effect, + apiRendererD3.enableComposer, + apiRendererD3.enableEffect ); if (this.renderTarget instanceof R3.D3.API.RenderTarget) { - this.renderTarget = new R3.D3.RenderTarget( - this.graphics, - this.renderTarget - ) + this.renderTarget = R3.Component.ConstructFromObject(this.renderTarget); } - this.clippingPlanes = this.clippingPlanes.map(function(clippingPlane){ - if (clippingPlane instanceof R3.API.Plane) { - return new R3.Plane( - this.graphics, - clippingPlane - ); - } else { - return clippingPlane; - } - }.bind(this)); + this.clippingPlanes = this.clippingPlanes.reduce( + function(result, clippingPlane) { + + if (clippingPlane instanceof R3.API.Plane) { + clippingPlane = R3.Component.ConstructFromObject(clippingPlane); + } + + result.push(clippingPlane); + + return result; + }, + [] + ); this.clearColor = new R3.Color( this.graphics, @@ -80,16 +84,27 @@ R3.Renderer.D3 = function ( this ); - this.viewports = this.viewports.map(function(viewport){ - if (viewport instanceof R3.D3.API.Viewport) { - return new R3.D3.Viewport( - this.graphics, - viewport - ); - } else { - return viewport; - } - }.bind(this)); + this.viewports = this.viewports.reduce( + function(result, viewport) { + + if (viewport instanceof R3.D3.API.Viewport) { + viewport = R3.Component.ConstructFromObject(viewport); + } + + result.push(viewport); + + return result; + }, + [] + ); + + if (this.composer instanceof R3.D3.API.Composer) { + this.composer = R3.Component.ConstructFromObject(this.composer); + } + + if (this.effect instanceof R3.D3.API.Effect) { + this.effect = R3.Component.ConstructFromObject(this.effect); + } R3.Renderer.call( this, @@ -131,8 +146,6 @@ R3.Renderer.D3.prototype.createInstance = function() { this.instance.setPixelRatio(window.devicePixelRatio); - this.updateInstance('width'); - this.instance.autoClear = this.autoClear; this.instance.autoClearColor = this.autoClearColor; this.instance.autoClearDepth = this.autoClearDepth; @@ -201,15 +214,6 @@ R3.Renderer.D3.prototype.updateInstance = function(property) { throw new Error('no renderer instance'); } - if ( - property === 'width' || - property === 'height' - ) { - var size = R3.Utils.GetWindowSize(); - this.instance.setSize(size.width, size.height, false); - return; - } - if (property === 'renderMode') { console.log('render mode change'); return; @@ -421,29 +425,6 @@ R3.Renderer.D3.prototype.clear = function() { return this.instance.clear(); }; -/** - * Convenience function to set size - * @param width - * @param height - */ -R3.Renderer.D3.prototype.setSize = function(width, height) { - - this.instance.setSize( - this.width * width, - this.height * height, - false - ); - - //this.instance.setPixelRatio(window.devicePixelRatio); -}; - -/** - * Convenience function to get size - * @returns {{width, height}} - */ -R3.Renderer.D3.prototype.getSize = function() { - return this.instance.getSize(); -}; /** * Convenience function to set viewport diff --git a/src/r3-server.js b/src/r3-server.js index 3dfefa2..4d88379 100644 --- a/src/r3-server.js +++ b/src/r3-server.js @@ -23,7 +23,7 @@ R3.Server = function( apiServer.preferIp, apiServer.port, apiServer.protocols, - apiServer.parentEntity + apiServer.parent ); this.connected = false; @@ -98,7 +98,7 @@ R3.Server.prototype.toApiObject = function() { this.preferIp, this.port, this.protocols, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-socket-0.js b/src/r3-socket-0.js index 92598af..453ae61 100644 --- a/src/r3-socket-0.js +++ b/src/r3-socket-0.js @@ -25,7 +25,7 @@ R3.Socket = function( apiSocket.roomId, apiSocket.peerId, apiSocket.server, - apiSocket.parentEntity + apiSocket.parent ); if (this.server instanceof R3.API.Server) { @@ -64,12 +64,12 @@ R3.Socket.prototype.createInstance = function() { this.instance = new WebSocket(this.server.getURL()); // Connection opened - this.instance.addEventListener('open', function (event) { + this.instance.addEventListener('open', function(event) { this.instance.send('Hello Server!'); }.bind(this)); // Listen for messages - this.instance.addEventListener('message', function (event) { + this.instance.addEventListener('message', function(event) { console.log('Message from server ', event.data); }); @@ -112,6 +112,6 @@ R3.Socket.prototype.toApiObject = function() { this.roomId, this.peerId, R3.Utils.IdOrNull(this.server), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-sphere.js b/src/r3-sphere.js index 4e40e69..19e296f 100644 --- a/src/r3-sphere.js +++ b/src/r3-sphere.js @@ -5,7 +5,7 @@ * @param parentObject * @constructor */ -R3.Sphere = function ( +R3.Sphere = function( implementation, apiSphere, parentObject diff --git a/src/r3-stats.js b/src/r3-stats.js index 6152df2..875e3f8 100644 --- a/src/r3-stats.js +++ b/src/r3-stats.js @@ -20,7 +20,7 @@ R3.Stats = function( apiStats.id, apiStats.name, apiStats.domElement, - apiStats.parentEntity + apiStats.parent ); R3.Component.call( @@ -66,7 +66,7 @@ R3.Stats.prototype.toApiObject = function() { this.id, this.name, R3.Utils.IdOrNull(this.domElement), - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-system-0.js b/src/r3-system-0.js index a5b3657..0fac28b 100644 --- a/src/r3-system-0.js +++ b/src/r3-system-0.js @@ -16,7 +16,7 @@ R3.System = function( apiSystem.id, apiSystem.name, apiSystem.systemType, - apiSystem.parentEntity + apiSystem.parent ); this.started = false; @@ -93,7 +93,7 @@ R3.System.prototype.toApiObject = function() { this.id, this.name, this.systemType, - R3.Utils.IdOrNull(this.parentEntity) + R3.Utils.IdOrNull(this.parent) ); }; diff --git a/src/r3-system-animation.js b/src/r3-system-animation.js index c5d7455..808cfa3 100644 --- a/src/r3-system-animation.js +++ b/src/r3-system-animation.js @@ -796,11 +796,11 @@ R3.System.Animation.prototype.detachAnimation = function(mesh) { // // storedValues : [] // }; // -// var getIntermediateAngle = function () { +// var getIntermediateAngle = function() { // return mesh.animationObject.intermediateAngle; // }; // -// var getTargetAngle = function () { +// var getTargetAngle = function() { // // // if (mesh.animationObject.storedValues.length > 0) { // // return mesh.animationObject.storedValues[mesh.animationObject.storedValues.length - 1]; @@ -809,7 +809,7 @@ R3.System.Animation.prototype.detachAnimation = function(mesh) { // return mesh.animationObject.targetAngle; // }; // -// var animateRotation = function (value) { +// var animateRotation = function(value) { // // mesh.animationObject.intermediateAngle += value; // diff --git a/src/r3-system-gui.js b/src/r3-system-gui.js index 1f226f7..bec92b0 100644 --- a/src/r3-system-gui.js +++ b/src/r3-system-gui.js @@ -558,7 +558,7 @@ R3.System.GUI.prototype.buildParentSelectionControl = function(folder, component }.bind(this) ); - if (property === 'parentEntity') { + if (property === 'parent') { R3.Event.Emit( R3.Event.BUILD_GUI, null @@ -635,9 +635,9 @@ R3.System.GUI.prototype.buildArrayManagerControl = function( var activeSelection = { component: null, - add: function () { + add: function() { - componentTemplate.affected.map(function (component) { + componentTemplate.affected.map(function(component) { //if (component[property].indexOf(activeSelection.component) === -1) { component[property].push(activeSelection.component); @@ -700,7 +700,7 @@ R3.System.GUI.prototype.buildUVManagerControl = function( var onChange = function(__uvSet, __uvIndex, __property) { return function(value) { componentTemplate.affected.map( - function (component) { + function(component) { component.uvs[__uvSet][__uvIndex][__property] = value; component.updateInstance('uvs', __uvSet, __uvIndex); } @@ -832,7 +832,7 @@ R3.System.GUI.prototype.buildSelectControl = function(folder, componentTemplate, options ).name(property).listen().onChange( - function (value) { + function(value) { var newComponent = null; @@ -946,8 +946,8 @@ R3.System.GUI.prototype.buildControl = function(folder, componentTemplate, prope object, property, { - 'in game' : R3.API.RenderConfiguration.DEFAULT_MODE_IN_GAME, - 'edit' : R3.API.RenderConfiguration.DEFAULT_MODE_EDIT + 'run' : R3.API.Project.APPLICATION_MODE_RUN, + 'edit' : R3.API.Project.APPLICATION_MODE_EDIT } ) ); @@ -999,18 +999,6 @@ R3.System.GUI.prototype.buildControl = function(folder, componentTemplate, prope } ) ); - } else if (property === 'renderMode') { - controllers.push( - folder.add( - object, - property, - { - 'canvas': R3.API.Renderer.MODE_CANVAS, - 'target': R3.API.Renderer.MODE_TARGET, - 'canvas and target': R3.API.Renderer.MODE_CANVAS_AND_TARGET - } - ) - ); } else if (property === 'drawMode') { controllers.push( folder.add( @@ -1735,7 +1723,7 @@ R3.System.GUI.prototype.buildControl = function(folder, componentTemplate, prope ); } else { controller.onChange( - function (value) { + function(value) { if (typeof this.initialValue === 'number') { value = Number(value); @@ -1907,7 +1895,7 @@ R3.System.GUI.prototype.buildGUI = function(data) { * We first remove everything which is not a Mesh */ this.components = this.components.filter( - function (component) { + function(component) { return (component instanceof R3.D3.Mesh); } ); @@ -2045,9 +2033,9 @@ R3.System.GUI.prototype.buildGUI = function(data) { var templateObject = { template : { /** - * Doing this here is just to put parentEntity at the top of the gui + * Doing this here is just to put parent at the top of the gui */ - 'parentEntity' : componentGroup.components[0].parentEntity + 'parent' : componentGroup.components[0].parent }, affected : [componentGroup.components[0]], componentType : componentGroup.componentType diff --git a/src/r3-system-input.js b/src/r3-system-input.js index 73439e6..f1baa51 100644 --- a/src/r3-system-input.js +++ b/src/r3-system-input.js @@ -70,7 +70,6 @@ R3.System.Input = function( this.mouseWheelEdit = this.onMouseWheelEdit.bind(this); this.mouseUpEdit = this.onMouseUpEdit.bind(this); - this.delayedInstanceEncounteredSubscription = null; this.instanceCreatedSubscription = null; this.removeComponentSubscription = null; this.canvasChangeSubscription = null; @@ -222,11 +221,6 @@ R3.System.Input.prototype.start = function() { this.removeComponent.bind(this) ); - this.delayedInstanceEncounteredSubscription = R3.Event.Subscribe( - R3.Event.DELAYED_INSTANCE_ENCOUNTERED, - this.delayedInstanceEncountered.bind(this) - ); - this.canvasChangeSubscription = R3.Event.Subscribe( R3.Event.CANVAS_CHANGE, this.canvasChange.bind(this) @@ -274,8 +268,6 @@ R3.System.Input.prototype.stop = function() { this.removeComponentSubscription.remove(); - this.delayedInstanceEncounteredSubscription.remove(); - this.canvasChangeSubscription.remove(); this.selectionModeChangeSubscription.remove(); @@ -374,7 +366,7 @@ R3.System.Input.prototype.beforeRender = function(data) { ); this.orbitControls.map( - function (control) { + function(control) { if (control && control.instance) { control.instance.update(data.delta); } @@ -555,48 +547,6 @@ R3.System.Input.prototype.removeComponent = function(data) { }; -/** - * Delayed Instance - we need to check if editControls will block the loading process (since only one will be created) - * @param data - */ -R3.System.Input.prototype.delayedInstanceEncountered = function(data) { - - if (data.component instanceof R3.Controls.D3.Editor) { - - if (this.editorControls.indexOf(data.component) !== -1) { - console.warn('Editor controls already registered'); - return; - } - - this.editorControls.push(data.component); - this.setMode(); - } - - - if (data.component instanceof R3.Controls.D3.FirstPerson) { - - if (this.firstPersonControls.indexOf(data.component) !== -1) { - console.warn('First Person Controls already registered'); - return; - } - - this.firstPersonControls.push(data.component); - this.setMode(); - } - - if (data.component instanceof R3.Controls.D3.Orbit) { - - if (this.orbitControls.indexOf(data.component) !== -1) { - console.warn('Orbit Controls already registered'); - return; - } - - this.orbitControls.push(data.component); - this.setMode(); - } - -}; - R3.System.Input.prototype.registerTouchControl = function(touchControl) { if (!touchControl.canvas || !touchControl.canvas.instance) { @@ -1024,7 +974,7 @@ R3.System.Input.prototype.onTouchStart = function(event) { ) }; -R3.System.Input.prototype.onTouchMove = function (event) { +R3.System.Input.prototype.onTouchMove = function(event) { this.sensitivityCounter++; @@ -1240,7 +1190,7 @@ R3.System.Input.prototype.onKeyDownEdit = function(event) { meshes = R3.EntityManager.Instance.queryComponentsByConstructor(R3.D3.Mesh); - meshes.map(function (mesh) { + meshes.map(function(mesh) { if (this.selectAll) { this.selectMesh(mesh); } else { @@ -1356,7 +1306,7 @@ R3.System.Input.prototype.onMouseDownEdit = function(event) { var intersects = scenes.reduce( - function (result, scene) { + function(result, scene) { this.raycaster.setFromCamera( this.mouse, @@ -1364,13 +1314,13 @@ R3.System.Input.prototype.onMouseDownEdit = function(event) { ); this.raycaster.getIntersectedObjects(scene.meshes).map( - function (intersect) { + function(intersect) { result.push(intersect); } ); this.raycaster.getIntersectedObjects(scene.clones).map( - function (intersect) { + function(intersect) { result.push(intersect); } ); @@ -1388,7 +1338,7 @@ R3.System.Input.prototype.onMouseDownEdit = function(event) { * Find the closest intersected mesh */ intersects.sort( - function (a, b) { + function(a, b) { if (a.distance < b.distance) { return -1; } diff --git a/src/r3-system-linking.js b/src/r3-system-linking.js index ddd5495..3c1ea0e 100644 --- a/src/r3-system-linking.js +++ b/src/r3-system-linking.js @@ -167,7 +167,7 @@ R3.System.Linking.prototype.link = function(component, data) { var linked = []; - component[property] = component[property].map(function (entry) { + component[property] = component[property].map(function(entry) { if (entry === data.component.id) { linked.push({ @@ -241,7 +241,7 @@ R3.System.Linking.prototype.resolveDependencies = function(data) { */ parentComponents.map( - function (parentComponent) { + function(parentComponent) { /** * Link the parent component to this component @@ -546,8 +546,8 @@ R3.System.Linking.prototype.removeComponent = function(data) { var component = data.component; - if (component.parentEntity instanceof R3.Entity) { - component.parentEntity.removeComponent(component); + if (component.parent instanceof R3.Entity) { + component.parent.removeComponent(component); } if (component instanceof R3.D3.Mesh && @@ -605,6 +605,44 @@ R3.System.Linking.prototype.instanceCloned = function(data) { R3.System.Linking.prototype.instanceCreated = function(data) { + /** + * Texture Linking + */ + if (data.component instanceof R3.D3.Texture) { + + /** + * Link Parent Textures to Canvas Objects + */ + R3.EntityManager.Instance.queryComponents(R3.Component.CANVAS).map( + function(canvas){ + if (canvas.parentTexture === data.component.id) { + canvas.parentTexture = data.component; + } + } + ); + + /** + * Find all Render Targets and see if their textures need updating + */ + R3.EntityManager.Instance.queryComponents(R3.Component.RENDER_TARGET).map( + function(renderTarget) { + if (renderTarget.texture === data.component) { + /** + * We found a render target which has this component as their texture - their instance + * has been updated + */ + if (renderTarget.texture.instance !== renderTarget.instance.texture) { + console.log('updating render target texture instance'); + renderTarget.instance.texture = renderTarget.texture.instance; + } + } + } + ) + } + + /** + * Image Linking + */ if (data.component instanceof R3.Image) { /** * Find all textures which use this image @@ -627,6 +665,19 @@ R3.System.Linking.prototype.instanceCreated = function(data) { } + /** + * Canvas Linking + */ + if (data.component instanceof R3.Canvas) { + R3.EntityManager.Instance.queryComponents(R3.Component.TEXTURE_CANVAS).map( + function(texture){ + if (data.component.parentTexture === texture.id) { + data.component.parentTexture = texture; + } + } + ) + } + /** * Link all scenes */ @@ -649,7 +700,7 @@ R3.System.Linking.prototype.instanceCreated = function(data) { typeof data.component.parentScene === 'string' ) { R3.EntityManager.Instance.queryComponents(R3.Component.SCENE).map( - function (scene) { + function(scene) { if (data.component.parentScene === scene.id) { data.component.parentScene = scene; scene.addObject(data.component); @@ -691,7 +742,7 @@ R3.System.Linking.prototype.instanceCreated = function(data) { typeof data.component.parentMesh === 'string' ) { R3.EntityManager.Instance.queryComponents(R3.Component.MESH).map( - function (mesh) { + function(mesh) { if (data.component.parentMesh === mesh.id) { data.component.parentMesh = mesh; data.component.updateInstance('parentMesh'); @@ -705,7 +756,7 @@ R3.System.Linking.prototype.instanceCreated = function(data) { typeof data.component.parentPhysicsWorld === 'string' ) { R3.EntityManager.Instance.queryComponents(R3.Component.PHYSICS_WORLD).map( - function (world) { + function(world) { if (data.component.parentPhysicsWorld === world.id) { data.component.parentPhysicsWorld = world; @@ -718,6 +769,8 @@ R3.System.Linking.prototype.instanceCreated = function(data) { ); } + + }; R3.System.Linking.prototype.materialTypeChanged = function(data) { diff --git a/src/r3-system-particle.js b/src/r3-system-particle.js index 0afa659..32cc341 100644 --- a/src/r3-system-particle.js +++ b/src/r3-system-particle.js @@ -85,7 +85,7 @@ R3.System.Particle.prototype.instanceCreated = function(data) { */ if (data.component instanceof R3.D3.Particle) { R3.EntityManager.Instance.queryComponents(R3.Component.PARTICLE_ENGINE).map( - function (particleEngine) { + function(particleEngine) { if (data.component.parentParticleEngine === particleEngine.id) { data.component.parentParticleEngine = particleEngine; } diff --git a/src/r3-system-render.js b/src/r3-system-render.js index 2dc801b..3497351 100644 --- a/src/r3-system-render.js +++ b/src/r3-system-render.js @@ -1,7 +1,6 @@ /** * System takes care of updating all the entities (based on their component data) * @param apiSystem R3.API.System - * @param graphicsRuntime * @constructor */ R3.System.Render = function( @@ -53,10 +52,8 @@ R3.System.Render = function( * Subscribe to some important events when this system starts * @type {null} */ - this.excludeFromEnvironmentSubscription = null; + this.excludeFromEnvironmentMapMapSubscription = null; - this.instanceCreatedSubscription = null; - this.removeComponentSubscription = null; this.renderSubscription = null; @@ -69,11 +66,6 @@ R3.System.Render = function( this.statistics = []; - this.excludedFromEnvironment = []; - - /** - * Get a handle on the project(s) - */ this.projects = []; }; @@ -87,16 +79,6 @@ R3.System.Render.prototype.start = function() { R3.System.prototype.start.call(this); - this.excludeFromEnvironmentSubscription = this.subscribe( - R3.Event.EXCLUDE_FROM_ENVIRONMENT, - this.excludeFromEnvironmentUpdate - ); - - this.instanceCreatedSubscription = this.subscribe( - R3.Event.INSTANCE_CREATED, - this.instanceCreated - ); - this.removeComponentSubscription = this.subscribe( R3.Event.REMOVE_COMPONENT, this.removeComponent @@ -124,20 +106,9 @@ R3.System.Render.prototype.start = function() { this.statistics = R3.EntityManager.Instance.queryComponents(R3.Component.STATS); - this.projects = R3.EntityManager.Instance.queryComponents(R3.Component.PROJECT); - - this.excludedFromEnvironment = []; - - R3.EntityManager.Instance.queryComponentsByConstructor(R3.D3.Mesh).map( - function(mesh) { - if (mesh.excludeFromEnvironment) { - this.excludedFromEnvironment.push(mesh); - } - }.bind(this) - ); + this.projects = R3.EntityManager.Instance.queryComponents(R3.Component.PROJECT); this.run(); - }; R3.System.Render.prototype.run = function() { @@ -155,20 +126,11 @@ R3.System.Render.prototype.run = function() { }; -R3.System.Render.prototype.excludeFromEnvironmentUpdate = function (data) { - - if (data.component.excludeFromEnvironment) { - console.log('excluding ' + data.component.name + ' from environment'); - R3.Utils.PushUnique(this.excludedFromEnvironment, data.component); - } else { - var index = this.excludedFromEnvironment.indexOf(data.component); - if (index !== -1) { - this.excludedFromEnvironment.splice(index,1); - } - console.log('including ' + data.component.name + ' in environment'); - } -}; - +/** + * It is assumed that the canvas size represents the 'window size'. + * The R3.Event.WINDOW_RESIZE event data should contain the canvas size (width + height) in pixels + * @param data + */ R3.System.Render.prototype.windowResize = function(data) { R3.Event.Emit( @@ -176,25 +138,60 @@ R3.System.Render.prototype.windowResize = function(data) { data ); - R3.EntityManager.Instance.queryComponentsByConstructor(R3.D3.RenderTarget).map( - function(renderTarget) { - if (renderTarget.autoUpdateSize) { - renderTarget.updateInstance('autoUpdateSize'); - } + /** + * Only resize elements relevant to the current projects + */ + this.projects.map( + function(project) { + project.renderers.map( + function(renderer) { + + /** + * Update renderer size + */ + renderer.instance.setSize(data.width, data.height); + + /** + * TODO: Update render target viewport (if required) + */ + if (renderer.renderTarget) { + console.log('TODO: check if we need to update render targets - imo textures should be left well alone - could be different for viewports') + } + + /** + * Update effects + */ + renderer.effect.setSize(data.width, data.height); + + /** + * Update Composer and passes + */ + renderer.composer.setSize( + data.width, + data.height + ); + + renderer.composer.passes.map( + function(pass) { + pass.setSize( + data.width, + data.height + ) + } + ); + + /** + * Update the renderer canvas size + */ + renderer.canvas.width = data.width; + renderer.canvas.height = data.height; + renderer.canvas.updateInstance('width'); + } + ) } ); - R3.EntityManager.Instance.queryComponentsByConstructor(R3.Renderer).map( - function(renderer) { - renderer.setSize(data.width, data.height); - } - ); - R3.EntityManager.Instance.queryComponentsByConstructor(R3.D3.Effect).map( - function(effect){ - effect.setSize(data.width, data.height); - } - ); R3.EntityManager.Instance.queryComponentsByConstructor(R3.Canvas).map( function(canvas) { @@ -224,47 +221,16 @@ R3.System.Render.prototype.windowResize = function(data) { R3.EntityManager.Instance.queryComponents(R3.Component.COMPOSER).map( function(composer){ - composer.setSize( - data.width, - data.height - ); - composer.passes.map( - function(pass) { - pass.setSize( - data.width, - data.height - ) - } - ) } ); - // R3.EntityManager.Instance.queryComponentsByConstructor(R3.AR).map( - // function(ar) { - // ar.resize(); - // } - // ); - R3.Event.Emit( R3.Event.AFTER_WINDOW_RESIZE, data ); }; -// -// R3.System.Render.prototype.shaderUpdate = function(data) { -// -// this.activeRenderConfiguration.activeScenes.map( -// function(scene){ -// this.activeRenderConfiguration.activeRenderer.instance.compile( -// scene.instance, -// this.activeRenderConfiguration.activeCamera.instance -// ); -// }.bind(this) -// ); -// -// }; R3.System.Render.prototype.textureUpdated = function(data) { @@ -272,7 +238,7 @@ R3.System.Render.prototype.textureUpdated = function(data) { function(material) { material.getTextures().map( - function (object) { + function(object) { if (object.texture === data.texture) { @@ -284,100 +250,11 @@ R3.System.Render.prototype.textureUpdated = function(data) { } ); - } ); }; -/** - * From now on we want to track everything about a component, only from the systems that are active - * @param data - */ -R3.System.Render.prototype.instanceCreated = function(data) { - - // if (data.component instanceof R3.RenderConfiguration) { - // console.log('adding render configuration to render system'); - // this.renderConfigurations.push(data.component); - // - // if (this.renderConfigurations.length === 1) { - // this.activeRenderConfiguration = this.renderConfigurations[0]; - // } - // } - - if (data.component instanceof R3.Renderer) { - console.log('adding renderer to render system'); - this.renderers.push(data.component); - } - - if (data.component instanceof R3.D3.Composer) { - console.log('adding composer to render system'); - this.composers.push(data.component); - } - - if (data.component instanceof R3.Stats) { - this.statistics.push(data.component); - } - - if (data.component instanceof R3.D3.Camera.Cube) { - this.cubeCameras.push(data.component); - } - - // if (data.component instanceof R3.AR) { - // this.arComponents.push(data.component); - // } - - if ( - data.component instanceof R3.D3.Mesh && - data.component.excludeFromEnvironment - ) { - R3.Utils.PushUnique(this.excludedFromEnvironment, data.component); - } - - if (data.component instanceof R3.D3.Texture) { - - /** - * Link Parent Textures to Canvas Objects - */ - R3.EntityManager.Instance.queryComponents(R3.Component.CANVAS).map( - function(canvas){ - if (canvas.parentTexture === data.component.id) { - canvas.parentTexture = data.component; - } - } - ); - - /** - * Find all Render Targets and see if their textures need updating - */ - R3.EntityManager.Instance.queryComponents(R3.Component.RENDER_TARGET).map( - function(renderTarget) { - if (renderTarget.texture === data.component) { - /** - * We found a render target which has this component as their texture - their instance - * has been updated - */ - - if (renderTarget.texture.instance !== renderTarget.instance.texture) { - console.log('updating render target texture instance'); - renderTarget.instance.texture = renderTarget.texture.instance; - } - } - } - ) - } - - if (data.component instanceof R3.Canvas) { - R3.EntityManager.Instance.queryComponents(R3.Component.TEXTURE_CANVAS).map( - function(texture){ - if (data.component.parentTexture === texture.id) { - data.component.parentTexture = texture; - } - } - ) - } -}; - R3.System.Render.prototype.replaceComponent = function(data) { if (data.current instanceof R3.D3.Material) { @@ -582,219 +459,212 @@ R3.System.Render.prototype.removeComponent = function(data) { */ R3.System.Render.prototype.render = function(data) { - if (this.statistics) { - this.statistics.map( - function (statistics) { - statistics.start(); - } - ); - } + this.statistics.map( + function(statistics) { + statistics.start(); + } + ); R3.Event.Emit( R3.Event.BEFORE_RENDER, data ); - // var configuration = this.activeRenderConfiguration; - // - // if (!configuration) { - // return; - // } - // - // var renderer = configuration.activeRenderer; - // - // if (renderer instanceof R3.Renderer.D2) { - // return; - // } + /** + * TODO: implement 2D rendering + */ + if (renderer instanceof R3.Renderer.D2) { + console.log('TODO: implement 2D rendering') + return; + } this.projects.map( function(project) { project.renderers.map( - function (renderer) { + function(renderer) { - var scenes = renderer.scenes; + var scenes = project.scenes; var camera = project.cameras[project.cameraIndex]; var effect = renderer.effect; - var composer = renderer.composer - } - ); - - - - } - ); - - - - var camera = configuration.activeCamera; - - var effect = configuration.activeEffect; - - var composer = configuration.activeComposer; - - if ( - configuration.enableEffect && - (!effect || !effect.instance) - ) { - renderer.clear(); - return; - } - - if ( - configuration.enableComposer && - (!composer || !composer.instance || composer.passes.length === 0) - ) { - renderer.clear(); - return; - } - - if ( - renderer.renderMode === R3.API.Renderer.MODE_TARGET || - renderer.renderMode === R3.API.Renderer.MODE_CANVAS_AND_TARGET - ) { - if (!renderer.renderTarget) { - console.warn('no render renderTarget'); - return; - } - } - - // var arComponent = null; - // - // if (this.arComponents.length > 1) { - // console.warn('only one AR component supported at this time'); - // return; - // } - // - // if (this.arComponents.length === 1) { - // arComponent = this.arComponents[0]; - // } - // - // if (arComponent) { - // arComponent.instance.arScene.process(); - // } - - var resetAutoClear = false; - - if (scenes.length > 1) { - - if (renderer.autoClear) { - resetAutoClear = true; - } - - renderer.autoClear = false; - renderer.updateInstance('autoClear'); - renderer.clear(); - } - - var size = renderer.getSize(); - - renderer.viewports.map( - - function(viewport) { - - renderer.setViewport( - viewport.x * size.width, - viewport.y * size.height, - viewport.width * size.width, - viewport.height * size.height - ); - - /** - * Update any cube camera's based on the scene - */ - this.cubeCameras.map( - function(cubeCamera) { - - this.excludedFromEnvironment.map( - function(mesh){ - mesh.visible = false; - mesh.updateInstance('visible'); - } - ); - - scenes.map( - function(scene) { - cubeCamera.update(renderer, scene); - } - ); - - this.excludedFromEnvironment.map( - function(mesh){ - mesh.visible = true; - mesh.updateInstance('visible'); - } - ); - - }.bind(this) - ); - - if (configuration.enableComposer) { - composer.render(); - return; - } - - scenes.map( - - function (scene) { - - var backupCamera = camera; - - /** - * Scene camera overrides normal camera - */ - if (scene.camera) { - camera = scene.camera; - } - - if (renderer.renderMode === R3.API.Renderer.MODE_TARGET || - renderer.renderMode === R3.API.Renderer.MODE_CANVAS_AND_TARGET) { - - renderer.renderToTarget( - scene, - camera - ) - - } - - if (renderer.renderMode === R3.API.Renderer.MODE_CANVAS || - renderer.renderMode === R3.API.Renderer.MODE_CANVAS_AND_TARGET) { - - if (configuration.enableEffect) { - effect.render(scene, camera); + if ( + renderer.renderMode === R3.API.Renderer.MODE_TARGET || + renderer.renderMode === R3.API.Renderer.MODE_CANVAS_AND_TARGET + ) { + if (!renderer.renderTarget) { + console.warn('no renderTarget'); + renderer.clear(); return; } - - renderer.render(scene, camera); } - camera = backupCamera; + /** + * If this renderer has autoClear set but multiple scenes, we want to render the all the scenes + * first and then restore the autoClear setting, otherwise rendering multiple scenes will result in + * only one scene being rendered. Setting the autoClear setting to false is not an option because + * in this situation all scenes will be renderered continuously (with no clearing in between at all) + * @type {boolean} + */ + var resetAutoClear = false; + if (scenes.length > 1) { - }.bind(this) + if (renderer.autoClear) { + resetAutoClear = true; + } + + renderer.autoClear = false; + renderer.updateInstance('autoClear'); + + renderer.clear(); + } + + /** + * Do the rendering + */ + var size = renderer.getSize(); + renderer.viewports.map( + + function(viewport) { + + renderer.setViewport( + viewport.x * size.width, + viewport.y * size.height, + viewport.width * size.width, + viewport.height * size.height + ); + + var cubeCameras = project.cameras.reduce( + function(result, camera){ + if (camera instanceof R3.D3.Camera.Cube) { + result.push(camera); + } + return result; + }, + [] + ); + + /** + * Update any cube camera's based on the scene + */ + cubeCameras.map( + function(cubeCamera) { + + var meshesExcluded = scene.meshes.reduce( + function(result, mesh){ + if (mesh.excludeFromEnvironmentMapMap) { + result.push(mesh) + } + return result; + }, + [] + ); + + meshesExcluded.map( + function(mesh){ + mesh.visible = false; + mesh.updateInstance('visible'); + } + ); + + scenes.map( + function(scene) { + cubeCamera.update(renderer, scene); + } + ); + + meshesExcluded.map( + function(mesh){ + mesh.visible = true; + mesh.updateInstance('visible'); + } + ); + + }.bind(this) + ); + + if (renderer.enableComposer) { + + if (renderer.composer && renderer.composer.ready()) { + renderer.composer.render(); + } else { + console.log('composer not ready'); + } + + return; + } + + scenes.map( + + function(scene) { + + var backupCamera = camera; + + /** + * Scene camera overrides normal camera + */ + if (scene.camera) { + camera = scene.camera; + } + + if (renderer.renderMode === R3.API.Renderer.MODE_TARGET || + renderer.renderMode === R3.API.Renderer.MODE_CANVAS_AND_TARGET) { + + renderer.renderToTarget( + scene, + camera + ) + + } + + if (renderer.renderMode === R3.API.Renderer.MODE_CANVAS || + renderer.renderMode === R3.API.Renderer.MODE_CANVAS_AND_TARGET) { + + if (renderer.enableEffect) { + + if (renderer.effect && renderer.effect.ready(scene, camera)) { + effect.render(scene, camera); + } else { + console.log('effect not ready'); + } + + return; + } + + renderer.render(scene, camera); + } + + camera = backupCamera; + + }.bind(this) + ); + }.bind(this) + ); + + /** + * Restore the autoClear for the next render loop + */ + if (resetAutoClear) { + renderer.autoClear = true; + renderer.updateInstance('autoClear'); + } + } ); - }.bind(this) + } ); - if (resetAutoClear) { - renderer.autoClear = true; - renderer.updateInstance('autoClear'); - } - R3.Event.Emit( R3.Event.AFTER_RENDER, data ); - if (this.statistics) { - this.statistics.map( - function (statistics) { - statistics.end(); - } - ); - } + this.statistics.map( + function(statistics) { + statistics.end(); + } + ); }; /** @@ -806,7 +676,7 @@ R3.System.Render.prototype.stop = function() { cancelAnimationFrame(this.animationFrameHook); - this.excludeFromEnvironmentSubscription.remove(); + this.excludeFromEnvironmentMapMapSubscription.remove(); this.instanceCreatedSubscription.remove(); diff --git a/src/r3-system-storage.js b/src/r3-system-storage.js index d628231..e455554 100644 --- a/src/r3-system-storage.js +++ b/src/r3-system-storage.js @@ -127,7 +127,7 @@ R3.System.Storage.prototype.start = function() { R3.System.Storage.prototype.delete = function(data) { - this.publish( + this.emit( R3.Event.GET_API_URL, null, function(urlData) { @@ -150,7 +150,7 @@ R3.System.Storage.prototype.delete = function(data) { xhr.setRequestHeader("Content-Type", "application/json"); xhr.setRequestHeader("x-authorization", urlData.passwoid); - xhr.onreadystatechange = function () { + xhr.onreadystatechange = function() { if (this.readyState === 4) { try { var response = JSON.parse(this.responseText) @@ -208,7 +208,7 @@ R3.System.Storage.prototype.save = function(data) { event = R3.Event.GET_REMOTE_API_URL } - this.publish( + this.emit( event, null, function(urlData) { @@ -228,7 +228,7 @@ R3.System.Storage.prototype.save = function(data) { xhr.setRequestHeader("Content-Type", "application/json"); xhr.setRequestHeader("x-authorization", urlData.passwoid); - xhr.onreadystatechange = function () { + xhr.onreadystatechange = function() { if (this.readyState === 4) { try { var response = JSON.parse(this.responseText) @@ -331,6 +331,10 @@ R3.System.Storage.prototype.createRuntimeObject = function(responseText, clientE R3.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, includeDependencies, clientCallback, clientErrorCallback) { + /** + * TODO: ensure parents of this component are loaded first + */ + /** * We just do an initial check if these components to process are already in the register - * if so we remove them since we probably want to overwrite them with stale DB versions. @@ -359,7 +363,7 @@ R3.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, includeD xhr.onload = function(__system) { - return function () { + return function() { var runtimeComponent = __system.createRuntimeObject.bind(__system)(this.responseText); @@ -369,13 +373,13 @@ R3.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, includeD } if ( - runtimeComponent.parentEntity && - typeof runtimeComponent.parentEntity === 'string' + runtimeComponent.parent && + typeof runtimeComponent.parent === 'string' ) { R3.EntityManager.Instance.queryComponents(R3.Component.ENTITY).map( - function (entity) { - if (runtimeComponent.parentEntity === entity.id) { - runtimeComponent.parentEntity = entity; + function(entity) { + if (runtimeComponent.parent === entity.id) { + runtimeComponent.parent = entity; } } ); @@ -441,7 +445,7 @@ R3.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, includeD */ dependencies = dependencies.reduce( - function (result, dependency) { + function(result, dependency) { if (R3.EntityManager.Instance.findComponentById(dependency)) { /** @@ -460,7 +464,7 @@ R3.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, includeD * Also check if this dependency is not already in our loaded */ dependencies = dependencies.reduce( - function (result, dependency) { + function(result, dependency) { if (__system.loaded.indexOf(dependency) === -1) { result.push(dependency); @@ -475,7 +479,7 @@ R3.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, includeD * We should now check our 'loading' list and add all dependencies which are not already in there */ dependencies.map( - function (dependency) { + function(dependency) { R3.Utils.PushUnique(__system.loading, dependency); } ); @@ -518,7 +522,7 @@ R3.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, includeD }(this); xhr.onerror = function(__id) { - return function (error) { + return function(error) { console.warn('component load failed for component ID ' + __id); if (clientErrorCallback) { @@ -547,7 +551,7 @@ R3.System.Storage.prototype.loadComponent = function(apiUrl, toProcess, includeD */ R3.System.Storage.prototype.load = function(data, clientCallback, clientErrorCallback) { - this.publish( + this.emit( R3.Event.GET_API_URL, null, function(urlData) { @@ -776,7 +780,7 @@ R3.System.Storage.prototype.loadFont = function(data, callback, errorCallback) { console.log('loading font : ' + data.font.name); - this.publish( + this.emit( R3.Event.GET_API_URL, null, function(urlData) { @@ -787,7 +791,7 @@ R3.System.Storage.prototype.loadFont = function(data, callback, errorCallback) { loader.load( url, - function ( font ) { + function( font ) { if (R3.Utils.IsEmpty(font.data)) { @@ -814,7 +818,7 @@ R3.System.Storage.prototype.loadImage = function(data, callback, errorCallback) console.log('loading image : ' + data.image.name); - this.publish( + this.emit( R3.Event.GET_API_URL, null, function(urlData) { diff --git a/src/r3-user.js b/src/r3-user.js index 72e34f5..ff8c03f 100644 --- a/src/r3-user.js +++ b/src/r3-user.js @@ -15,7 +15,7 @@ R3.User = function( this, apiUser.id, apiUser.name, - apiUser.parentEntity, + apiUser.parent, apiUser.googleId, apiUser.fullName, apiUser.givenName, @@ -90,7 +90,7 @@ R3.User.prototype.toApiObject = function() { return new R3.API.User( this.id, this.name, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), this.googleId, this.fullName, this.givenName, diff --git a/src/r3-vector2.js b/src/r3-vector2.js index ca0a6e8..fb0132e 100644 --- a/src/r3-vector2.js +++ b/src/r3-vector2.js @@ -1,38 +1,41 @@ /** * Runtime vector2 for updating instance objects - * @param graphics R3.GraphicsRuntime - * @param parentObject R3.D3.* - * @param apiVector2 R3.API.Vector2 - * @param grain Number * @constructor + * @param parent + * @param apiVector2 */ -R3.Vector2 = function ( - graphics, - apiVector2, - parentObject, - grain +R3.Vector2 = function( + parent, + apiVector2 ) { - this.graphics = graphics; + if (R3.Utils.UndefinedOrNull(parent)) { + parent = null; + } + this.parent = parent; if (R3.Utils.UndefinedOrNull(apiVector2)) { apiVector2 = {}; } + this.apiVector2 = apiVector2; - R3.API.Vector2.call( + R3.API.Vector2.call( this, apiVector2.x, apiVector2.y ); - if (R3.Utils.UndefinedOrNull(parentObject)) { - parentObject = null; - } - this.parentObject = parentObject; + this.graphics = null; + this.physics = null; - if (R3.Utils.UndefinedOrNull(grain)) { - grain = 0.001; - } - this.grain = grain; + R3.Event.Emit( + R3.Event.GET_RUNTIME, + function(runtime) { + this.graphics = runtime.graphics; + this.physics = runtime.physics; + }.bind(this) + ); + + this.componentRuntime = R3.Component.GetComponentRuntime(parent); this.createInstance(); }; @@ -40,17 +43,27 @@ R3.Vector2 = function ( R3.Vector2.prototype = Object.create(R3.API.Vector2.prototype); R3.Vector2.prototype.constructor = R3.Vector2; - /** * Creates an instance vector2 * @returns {*} */ R3.Vector2.prototype.createInstance = function() { - if (this.graphics && this.graphics.isThree()) { - this.instance = new THREE.Vector2(this.x, this.y); - } else { - this.instance = this; + switch (this.componentRuntime) { + case R3.Component.GRAPHICS_RUNTIME : + this.instance = this.graphics.Vector2( + this.x, + this.y + ); + break; + case R3.Component.PHYSICS_RUNTIME : + this.instance = this.physics.Vector3( + this.x, + this.y + ); + break; + default: + throw new Error('unhandled component runtime: ' + this.componentRuntime); } }; @@ -60,13 +73,14 @@ R3.Vector2.prototype.createInstance = function() { */ R3.Vector2.prototype.updateInstance = function(property) { - this.instance.x = this.x; - this.instance.y = this.y; - - if (this.parentObject && - this.parentObject.updateInstance) { - this.parentObject.updateInstance(property); + if (property === 'x') { + this.instance.x = this.x; } + + if (property === 'y') { + this.instance.y = this.y; + } + }; /** @@ -77,7 +91,7 @@ R3.Vector2.prototype.toApiObject = function() { return new R3.API.Vector2( this.x, this.y - ); + ) }; /** @@ -86,206 +100,12 @@ R3.Vector2.prototype.toApiObject = function() { * @param v optional * @returns {R3.Vector2} */ -R3.Vector2.prototype.copy = function (v) { +R3.Vector2.prototype.clone = function(v) { - if (R3.Utils.UndefinedOrNull(v)) { - - return new R3.Vector2( - this.graphics, - new R3.API.Vector2( - this.x, - this.y - ), - this.parentObject, - this.grain - ); - - } else { - - this.x = v.x; - this.y = v.y; - - return this; - } -}; - -/** - * Equals - * TODO: Test - * @param v - * @returns {boolean} - */ -R3.Vector2.prototype.equals = function(v) { - - if ((this.x == v.x) && - (this.y == v.y)) { - return true; - } else { - return false; - } - -}; - -/** - * Add - * TODO: Test - * @param v - */ -R3.Vector2.prototype.add = function(v) { - - if ( - v instanceof R3.API.Vector2 || - v instanceof R3.API.Vector3 || - v instanceof R3.API.Vector4 || - v instanceof R3.API.Quaternion - ) { - this.x += v.x; - this.y += v.y; - } else { - console.warn('Could not add Vector2'); - throw new Error('Could not add Vector2'); - } - -}; - -/** - * Subtract - * TODO: Test - * @param v - */ -R3.Vector2.prototype.subtract = function(v) { - - if ( - v instanceof R3.API.Vector2 || - v instanceof R3.API.Vector3 || - v instanceof R3.API.Vector4 || - v instanceof R3.API.Quaternion - ) { - this.x -= v.x; - this.y -= v.y; - } else { - console.warn('Could not subtract Vector2'); - throw new Error('Could not subtract Vector2'); - } - -}; - -/** - * Multiply - * TODO: Test - * @param v - */ -R3.Vector2.prototype.multiply = function(v) { - - if ( - v instanceof R3.API.Vector2 || - v instanceof R3.API.Vector3 || - v instanceof R3.API.Vector4 || - v instanceof R3.API.Quaternion - ) { - this.x *= v.x; - this.y *= v.y; - } else if (typeof v == 'number') { - this.x *= v; - this.y *= v; - } else { - console.warn('Could not multiply Vector2'); - throw new Error('Could not multiply Vector2'); - } - -}; - -/** - * Divide - * TODO: Test - * @param v - */ -R3.Vector2.prototype.divide = function(v) { - - if ( - v instanceof R3.API.Vector2 || - v instanceof R3.API.Vector3 || - v instanceof R3.API.Vector4 || - v instanceof R3.API.Quaternion - ) { - this.x *= (1.0 / v.x); - this.y *= (1.0 / v.y); - } else if (typeof v == 'number') { - this.x *= 1.0 / v; - this.y *= 1.0 / v; - } else { - console.warn('Could not divide Vector2'); - throw new Error('Could not divide Vector2'); - } - -}; - -/** - * Clamp - * TODO: Test - * @param min R3.API.Vector2 - * @param max R3.API.Vector2 - * @returns {R3.Vector2} - */ -R3.Vector2.prototype.clamp = function(min, max) { - - this.x = Math.max(min.x, Math.min(max.x, this.x)); - this.y = Math.max(min.y, Math.min(max.y, this.y)); - - return this; - -}; - -/** - * Length - * TODO: Test - * @returns {number} - */ -R3.Vector2.prototype.length = function() { - return Math.sqrt( - this.x * this.x + this.y * this.y - ); -}; - -/** - * Dot product - * TODO: Test - * @param v - * @returns {number} - */ -R3.Vector2.prototype.dot = function(v) { - return this.x * v.x + this.y * v.y; -}; - -/** - * Normalize - * TODO: Test - */ -R3.Vector2.prototype.normalize = function() { - return this.multiply(1.0 / this.length()); -}; - -/** - * TODO: Test - * Angle between this vector and origin - * @returns {number} - */ -R3.Vector2.prototype.angle = function() { - var angle = Math.atan2(this.y, this.x); - if ( angle < 0 ) angle += 2 * Math.PI; - return angle; -}; - -/** - * Interpolate to v from here - * TODO: Test - * @param v - * @param alpha - * @returns {R3.Vector2} - */ -R3.Vector2.prototype.lerp = function ( v, alpha ) { return new R3.Vector2( - this.x + ( v.x - this.x ) * alpha, - this.y + ( v.y - this.y ) * alpha + this.parent, + this.x, + this.y ); -}; \ No newline at end of file + +}; diff --git a/src/r3-vector3.js b/src/r3-vector3.js index cdff564..2cf71d3 100644 --- a/src/r3-vector3.js +++ b/src/r3-vector3.js @@ -1,67 +1,43 @@ /** - * Runtime apiVector3 for updating instance objects - * @param implementation R3.GraphicsRuntime - * @param apiVector3 R3.API.Vector3 - * @param parentObject R3.* - * @param grain Number - * @param min - * @param max + * R3.Vector3 + * @param parent + * @param apiVector * @constructor */ -R3.Vector3 = function ( - implementation, - apiVector3, - parentObject, - grain, - min, - max +R3.Vector3 = function( + parent, + apiVector ) { - this.implementation = implementation; - - if (implementation instanceof R3.GraphicsRuntime) { - this.physics = null; - this.graphics = implementation; - this.graphics.isNotThreeThrow(); - } else if (implementation instanceof R3.PhysicsRuntime) { - this.graphics = null; - this.physics = implementation; - this.physics.isNotCannonThrow(); - } else { - throw new Error('Unhandled implementation : ' + implementation); + if (R3.Utils.UndefinedOrNull(parent)) { + parent = null; } + this.parent = parent; - if (R3.Utils.UndefinedOrNull(apiVector3)) { - apiVector3 = {}; + if (R3.Utils.UndefinedOrNull(apiVector)) { + apiVector = {}; } + this.apiVector = apiVector; - R3.API.Vector3.call( + R3.API.Vector3.call( this, - apiVector3.x, - apiVector3.y, - apiVector3.z + apiVector.x, + apiVector.y, + apiVector.z ); - if (R3.Utils.UndefinedOrNull(parentObject)) { - parentObject = this; - } - this.parentObject = parentObject; + this.graphics = null; + this.physics = null; - if (R3.Utils.UndefinedOrNull(grain)) { - grain = 0.001; - } - this.grain = grain; - - if (R3.Utils.UndefinedOrNull(min)) { - min = 0; - } - this.min = min; - - if (R3.Utils.UndefinedOrNull(max)) { - max = 1; - } - this.max = max; + R3.Event.Emit( + R3.Event.GET_RUNTIME, + function(runtime) { + this.graphics = runtime.graphics; + this.physics = runtime.physics; + }.bind(this) + ); + this.componentRuntime = R3.Component.GetComponentRuntime(parent); this.createInstance(); }; @@ -75,37 +51,43 @@ R3.Vector3.prototype.constructor = R3.Vector3; */ R3.Vector3.prototype.createInstance = function() { - if (this.graphics) { - this.instance = new THREE.Vector3( - this.x, - this.y, - this.z - ); - } else if (this.physics) { - this.instance = new CANNON.Vec3( - this.x, - this.y, - this.z - ) + switch (this.componentRuntime) { + case R3.Component.GRAPHICS_RUNTIME : + this.instance = this.graphics.Vector3( + this.x, + this.y, + this.z + ); + break; + case R3.Component.PHYSICS_RUNTIME : + this.instance = this.physics.Vector3( + this.x, + this.y, + this.z + ); + break; + default: + throw new Error('unhandled component runtime: ' + this.componentRuntime); } - }; /** * Updates the instance vector, calls updateInstance on the parent object */ -R3.Vector3.prototype.updateInstance = function(property, preventParentUpdate) { +R3.Vector3.prototype.updateInstance = function(property) { - this.instance.x = this.x; - this.instance.y = this.y; - this.instance.z = this.z; - - if (!preventParentUpdate && - this.parentObject && - this.parentObject !== this && - this.parentObject.updateInstance) { - this.parentObject.updateInstance(property); + if (property === 'x') { + this.instance.x = this.x; } + + if (property === 'y') { + this.instance.y = this.y; + } + + if (property === 'z') { + this.instance.z = this.z; + } + }; /** @@ -120,31 +102,15 @@ R3.Vector3.prototype.toApiObject = function() { }; /** - * Creates a new copy of this Vector3 + * Clones this vector + * @returns {R3.Vector3|R3.Vector3|R3.Vector3} */ -R3.Vector3.prototype.copy = function() { - return new R3.Vector3( - this.implementation, - new R3.API.Vector3( - this.x, - this.y, - this.z - ), - this.parentObject, - this.grain - ) -}; - R3.Vector3.prototype.clone = function() { return new R3.Vector3( - this.implementation, - new R3.API.Vector3( - this.x, - this.y, - this.z - ), - this.parentObject, - this.grain + this.parent, + this.x, + this.y, + this.z ) }; @@ -154,14 +120,10 @@ R3.Vector3.prototype.clone = function() { */ R3.Vector3.prototype.negativeCopy = function() { return new R3.Vector3( - this.implementation, - new R3.API.Vector3( - -this.x, - -this.y, - -this.z - ), - this.parentObject, - this.grain + this.parent, + -this.x, + -this.y, + -this.z ) }; @@ -184,10 +146,5 @@ R3.Vector3.prototype.applyAxisAngle = function(axis, angle) { this.x = this.instance.x; this.y = this.instance.y; this.z = this.instance.z; -}; - -R3.Vector3.prototype.setFrom = function(vector3) { - this.x = vector3.x; - this.y = vector3.y; - this.z = vector3.z; -}; + return this; +}; \ No newline at end of file diff --git a/src/r3-vector4.js b/src/r3-vector4.js index 36e319a..6815c4c 100644 --- a/src/r3-vector4.js +++ b/src/r3-vector4.js @@ -1,26 +1,25 @@ /** * Runtime apiVector4 for updating instance objects - * @param graphics R3.GraphicsRuntime - * @param apiVector4 R3.API.Vector4 - * @param parentObject R3.* - * @param grain Number * @constructor + * @param parent + * @param apiVector4 */ -R3.Vector4 = function ( - graphics, - apiVector4, - parentObject, - grain +R3.Vector4 = function( + parent, + apiVector4 ) { - this.graphics = graphics; - this.graphics.isNotThreeThrow(); + if (R3.Utils.UndefinedOrNull(parent)) { + parent = null; + } + this.parent = parent; if (R3.Utils.UndefinedOrNull(apiVector4)) { apiVector4 = {}; } + this.apiVector4 = apiVector4; - R3.API.Vector4.call( + R3.API.Vector4.call( this, apiVector4.x, apiVector4.y, @@ -28,15 +27,18 @@ R3.Vector4 = function ( apiVector4.w ); - if (R3.Utils.UndefinedOrNull(parentObject)) { - parentObject = null; - } - this.parentObject = parentObject; + this.graphics = null; + this.physics = null; - if (R3.Utils.UndefinedOrNull(grain)) { - grain = 0.001; - } - this.grain = grain; + R3.Event.Emit( + R3.Event.GET_RUNTIME, + function(runtime) { + this.graphics = runtime.graphics; + this.physics = runtime.physics; + }.bind(this) + ); + + this.componentRuntime = R3.Component.GetComponentRuntime(parent); this.createInstance(); }; @@ -49,12 +51,26 @@ R3.Vector4.prototype.constructor = R3.Vector4; * @returns {*} */ R3.Vector4.prototype.createInstance = function() { - this.instance = new THREE.Quaternion( - this.x, - this.y, - this.z, - this.w - ); + switch (this.componentRuntime) { + case R3.Component.GRAPHICS_RUNTIME : + this.instance = this.graphics.Vector4( + this.x, + this.y, + this.z, + this.w + ); + break; + case R3.Component.PHYSICS_RUNTIME : + this.instance = this.physics.Vector4( + this.x, + this.y, + this.z, + this.w + ); + break; + default: + throw new Error('unhandled component runtime: ' + this.componentRuntime); + } }; /** @@ -62,14 +78,20 @@ R3.Vector4.prototype.createInstance = function() { */ R3.Vector4.prototype.updateInstance = function(property) { - this.instance.x = this.x; - this.instance.y = this.y; - this.instance.z = this.z; - this.instance.w = this.w; + if (property === 'x') { + this.instance.x = this.x; + } - if (this.parentObject && - this.parentObject.updateInstance) { - this.parentObject.updateInstance(property); + if (property === 'y') { + this.instance.y = this.y; + } + + if (property === 'z') { + this.instance.z = this.z; + } + + if (property === 'w') { + this.instance.w = this.w; } }; @@ -77,10 +99,10 @@ R3.Vector4.prototype.updateInstance = function(property) { * Converts runtime vector to API Vector */ R3.Vector4.prototype.toApiObject = function() { - return new R3.API.Vector4( - this.x, - this.y, - this.z, - this.w - ); + return { + x : this.x, + y : this.y, + z : this.z, + w : this.w + } }; diff --git a/src/r3-video.js b/src/r3-video.js index 6263d8c..9e0bb16 100644 --- a/src/r3-video.js +++ b/src/r3-video.js @@ -19,7 +19,7 @@ R3.Video = function( this, apiVideo.id, apiVideo.name, - apiVideo.parentEntity, + apiVideo.parent, apiVideo.autoUpdateSize, apiVideo.width, apiVideo.height, @@ -152,7 +152,7 @@ R3.Video.prototype.toApiObject = function() { return new R3.API.Video( this.id, this.name, - R3.Utils.IdOrNull(this.parentEntity), + R3.Utils.IdOrNull(this.parent), this.autoUpdateSize, this.width, this.height,