From 567b6b9f387504a450dc2570be2eed27793a3954 Mon Sep 17 00:00:00 2001 From: cybafelo Date: Wed, 24 Jul 2019 14:45:42 +0200 Subject: [PATCH] done with API classes --- gulpfile.js | 142 ++++++- src/r3-a-3-api-component.js | 83 +++- src/r3-a-4-component-a.js | 13 +- src/r3-api-controls-0.js | 52 +-- src/r3-api-controls-d3.js | 14 +- src/r3-api-controls-keyboard.js | 4 +- src/r3-api-controls-mouse.js | 4 +- src/r3-api-controls-touch.js | 4 +- src/r3-api-curve-a.js | 73 +--- src/r3-api-curve-path-a.js | 22 +- src/r3-api-curve-path-d2-a.js | 21 +- src/r3-api-curve-path-d2-shape.js | 8 +- src/r3-api-custom-code.js | 27 +- src/r3-api-dom-element.js | 40 +- src/r3-api-draw-range.js | 22 +- src/r3-api-entity-manager.js | 54 +-- src/r3-api-entity.js | 46 +-- src/r3-api-group.js | 23 +- src/r3-api-gui.js | 51 +-- src/r3-api-image.js | 29 +- src/r3-api-matrix4.js | 27 -- src/r3-api-mouse.js | 24 +- src/r3-api-plane.js | 43 +- src/r3-api-project.js | 25 +- src/r3-api-quaternion-points.js | 4 + src/r3-api-renderer-a.js | 81 +--- src/r3-api-renderer-d2.js | 16 +- src/r3-api-renderer-d3-canvas-target.js | 301 +------------- src/r3-api-renderer-d3-canvas.js | 311 +++------------ src/r3-api-renderer-d3-target.js | 333 +++------------- src/r3-api-renderer-d3.js | 54 +-- src/r3-api-server.js | 28 +- src/r3-api-socket-0.js | 66 +-- src/r3-api-socket-cast.js | 27 +- src/r3-api-socket-receive.js | 25 +- src/r3-api-sphere.js | 8 + src/r3-api-stats.js | 50 +-- src/r3-api-system.js | 104 ----- src/r3-api-user.js | 24 +- src/r3-api-video.js | 22 +- src/r3-box3.js | 16 +- src/r3-color.js | 60 +-- src/r3-d3-api-a-object.js | 135 +------ src/r3-d3-api-animation.js | 56 +-- src/r3-d3-api-audio.js | 57 +-- src/r3-d3-api-bone.js | 33 +- src/r3-d3-api-broadphase.js | 40 +- src/r3-d3-api-camera-a.js | 45 +-- src/r3-d3-api-camera-cube.js | 30 +- ...d3-api-camera-orthographic-fixed-aspect.js | 37 ++ ...3-api-camera-orthographic-zoomed-aspect.js | 59 +++ src/r3-d3-api-camera-orthographic.js | 131 ++---- src/r3-d3-api-camera-perspective-stereo.js | 36 +- src/r3-d3-api-camera-perspective.js | 33 +- src/r3-d3-api-composer.js | 48 +-- src/r3-d3-api-effect-a.js | 75 +--- src/r3-d3-api-effect-anaglyph.js | 21 +- src/r3-d3-api-effect-parallax.js | 19 +- src/r3-d3-api-effect-stereo.js | 25 +- src/r3-d3-api-face.js | 109 +---- src/r3-d3-api-fog.js | 27 +- src/r3-d3-api-font.js | 48 +-- src/r3-d3-api-friction-contact-material.js | 48 +-- src/r3-d3-api-friction-material.js | 43 +- src/r3-d3-api-geometry-a.js | 377 +----------------- src/r3-d3-api-geometry-buffer-a.js | 28 +- src/r3-d3-api-geometry-buffer-box.js | 25 +- src/r3-d3-api-geometry-buffer-circle.js | 24 +- src/r3-d3-api-geometry-buffer-cone.js | 23 +- src/r3-d3-api-geometry-buffer-cylinder.js | 23 +- src/r3-d3-api-geometry-buffer-dodecahedron.js | 23 +- src/r3-d3-api-geometry-buffer-extrude.js | 23 +- src/r3-d3-api-geometry-buffer-icosahedron.js | 23 +- src/r3-d3-api-geometry-buffer-instanced.js | 23 +- src/r3-d3-api-geometry-buffer-lathe.js | 23 +- src/r3-d3-api-geometry-buffer-octahedron.js | 23 +- src/r3-d3-api-geometry-buffer-parametric.js | 23 +- src/r3-d3-api-geometry-buffer-plane.js | 23 +- src/r3-d3-api-geometry-buffer-polyhedron.js | 23 +- src/r3-d3-api-geometry-buffer-ring.js | 23 +- src/r3-d3-api-geometry-buffer-shape.js | 23 +- src/r3-d3-api-geometry-buffer-sphere.js | 23 +- src/r3-d3-api-geometry-buffer-tetrahedron.js | 23 +- src/r3-d3-api-geometry-buffer-text.js | 23 +- src/r3-d3-api-geometry-buffer-torus-knot.js | 23 +- src/r3-d3-api-geometry-buffer-torus.js | 23 +- src/r3-d3-api-geometry-buffer-tube.js | 23 +- src/r3-d3-api-geometry-normal-a.js | 32 +- src/r3-d3-api-geometry-normal-box.js | 33 +- src/r3-d3-api-geometry-normal-circle.js | 31 +- src/r3-d3-api-geometry-normal-cone.js | 31 +- src/r3-d3-api-geometry-normal-cylinder.js | 31 +- src/r3-d3-api-geometry-normal-dodecahedron.js | 31 +- src/r3-d3-api-geometry-normal-edges.js | 31 +- src/r3-d3-api-geometry-normal-extrude.js | 31 +- src/r3-d3-api-geometry-normal-icosahedron.js | 31 +- src/r3-d3-api-geometry-normal-lathe.js | 31 +- src/r3-d3-api-geometry-normal-octahedron.js | 31 +- src/r3-d3-api-geometry-normal-parametric.js | 31 +- src/r3-d3-api-geometry-normal-plane.js | 31 +- src/r3-d3-api-geometry-normal-polyhedron.js | 31 +- src/r3-d3-api-geometry-normal-ring.js | 31 +- src/r3-d3-api-geometry-normal-shape.js | 31 +- src/r3-d3-api-geometry-normal-sphere.js | 31 +- src/r3-d3-api-geometry-normal-tetrahedron.js | 31 +- src/r3-d3-api-geometry-normal-text.js | 31 +- src/r3-d3-api-geometry-normal-torus-knot.js | 31 +- src/r3-d3-api-geometry-normal-torus.js | 31 +- src/r3-d3-api-geometry-normal-tube.js | 31 +- src/r3-d3-api-geometry-normal-wireframe.js | 31 +- src/r3-d3-api-light-a.js | 108 +---- src/r3-d3-api-light-ambient.js | 19 +- src/r3-d3-api-light-directional.js | 37 +- src/r3-d3-api-light-hemisphere.js | 31 +- src/r3-d3-api-light-point.js | 51 +-- src/r3-d3-api-light-rect-area.js | 44 +- src/r3-d3-api-light-spot.js | 43 +- src/r3-d3-api-material-a.js | 110 +---- src/r3-d3-api-material-basic.js | 51 +-- src/r3-d3-api-material-phong.js | 51 +-- src/r3-d3-api-material-points.js | 51 +-- src/r3-d3-api-material-shader-a.js | 52 +-- src/r3-d3-api-material-shader-raw.js | 43 +- src/r3-d3-api-material-standard.js | 51 +-- src/r3-d3-api-mesh-0.js | 56 +-- src/r3-d3-api-particle-engine.js | 128 ++---- src/r3-d3-api-particle.js | 35 +- src/r3-d3-api-pass-0.js | 78 +--- src/r3-d3-api-pass-bloom.js | 24 +- src/r3-d3-api-pass-fxaa.js | 24 +- src/r3-d3-api-pass-render.js | 36 +- src/r3-d3-api-pass-ssao.js | 37 +- src/r3-d3-api-physics-world.js | 63 +-- src/r3-d3-api-raycast-vehicle.js | 52 +-- src/r3-d3-api-raycast-wheel.js | 64 +-- src/r3-d3-api-raycaster.js | 23 +- src/r3-d3-api-render-target-a.js | 85 +--- src/r3-d3-api-render-target-cube.js | 47 +-- src/r3-d3-api-rigid-body.js | 78 +--- src/r3-d3-api-scene.js | 72 +++- src/r3-d3-api-shader-a.js | 87 +--- src/r3-d3-api-shader-fragment.js | 17 +- src/r3-d3-api-shader-vertex.js | 17 +- src/r3-d3-api-shadow-a.js | 142 ++----- src/r3-d3-api-shadow-directional.js | 31 +- src/r3-d3-api-shadow-spot.js | 44 +- src/r3-d3-api-shape-box.js | 28 ++ src/r3-d3-api-shape-convex-hull-cylinder.js | 25 ++ src/r3-d3-api-shape-convex-hull.js | 28 ++ src/r3-d3-api-shape-plane.js | 28 ++ src/r3-d3-api-shape-sphere.js | 28 ++ src/r3-d3-api-shape-tri-mesh.js | 28 ++ src/r3-d3-api-shape.js | 133 +----- src/r3-d3-api-skeleton.js | 25 +- src/r3-d3-api-solver.js | 50 +-- src/r3-d3-api-spline.js | 44 +- src/r3-d3-api-text.js | 35 +- src/r3-d3-api-texture-canvas.js | 41 +- src/r3-d3-api-texture-cube.js | 41 +- src/r3-d3-api-texture-image.js | 41 +- ...-api-texture-a.js => r3-d3-api-texture.js} | 79 +--- src/r3-d3-api-viewport-fixed-aspect.js | 35 +- src/r3-d3-api-viewport-zoomed-aspect.js | 52 ++- src/r3-d3-api-viewport.js | 173 +------- src/r3-d3-camera-orthographic-fixed-aspect.js | 289 ++++++++++++++ ...r3-d3-camera-orthographic-zoomed-aspect.js | 289 ++++++++++++++ src/r3-graphics-runtime-a.js | 12 + src/r3-graphics-runtime-three.js | 38 ++ src/r3-matrix-4.js | 280 ++++++------- src/r3-physics-runtime-cannon.js | 17 +- src/r3-physics-runtime.js | 12 + src/r3-quaternion.js | 95 +++-- src/r3-vector2.js | 2 +- src/r3-vector3.js | 16 +- src/r3-vector4.js | 2 +- 175 files changed, 2449 insertions(+), 6642 deletions(-) delete mode 100644 src/r3-api-system.js create mode 100644 src/r3-d3-api-camera-orthographic-fixed-aspect.js create mode 100644 src/r3-d3-api-camera-orthographic-zoomed-aspect.js create mode 100644 src/r3-d3-api-shape-box.js create mode 100644 src/r3-d3-api-shape-convex-hull-cylinder.js create mode 100644 src/r3-d3-api-shape-convex-hull.js create mode 100644 src/r3-d3-api-shape-plane.js create mode 100644 src/r3-d3-api-shape-sphere.js create mode 100644 src/r3-d3-api-shape-tri-mesh.js rename src/{r3-d3-api-texture-a.js => r3-d3-api-texture.js} (76%) create mode 100644 src/r3-d3-camera-orthographic-fixed-aspect.js create mode 100644 src/r3-d3-camera-orthographic-zoomed-aspect.js diff --git a/gulpfile.js b/gulpfile.js index 6cffe39..19d2147 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,24 +7,144 @@ 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;'; +var code = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n'; +code += '\t\tapiComponent = {};\n'; +code += '\t}\n'; +code += '\tthis.apiComponent = apiComponent;\n'; code += '\n'; -code += ' R3.API.Component.call('; -code += ' this,'; -code += ' this.apiComponent.parent,'; -code += ' this.apiComponent.id,'; -code += ' this.apiComponent.name'; -code += ' );'; +code += '\tR3.API.Component.call(\n'; +code += '\t\tthis,\n'; +code += '\t\tthis.apiComponent.parent,\n'; +code += '\t\tthis.apiComponent.id,\n'; +code += '\t\tthis.apiComponent.name\n'; +code += '\t);'; + +var code2 = 'if (R3.Utils.UndefinedOrNull(apiGeometryBuffer)) {\n'; +code2 += '\t\tapiGeometryBuffer = {};\n'; +code2 += '\t}\n'; +code2 += '\tthis.apiGeometryBuffer = apiGeometryBuffer;\n'; +code2 += '\n'; +code2 += '\tR3.D3.API.Geometry.Buffer.call(\n'; +code2 += '\t\tthis,\n'; +code2 += '\t\tthis.apiGeometryBuffer,\n'; +code2 += '\t\tthis.apiGeometryBuffer.attributes,\n'; +code2 += '\t\tthis.apiGeometryBuffer.drawRange,\n'; +code2 += '\t\tthis.apiGeometryBuffer.groups,\n'; +code2 += '\t\tthis.apiGeometryBuffer.index,\n'; +code2 += '\t\tthis.apiGeometryBuffer.morphAttributes\n'; +code2 += '\t);'; + +var code3 = 'if (R3.Utils.UndefinedOrNull(apiGeometryNormal)) {\n'; +code3 += '\t\tapiGeometryNormal = {};\n'; +code3 += '\t}\n'; +code3 += '\tthis.apiGeometryNormal = apiGeometryNormal;\n'; +code3 += '\n'; +code3 += '\tR3.D3.API.Geometry.Normal.call(\n'; +code3 += '\t\tthis,\n'; +code3 += '\t\tthis.apiGeometryNormal,\n'; +code3 += '\t\tthis.apiGeometryNormal.colors,\n'; +code3 += '\t\tthis.apiGeometryNormal.lineDistances,\n'; +code3 += '\t\tthis.apiGeometryNormal.morphTargets,\n'; +code3 += '\t\tthis.apiGeometryNormal.morphNormals,\n'; +code3 += '\t\tthis.apiGeometryNormal.skinWeights,\n'; +code3 += '\t\tthis.apiGeometryNormal.skinIndices,\n'; +code3 += '\t\tthis.apiGeometryNormal.verticesNeedsUpdate,\n'; +code3 += '\t\tthis.apiGeometryNormal.elementsNeedUpdate,\n'; +code3 += '\t\tthis.apiGeometryNormal.uvsNeedUpdate,\n'; +code3 += '\t\tthis.apiGeometryNormal.normalsNeedUpdate,\n'; +code3 += '\t\tthis.apiGeometryNormal.colorsNeedUpdate,\n'; +code3 += '\t\tthis.apiGeometryNormal.groupsNeedUpdate,\n'; +code3 += '\t\tthis.apiGeometryNormal.lineDistancesNeedUpdate\n'; +code3 += '\t);'; + +var code4 = 'if (R3.Utils.UndefinedOrNull(apiMaterial)) {\n'; +code4 += '\t\tapiMaterial = {};\n'; +code4 += '\t}\n'; +code4 += '\tthis.apiMaterial = apiMaterial;\n'; +code4 += '\n'; +code4 += '\tR3.D3.API.Material.call(\n'; +code4 += '\t\tthis,\n'; +code4 += '\t\tthis.apiMaterial,\n'; +code4 += '\t\tthis.apiMaterial.parentMeshes,\n'; +code4 += '\t\tthis.apiMaterial.alphaTest,\n'; +code4 += '\t\tthis.apiMaterial.blendDst,\n'; +code4 += '\t\tthis.apiMaterial.blendDstAlpha,\n'; +code4 += '\t\tthis.apiMaterial.blendEquation,\n'; +code4 += '\t\tthis.apiMaterial.blendEquationAlpha,\n'; +code4 += '\t\tthis.apiMaterial.blending,\n'; +code4 += '\t\tthis.apiMaterial.blendSrc,\n'; +code4 += '\t\tthis.apiMaterial.blendSrcAlpha,\n'; +code4 += '\t\tthis.apiMaterial.clipIntersection,\n'; +code4 += '\t\tthis.apiMaterial.clippingPlanes,\n'; +code4 += '\t\tthis.apiMaterial.clipShadows,\n'; +code4 += '\t\tthis.apiMaterial.colorWrite,\n'; +code4 += '\t\tthis.apiMaterial.customDepthMaterial,\n'; +code4 += '\t\tthis.apiMaterial.customDistanceMaterial,\n'; +code4 += '\t\tthis.apiMaterial.defines,\n'; +code4 += '\t\tthis.apiMaterial.depthFunc,\n'; +code4 += '\t\tthis.apiMaterial.depthTest,\n'; +code4 += '\t\tthis.apiMaterial.depthWrite,\n'; +code4 += '\t\tthis.apiMaterial.fog,\n'; +code4 += '\t\tthis.apiMaterial.lights,\n'; +code4 += '\t\tthis.apiMaterial.opacity,\n'; +code4 += '\t\tthis.apiMaterial.overdraw,\n'; +code4 += '\t\tthis.apiMaterial.polygonOffset,\n'; +code4 += '\t\tthis.apiMaterial.polygonOffsetFactor,\n'; +code4 += '\t\tthis.apiMaterial.polygonOffsetUnits,\n'; +code4 += '\t\tthis.apiMaterial.precision,\n'; +code4 += '\t\tthis.apiMaterial.premultipliedAlpha,\n'; +code4 += '\t\tthis.apiMaterial.dithering,\n'; +code4 += '\t\tthis.apiMaterial.flatShading,\n'; +code4 += '\t\tthis.apiMaterial.side,\n'; +code4 += '\t\tthis.apiMaterial.transparent,\n'; +code4 += '\t\tthis.apiMaterial.vertexColors,\n'; +code4 += '\t\tthis.apiMaterial.visible\n'; +code4 += '\t);'; + +var code5 = 'if (R3.Utils.UndefinedOrNull(apiTexture)) {\n'; +code5 += '\t\tapiTexture = {};\n'; +code5 += '\t}\n'; +code5 += '\tthis.apiTexture = apiTexture;\n'; +code5 += '\n'; +code5 += '\tR3.D3.API.Texture.call(\n'; +code5 += '\t\tthis,\n'; +code5 += '\t\tthis.apiTexture,\n'; +code5 += '\t\tthis.apiTexture.parentMaterials,\n'; +code5 += '\t\tthis.apiTexture.mipmaps,\n'; +code5 += '\t\tthis.apiTexture.mapping,\n'; +code5 += '\t\tthis.apiTexture.wrapS,\n'; +code5 += '\t\tthis.apiTexture.wrapT,\n'; +code5 += '\t\tthis.apiTexture.magFilter,\n'; +code5 += '\t\tthis.apiTexture.minFilter,\n'; +code5 += '\t\tthis.apiTexture.anisotropy,\n'; +code5 += '\t\tthis.apiTexture.format,\n'; +code5 += '\t\tthis.apiTexture.storageType,\n'; +code5 += '\t\tthis.apiTexture.offset,\n'; +code5 += '\t\tthis.apiTexture.repeat,\n'; +code5 += '\t\tthis.apiTexture.rotation,\n'; +code5 += '\t\tthis.apiTexture.center,\n'; +code5 += '\t\tthis.apiTexture.matrixAutoUpdate,\n'; +code5 += '\t\tthis.apiTexture.generateMipMaps,\n'; +code5 += '\t\tthis.apiTexture.premultiplyAlpha,\n'; +code5 += '\t\tthis.apiTexture.flipY,\n'; +code5 += '\t\tthis.apiTexture.unpackAlignment,\n'; +code5 += '\t\tthis.apiTexture.encoding,\n'; +code5 += '\t\tthis.apiTexture.version,\n'; +code5 += '\t\tthis.apiTexture.animated,\n'; +code5 += '\t\tthis.apiTexture.reverseAnimation,\n'; +code5 += '\t\tthis.apiTexture.forward\n'; +code5 += '\t);'; 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(replace('__API_COMPONENT_MACRO__', code)) + .pipe(replace('__API_GEOMETRY_BUFFER_MACRO__', code2)) + .pipe(replace('__API_GEOMETRY_NORMAL_MACRO__', code3)) + .pipe(replace('__API_MATERIAL_MACRO__', code4)) + .pipe(replace('__API_TEXTURE_MACRO__', code5)) .pipe(minify({ ext:{ src:'.js', diff --git a/src/r3-a-3-api-component.js b/src/r3-a-3-api-component.js index 52b0037..e07543f 100644 --- a/src/r3-a-3-api-component.js +++ b/src/r3-a-3-api-component.js @@ -31,6 +31,84 @@ R3.API.Component = function( R3.API.Component.prototype.constructor = R3.API.Component; +R3.API.Component.prototype.getParent = function(property, index, constructor) { + + if (R3.Utils.UndefinedOrNull(constructor)) { + constructor = null; + } + + if (R3.Utils.UndefinedOrNull(index)) { + index = null; + } + + if (this.parent) { + /** + * Parent defined + */ + if (this.parent.hasOwnProperty(property)) { + + if (constructor) { + + if (index) { + + if (this.parent[property][index] instanceof constructor) { + return this.parent[property][index]; + } else { + + if (typeof this.parent.getParent === 'function') { + return this.parent.getParent(property, index, constructor); + } else { + console.warn('getParent not defined on API object : ' + this.parent + ' - you should avoid having these messsages'); + return null; + } + } + + } else { + if (this.parent[property] instanceof constructor) { + return this.parent[property]; + } else { + + if (typeof this.parent.getParent === 'function') { + return this.parent.getParent(property, index, constructor); + } else { + console.warn('getParent not defined on API object : ' + this.parent + ' - you should avoid having these messsages'); + return null; + } + + } + } + + } else { + + if (index) { + return this.parent[property][index]; + } else { + return this.parent[property]; + } + } + } else { + + /** + * This parent does not have the property - go a level higher + */ + if (typeof this.parent.getParent === 'function') { + return this.parent.getParent(property, index, constructor); + } else { + console.warn('getParent not defined on API object : ' + this.parent + ' - you should avoid having these messsages'); + return null; + } + } + + } else { + /** + * No parent defined + */ + console.warn('property : ' + property + ' of type ' + constructor + ' was not found in the parent chain'); + return null; + } + +}; + R3.API.Component.prototype.getComponentType = function() { if (this instanceof R3.API.Box3) { @@ -180,6 +258,9 @@ R3.API.Component.prototype.getComponentType = function() { if (this instanceof R3.D3.API.Effect.Anaglyph) { return R3.Component.EFFECT_ANAGLYPH; } + if (this instanceof R3.D3.API.Face) { + return R3.Component.FACE; + } if (this instanceof R3.D3.API.Fog) { return R3.Component.FOG; } @@ -369,7 +450,7 @@ R3.API.Component.prototype.getComponentType = function() { if (this instanceof R3.D3.API.Mesh) { return R3.Component.MESH; } - if (this instanceof R3.D3.API.ParticleEngine) { + if (this instanceof R3.D3.API.Particle.Engine) { return R3.Component.PARTICLE_ENGINE; } if (this instanceof R3.D3.API.Particle) { diff --git a/src/r3-a-4-component-a.js b/src/r3-a-4-component-a.js index 7f0f58b..c8204bf 100644 --- a/src/r3-a-4-component-a.js +++ b/src/r3-a-4-component-a.js @@ -281,7 +281,7 @@ R3.Component.PASS_RENDER = 0xd; R3.Component.SCENE = 0xe; R3.Component.RAYCASTER = 0xf; R3.Component.TEXT = 0x10; -R3.Component.UNUSED = 0x11; +R3.Component.FACE = 0x11; R3.Component.VIEWPORT = 0x12; R3.Component.SYSTEM = 0x13; R3.Component.GRAPHICS = 0x14; @@ -942,10 +942,10 @@ R3.Component.GetComponentInfo = function(number) { apiConstructor : R3.API.Controls.D3.Orbit }; case 0x52 : return { - name : 'R3.D3.ParticleEngine', + name : 'R3.D3.Particle.Engine', runtime : R3.Component.GRAPHICS_RUNTIME, - constructor : R3.D3.ParticleEngine, - apiConstructor : R3.D3.API.ParticleEngine + constructor : R3.D3.Particle.Engine, + apiConstructor : R3.D3.API.Particle.Engine }; case 0x53 : return { name : 'R3.System.Particle', @@ -1623,6 +1623,9 @@ R3.Component.prototype.getComponentType = function() { if (this instanceof R3.D3.Effect.Stereo) { return R3.Component.EFFECT_STEREO; } + if (this instanceof R3.D3.Face) { + return R3.Component.FACE; + } if (this instanceof R3.D3.Fog) { return R3.Component.FOG; } @@ -1809,7 +1812,7 @@ R3.Component.prototype.getComponentType = function() { if (this instanceof R3.D3.Mesh) { return R3.Component.MESH; } - if (this instanceof R3.D3.ParticleEngine) { + if (this instanceof R3.D3.Particle.Engine) { return R3.Component.PARTICLE_ENGINE; } if (this instanceof R3.D3.Particle) { diff --git a/src/r3-api-controls-0.js b/src/r3-api-controls-0.js index 525b208..b3761b5 100644 --- a/src/r3-api-controls-0.js +++ b/src/r3-api-controls-0.js @@ -1,58 +1,22 @@ /** * R3.API.Controls - * @param parent - * @param id - * @param name + * @param apiComponent * @param canvas * @constructor */ R3.API.Controls = function( - parent, - id, - name, + apiComponent, canvas ) { - R3.API.Component.call( - this, - parent - ); - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - - name = 'Controls'; - - switch (this.componentType) { - case R3.Component.CONTROLS_TOUCH: - name = 'Controls Touch'; - break; - case R3.Component.CONTROLS_KEYBOARD : - name = 'Controls Keyboard'; - break; - case R3.Component.CONTROLS_MOUSE : - name = 'Controls Mouse'; - break; - case R3.Component.CONTROLS_EDITOR : - name = 'Controls Editor'; - break; - case R3.Component.CONTROLS_FIRST_PERSON : - name = 'Controls First Person'; - break; - case R3.Component.CONTROLS_ORBIT : - name = 'Controls Orbit'; - break; - } - - name += ' (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(canvas)) { - canvas = null; + /** + * Try to attach the controls to the parent canvas + * @type {null} + */ + canvas = this.getParent('canvas'); } this.canvas = canvas; }; diff --git a/src/r3-api-controls-d3.js b/src/r3-api-controls-d3.js index ee8ac6a..6904f47 100644 --- a/src/r3-api-controls-d3.js +++ b/src/r3-api-controls-d3.js @@ -13,14 +13,20 @@ R3.API.Controls.D3 = function( R3.API.Controls.call( this, - apiControls.parent, - apiControls.id, - apiControls.name, + apiControls, apiControls.canvas ); if (R3.Utils.UndefinedOrNull(camera)) { - camera = null; + /** + * Get the cameraIndexEdit of the scene which is responsible for these controls + */ + var cameraIndex = this.getParent('cameraIndexEdit'); + + /** + * Now get the camera with this index from our project cameras + */ + camera = this.getParent('cameras', cameraIndex); } this.camera = camera; }; diff --git a/src/r3-api-controls-keyboard.js b/src/r3-api-controls-keyboard.js index fb53411..a696c21 100644 --- a/src/r3-api-controls-keyboard.js +++ b/src/r3-api-controls-keyboard.js @@ -7,9 +7,7 @@ R3.API.Controls.Keyboard = function( ) { R3.API.Controls.call( this, - apiControls.parent, - apiControls.id, - apiControls.name, + apiControls, apiControls.canvas ); }; diff --git a/src/r3-api-controls-mouse.js b/src/r3-api-controls-mouse.js index 4cf067f..344b07a 100644 --- a/src/r3-api-controls-mouse.js +++ b/src/r3-api-controls-mouse.js @@ -7,9 +7,7 @@ R3.API.Controls.Mouse = function( ) { R3.API.Controls.call( this, - apiControls.parent, - apiControls.id, - apiControls.name, + apiControls, apiControls.canvas ); }; diff --git a/src/r3-api-controls-touch.js b/src/r3-api-controls-touch.js index 7f7db65..17cf745 100644 --- a/src/r3-api-controls-touch.js +++ b/src/r3-api-controls-touch.js @@ -10,9 +10,7 @@ R3.API.Controls.Touch = function( R3.API.Controls.call( this, - apiControls.parent, - apiControls.id, - apiControls.name, + apiControls, apiControls.canvas ); diff --git a/src/r3-api-curve-a.js b/src/r3-api-curve-a.js index 4a783da..4179d46 100644 --- a/src/r3-api-curve-a.js +++ b/src/r3-api-curve-a.js @@ -1,88 +1,21 @@ /** * R3.API.Curve - * @param id - * @param name - * @param curveType - * @param parent + * @param apiComponent * @param arcLenghDivisions * @constructor */ R3.API.Curve = function( - parent, - id, - name, - curveType, + apiComponent, arcLenghDivisions ) { - R3.API.Component.call( - this, - parent - ); - if (R3.Utils.UndefinedOrNull(curveType)) { - curveType = R3.API.Curve.CURVE_TYPE_NONE; - } - this.curveType = curveType; - - if (R3.Utils.UndefinedOrNull(name)) { - - switch (this.curveType) { - case R3.API.Curve.CURVE_TYPE_NONE : - name = 'Curve'; - break; - case R3.API.Curve.CURVE_TYPE_PATH : - name = 'Curve Path'; - break; - default: - console.log('no nice name for curve'); - } - - name += ' (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(arcLenghDivisions)) { arcLenghDivisions = 200; } this.arcLenghDivisions = arcLenghDivisions; - - R3.API.Component.call( - this, - R3.API.Curve.GetComponentType(this.curveType), - parent - ); }; R3.API.Curve.prototype = Object.create(R3.API.Curve.prototype); R3.API.Curve.prototype.constructor = R3.API.Curve; - -R3.API.Curve.GetComponentType = function(curveType) { - - var componentType = null; - - switch (curveType) { - case R3.API.Curve.CURVE_TYPE_NONE : - componentType = R3.Component.CURVE; - break; - case R3.API.Curve.CURVE_TYPE_PATH : - componentType = R3.Component.CURVE_PATH; - break; - case R3.API.Curve.CURVE_TYPE_PATH_2D : - componentType = R3.Component.CURVE_PATH_D2; - break; - case R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE : - componentType = R3.Component.CURVE_PATH_D2_SHAPE; - break; - default : - throw new Error('unhandled curve type'); - } - - return componentType; -}; - -R3.API.Curve.CURVE_TYPE_NONE = 0x0; -R3.API.Curve.CURVE_TYPE_PATH = 0x1; -R3.API.Curve.CURVE_TYPE_PATH_2D = 0x2; -R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE = 0x3; - - diff --git a/src/r3-api-curve-path-a.js b/src/r3-api-curve-path-a.js index 8b73e5f..ab818db 100644 --- a/src/r3-api-curve-path-a.js +++ b/src/r3-api-curve-path-a.js @@ -11,14 +11,15 @@ R3.API.Curve.Path = function( autoClose ) { if (R3.Utils.UndefinedOrNull(apiCurve)) { - apiCurve = { - curveType: R3.API.Curve.CURVE_TYPE_PATH - }; + apiCurve = {} } + this.apiCurve = apiCurve; - if (R3.Utils.UndefinedOrNull(apiCurve.curveType)) { - apiCurve.curveType = R3.API.Curve.CURVE_TYPE_PATH; - } + R3.API.Curve.call( + this, + apiCurve, + apiCurve.arcLenghDivisions + ); if (R3.Utils.UndefinedOrNull(curves)) { curves = []; @@ -29,15 +30,6 @@ R3.API.Curve.Path = function( autoClose = false; } this.autoClose = autoClose; - - R3.API.Curve.call( - this, - apiCurve.id, - apiCurve.name, - apiCurve.curveType, - apiCurve.parent, - apiCurve.arcLenghDivisions - ); }; R3.API.Curve.Path.prototype = Object.create(R3.API.Curve.prototype); diff --git a/src/r3-api-curve-path-d2-a.js b/src/r3-api-curve-path-d2-a.js index f862c9e..768d612 100644 --- a/src/r3-api-curve-path-d2-a.js +++ b/src/r3-api-curve-path-d2-a.js @@ -8,20 +8,11 @@ R3.API.Curve.Path.D2 = function( apiCurvePath, points ) { + if (R3.Utils.UndefinedOrNull(apiCurvePath)) { - apiCurvePath = { - curveType: R3.API.Curve.CURVE_TYPE_PATH_2D - }; + apiCurvePath = {} } - - if (R3.Utils.UndefinedOrNull(apiCurvePath.curveType)) { - apiCurvePath.curveType = R3.API.Curve.CURVE_TYPE_PATH_2D; - } - - if (R3.Utils.UndefinedOrNull(points)) { - points = []; - } - this.points = points; + this.apiCurvePath = apiCurvePath; R3.API.Curve.Path.call( this, @@ -29,6 +20,12 @@ R3.API.Curve.Path.D2 = function( apiCurvePath.curves, apiCurvePath.autoClose ); + + if (R3.Utils.UndefinedOrNull(points)) { + points = []; + } + this.points = points; + }; R3.API.Curve.Path.D2.prototype = Object.create(R3.API.Curve.Path.prototype); diff --git a/src/r3-api-curve-path-d2-shape.js b/src/r3-api-curve-path-d2-shape.js index 325c498..bd20af3 100644 --- a/src/r3-api-curve-path-d2-shape.js +++ b/src/r3-api-curve-path-d2-shape.js @@ -7,13 +7,7 @@ R3.API.Curve.Path.D2.Shape = function( apiCurvePathD2 ) { if (R3.Utils.UndefinedOrNull(apiCurvePathD2)) { - apiCurvePathD2 = { - curveType : R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE - }; - } - - if (R3.Utils.UndefinedOrNull(apiCurvePathD2.curveType)) { - apiCurvePathD2.curveType = R3.API.Curve.CURVE_TYPE_PATH_2D_SHAPE ; + apiCurvePathD2 = {}; } R3.API.Curve.Path.call( diff --git a/src/r3-api-custom-code.js b/src/r3-api-custom-code.js index 3a54f7b..045f894 100644 --- a/src/r3-api-custom-code.js +++ b/src/r3-api-custom-code.js @@ -1,31 +1,20 @@ /** * Custom Code Component - * @param id - * @param name + * @param apiComponent * @param eventId * @param code - * @param parent * @constructor */ R3.API.CustomCode = function( - id, - name, + apiComponent, eventId, - code, - parent + code ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'CustomCode (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(eventId)) { - eventId = 42; + eventId = R3.Event.KEY_UP; } this.eventId = eventId; @@ -33,12 +22,6 @@ R3.API.CustomCode = function( code = "return null;\n//@ sourceURL=" + this.name + ".js"; } this.code = code; - - R3.API.Component.call( - this, - R3.Component.CUSTOM_CODE, - parent - ); }; R3.API.CustomCode.prototype = Object.create(R3.API.Component.prototype); diff --git a/src/r3-api-dom-element.js b/src/r3-api-dom-element.js index ddd5d9f..05ff5bc 100644 --- a/src/r3-api-dom-element.js +++ b/src/r3-api-dom-element.js @@ -1,53 +1,21 @@ /** * API DomElement - * @param id - * @param name + * @param apiComponent * @param domElementId - * @param parent * @constructor */ R3.API.DomElement = function( - id, - name, - domElementId, - parent + apiComponent, + domElementId ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - name = 'DOM Element (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(domElementId)) { domElementId = ''; } this.domElementId = domElementId; - - R3.API.Component.call( - this, - R3.Component.DOM_ELEMENT, - parent - ); }; R3.API.DomElement.prototype = Object.create(R3.API.Component.prototype); R3.API.DomElement.prototype.constructor = R3.API.DomElement; - -/** - * Returns an API domElement from an Object domElement - * @param objectDomElement - * @constructor - */ -R3.API.DomElement.FromObject = function(objectDomElement) { - return new R3.API.DomElement( - objectDomElement.id, - objectDomElement.name, - objectDomElement.domElementId, - objectDomElement.parent - ) -}; diff --git a/src/r3-api-draw-range.js b/src/r3-api-draw-range.js index fa868b2..a11fdcf 100644 --- a/src/r3-api-draw-range.js +++ b/src/r3-api-draw-range.js @@ -1,28 +1,17 @@ /** * R3.API.Box3 * @constructor - * @param id - * @param name - * @param parent + * @param apiComponent * @param start * @param count */ R3.API.DrawRange = function( - id, - name, - parent, + apiComponent, start, count ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'DrawRange (' + id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(start)) { start = 0; @@ -34,11 +23,6 @@ R3.API.DrawRange = function( } this.count = count; - R3.API.Component.call( - this, - R3.Component.DRAW_RANGE, - parent - ) }; R3.API.DrawRange.prototype = Object.create(R3.API.Component.prototype); diff --git a/src/r3-api-entity-manager.js b/src/r3-api-entity-manager.js index b931ab8..cc7a44c 100644 --- a/src/r3-api-entity-manager.js +++ b/src/r3-api-entity-manager.js @@ -1,67 +1,21 @@ /** * Entity API Object (for storing / loading entities to and from API) * @constructor - * @param id - * @param name + * @param apiComponent * @param entities R3.API.Entity[] - * @param defaultEntity - * @param parent */ R3.API.EntityManager = function( - id, - name, - entities, - defaultEntity, - parent + apiComponent, + entities ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Entity Manager (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(entities)) { entities = []; } this.entities = entities; - - if (R3.Utils.UndefinedOrNull(defaultEntity)) { - defaultEntity = null; - } - this.defaultEntity = defaultEntity; - - R3.API.Component.call( - this, - R3.Component.ENTITY_MANAGER, - parent - ); }; R3.API.EntityManager.prototype = Object.create(R3.API.Component.prototype); R3.API.EntityManager.prototype.constructor = R3.API.EntityManager; - -/** - * Creates an API entity manager from an Object entity manager - * @param objectEntityManager - * @constructor - */ -R3.API.EntityManager.FromObject = function(objectEntityManager) { - - var apiEntities = objectEntityManager.entities.map( - function(objectEntity) { - return R3.API.Entity.FromObject(objectEntity); - } - ); - - return new R3.API.EntityManager( - objectEntityManager.id, - objectEntityManager.name, - apiEntities, - objectEntityManager.defaultEntity, - objectEntityManager.parent - ); -}; diff --git a/src/r3-api-entity.js b/src/r3-api-entity.js index 9a7bcad..42ff8b1 100644 --- a/src/r3-api-entity.js +++ b/src/r3-api-entity.js @@ -1,58 +1,22 @@ /** * Entity API Object (for storing / loading entities to and from API) - * @param id - * @param name - * @param components R3.Component[] - * @param parent R3.Entity + * @param apiComponent + * @param components R3.API.Component[] * @constructor */ R3.API.Entity = function( - id, - name, - components, - parent + apiComponent, + components ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Entity (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(components)) { components = []; } this.components = components; - var componentType = R3.Component.ENTITY; - - if (this instanceof R3.API.Project) { - componentType = R3.Component.PROJECT; - } - - R3.API.Component.call( - this, - componentType, - parent - ); }; R3.API.Entity.prototype = Object.create(R3.API.Component.prototype); R3.API.Entity.prototype.constructor = R3.API.Entity; - -/** - * Returns an API entity from an Object entity - * @param objectEntity - * @constructor - */ -R3.API.Entity.FromObject = function(objectEntity) { - return new R3.API.Entity( - objectEntity.id, - objectEntity.name, - objectEntity.components, - objectEntity.parent - ) -}; diff --git a/src/r3-api-group.js b/src/r3-api-group.js index dd2180c..924e8a1 100644 --- a/src/r3-api-group.js +++ b/src/r3-api-group.js @@ -1,30 +1,19 @@ /** * R3.API.Group * @constructor - * @param id - * @param name - * @param parent + * @param apiComponent * @param start * @param count * @param materialIndex */ R3.API.Group = function( - id, - name, - parent, + apiComponent, start, count, materialIndex ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Group (' + id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(start)) { start = 0; @@ -40,12 +29,6 @@ R3.API.Group = function( materialIndex = 0; } this.materialIndex = materialIndex; - - R3.API.Component.call( - this, - R3.Component.GROUP, - parent - ) }; R3.API.Group.prototype = Object.create(R3.API.Component.prototype); diff --git a/src/r3-api-gui.js b/src/r3-api-gui.js index d6a3b1d..0923812 100644 --- a/src/r3-api-gui.js +++ b/src/r3-api-gui.js @@ -1,64 +1,21 @@ /** * Raw GUI API object - should always correspond with the GUI Schema - * @param id - * @param name + * @param apiComponent * @param domElement - * @param parent * @constructor */ R3.API.GUI = function( - id, - name, - domElement, - parent + apiComponent, + domElement ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - name = 'GUI (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(domElement)) { domElement = null; } this.domElement = domElement; - - R3.API.Component.call( - this, - R3.Component.GUI, - parent - ); }; R3.API.GUI.prototype = Object.create(R3.API.Component.prototype); R3.API.GUI.prototype.constructor = R3.API.GUI; - -/** - * Creates an API GUI from an Object GUI - * @param objectGUI - * @constructor - */ -R3.API.GUI.FromObject = function(objectGUI) { - - var apiDomElement = null; - if (objectGUI.domElement) { - if (objectGUI.domElement instanceof Object) { - apiDomElement = R3.API.DomElement.FromObject(objectGUI.domElement); - } else { - apiDomElement = objectGUI.domElement; - } - } - - return new R3.API.GUI( - objectGUI.id, - objectGUI.name, - apiDomElement, - objectGUI.parent - ); - -}; diff --git a/src/r3-api-image.js b/src/r3-api-image.js index 0405ee1..a5ef388 100644 --- a/src/r3-api-image.js +++ b/src/r3-api-image.js @@ -1,9 +1,6 @@ /** * R3.API.Image - * @param id - * @param name - * @param parent - * @param parentTexture + * @param apiComponent * @param fileName * @param extension * @param path @@ -14,10 +11,7 @@ * @constructor */ R3.API.Image = function( - id, - name, - parent, - parentTexture, + apiComponent, fileName, extension, path, @@ -26,20 +20,8 @@ R3.API.Image = function( width, height ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Image ' + id; - } - this.name = name; - - if (R3.Utils.UndefinedOrNull(parentTexture)) { - parentTexture = null; - } - this.parentTexture = parentTexture; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(fileName)) { fileName = R3.Utils.LowerUnderscore(name); @@ -89,11 +71,6 @@ R3.API.Image = function( } this.height = height; - R3.API.Component.call( - this, - R3.Component.IMAGE, - parent - ); }; R3.API.Image.prototype = Object.create(R3.API.Component.prototype); diff --git a/src/r3-api-matrix4.js b/src/r3-api-matrix4.js index 44ce5b8..9b8a858 100644 --- a/src/r3-api-matrix4.js +++ b/src/r3-api-matrix4.js @@ -56,33 +56,6 @@ R3.API.Matrix4 = function ApiMatrix4( this.up = new R3.API.Vector4(); }; -/** - * Returns an API matrix from an Object matrix - * @param objectMatrix - * @constructor - */ -R3.API.Matrix4.FromObject = function(objectMatrix) { - - if (objectMatrix.rows) { - return new R3.API.Matrix4( - R3.API.Vector4.FromObject(objectMatrix.rows[0]), - R3.API.Vector4.FromObject(objectMatrix.rows[1]), - R3.API.Vector4.FromObject(objectMatrix.rows[2]), - R3.API.Vector4.FromObject(objectMatrix.rows[3]) - ); - } else if (objectMatrix instanceof Array) { - return new R3.API.Matrix4( - R3.API.Vector4.FromObject(objectMatrix[0]), - R3.API.Vector4.FromObject(objectMatrix[1]), - R3.API.Vector4.FromObject(objectMatrix[2]), - R3.API.Vector4.FromObject(objectMatrix[3]) - ); - } else { - console.warn('Unsupported object matrix type - whats your DB version?'); - throw new Error('Unsupported object matrix type - whats your DB version?'); - } -}; - 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); diff --git a/src/r3-api-mouse.js b/src/r3-api-mouse.js index e37e16d..fb17551 100644 --- a/src/r3-api-mouse.js +++ b/src/r3-api-mouse.js @@ -1,28 +1,17 @@ /** - * API Mouse - * @param id - * @param name - * @param parent + * R3.API.Mouse + * @param apiComponent * @param x * @param y * @constructor */ R3.API.Mouse = function( - id, - name, - parent, + apiComponent, x, y ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Mouse (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(x)) { x = 0; @@ -34,11 +23,6 @@ R3.API.Mouse = function( } this.y = y; - R3.API.Component.call( - this, - R3.Component.MOUSE, - parent - ); }; R3.API.Mouse.prototype = Object.create(R3.API.Component.prototype); diff --git a/src/r3-api-plane.js b/src/r3-api-plane.js index 26896f2..c2bd19b 100644 --- a/src/r3-api-plane.js +++ b/src/r3-api-plane.js @@ -1,20 +1,17 @@ +/** + * R3.API.Plane + * @param apiComponent + * @param normal + * @param constant + * @constructor + */ R3.API.Plane = function( - id, - name, + apiComponent, normal, - constant, - parent + constant ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Plane (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(normal)) { normal = new R3.API.Vector3(1,0,0); @@ -26,28 +23,8 @@ R3.API.Plane = function( } this.constant = constant; - R3.API.Component.call( - this, - R3.Component.PLANE, - parent - ); }; R3.API.Plane.prototype = Object.create(R3.API.Component.prototype); R3.API.Plane.prototype.constructor = R3.API.Plane; - -/** - * Returns an API vector from an Object vector - * @param objectPlane - * @constructor - */ -R3.API.Plane.FromObject = function(objectPlane) { - return new R3.API.Plane( - objectPlane.id, - objectPlane.name, - R3.API.Vector3.FromObject(objectPlane.normal), - objectPlane.constant, - objectPlane.parent - ); -}; diff --git a/src/r3-api-project.js b/src/r3-api-project.js index 1fadaaa..0720555 100644 --- a/src/r3-api-project.js +++ b/src/r3-api-project.js @@ -1,8 +1,6 @@ /** * API Project - * @param id - * @param name - * @param parent + * @param apiComponent * @param users * @param isPublic * @param entities @@ -12,9 +10,7 @@ * @constructor */ R3.API.Project = function( - id, - name, - parent, + apiComponent, users, isPublic, entities, @@ -22,15 +18,8 @@ R3.API.Project = function( cameras, mode ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Project (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(users)) { throw new Error('Only registered users can create projects'); @@ -71,14 +60,6 @@ R3.API.Project = function( mode = R3.API.Project.APPLICATION_MODE_EDIT; } this.mode = mode; - - R3.API.Component.call( - this, - this.id, - this.name, - this.components, - this.parent - ); }; R3.API.Project.prototype = Object.create(R3.API.Component.prototype); diff --git a/src/r3-api-quaternion-points.js b/src/r3-api-quaternion-points.js index cf37b74..6ed6d61 100644 --- a/src/r3-api-quaternion-points.js +++ b/src/r3-api-quaternion-points.js @@ -1,3 +1,7 @@ +/** + * R3.API.Quaternion.Points + * @constructor + */ R3.API.Quaternion.Points = function() { this.vectors = []; }; diff --git a/src/r3-api-renderer-a.js b/src/r3-api-renderer-a.js index fd84a81..ad56170 100644 --- a/src/r3-api-renderer-a.js +++ b/src/r3-api-renderer-a.js @@ -1,94 +1,19 @@ /** * R3.API.Renderer - * @param id - * @param name - * @param rendererType - * @param parent - * @param canvas * @constructor + * @param apiComponent */ R3.API.Renderer = function( - id, - name, - parent, - rendererType + apiComponent ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(rendererType)) { - rendererType = R3.API.Renderer.RENDERER_TYPE_NONE; - } - this.rendererType = rendererType; - - if (R3.Utils.UndefinedOrNull(name)) { - - switch (this.rendererType) { - case R3.API.Renderer.RENDERER_TYPE_NONE : - name = "Renderer"; - break; - case R3.API.Renderer.RENDERER_TYPE_2D : - name = "Renderer 2D"; - break; - case R3.API.Renderer.RENDERER_TYPE_3D : - name = "Renderer 3D"; - break; - default : - console.warn('no nice name for renderer'); - break; - } - - name += " (" + this.id + ")"; - } - this.name = name; - - R3.API.Component.call( - this, - R3.API.Renderer.GetComponentType(this.rendererType), - parent - ); + __API_COMPONENT_MACRO__ }; R3.API.Renderer.prototype = Object.create(R3.API.Component.prototype); R3.API.Renderer.prototype.constructor = R3.API.Renderer; -R3.API.Renderer.GetComponentType = function(rendererType) { - - var componentType = null; - - switch (rendererType) { - case R3.API.Renderer.RENDERER_TYPE_NONE : - componentType = R3.Component.RENDERER; - break; - case R3.API.Renderer.RENDERER_TYPE_2D : - componentType = R3.Component.RENDERER_D2; - break; - 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'); - break; - } - - return componentType; -}; - -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; R3.API.Renderer.MODE_CANVAS_AND_TARGET = 0x3; diff --git a/src/r3-api-renderer-d2.js b/src/r3-api-renderer-d2.js index e7013f2..2e89f36 100644 --- a/src/r3-api-renderer-d2.js +++ b/src/r3-api-renderer-d2.js @@ -10,21 +10,13 @@ R3.API.Renderer.D2 = function( ) { if (R3.Utils.UndefinedOrNull(apiRenderer)) { - apiRenderer = { - rendererType : R3.API.Renderer.RENDERER_TYPE_2D - }; - } - - if (R3.Utils.UndefinedOrNull(apiRenderer.rendererType)) { - apiRenderer.rendererType = R3.API.Renderer.RENDERER_TYPE_2D; + apiRenderer = {}; } + this.apiRenderer = apiRenderer; R3.API.Renderer.call( this, - apiRenderer.id, - apiRenderer.name, - apiRenderer.parent, - apiRenderer.rendererType + this.apiRenderer ); if (R3.Utils.UndefinedOrNull(canvas)) { @@ -35,4 +27,4 @@ R3.API.Renderer.D2 = function( }; R3.API.Renderer.D2.prototype = Object.create(R3.API.Renderer.prototype); -R3.API.Renderer.D2.prototype.constructor = R3.API.Renderer.D2; \ No newline at end of file +R3.API.Renderer.D2.prototype.constructor = R3.API.Renderer.D2; diff --git a/src/r3-api-renderer-d3-canvas-target.js b/src/r3-api-renderer-d3-canvas-target.js index 220ee6b..c1b8721 100644 --- a/src/r3-api-renderer-d3-canvas-target.js +++ b/src/r3-api-renderer-d3-canvas-target.js @@ -1,296 +1,29 @@ /** - * 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 + * R3.API.Renderer.D3.Canvas.Target * @constructor + * @param apiRendererD3Canvas + * @param target */ 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 + apiRendererD3Canvas, + target ) { - - if (R3.Utils.UndefinedOrNull(apiRenderer)) { - apiRenderer = { - rendererType : R3.API.Renderer.RENDERER_TYPE_3D - }; + if (R3.Utils.UndefinedOrNull(apiRendererD3Canvas)) { + apiRendererD3Canvas = {}; } + this.apiRendererD3Canvas = apiRendererD3Canvas; - 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( + R3.API.Renderer.D3.Canvas.call( this, - apiRenderer.id, - apiRenderer.name, - apiRenderer.parent, - apiRenderer.rendererType, - apiRenderer.canvas + this.apiRendererD3Canvas, + this.apiRendererD3Canvas.canvas ); + if (R3.Utils.UndefinedOrNull(target)) { + target = new R3.D3.API.RenderTarget(); + } + this.target = target; }; -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 +R3.API.Renderer.D3.Canvas.Target.prototype = Object.create(R3.API.Renderer.D3.Canvas.prototype); +R3.API.Renderer.D3.prototype.constructor = R3.API.Renderer.D3.Canvas.Target; diff --git a/src/r3-api-renderer-d3-canvas.js b/src/r3-api-renderer-d3-canvas.js index dfc4a9b..280c72b 100644 --- a/src/r3-api-renderer-d3-canvas.js +++ b/src/r3-api-renderer-d3-canvas.js @@ -1,274 +1,63 @@ /** - * 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 + * R3.API.Renderer.D3.Canvas + * @param apiRendererD3 + * @param canvas * @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 + apiRendererD3, + canvas ) { - if (R3.Utils.UndefinedOrNull(apiRenderer)) { - apiRenderer = { - rendererType : R3.API.Renderer.RENDERER_TYPE_3D - }; + if (R3.Utils.UndefinedOrNull(apiRendererD3)) { + apiRendererD3 = {}; } + this.apiRendererD3 = apiRendererD3; - 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( + R3.API.Renderer.D3.call( this, - apiRenderer.id, - apiRenderer.name, - apiRenderer.parent, - apiRenderer.rendererType, - apiRenderer.canvas + this.apiRendererD3, + this.apiRendererD3.renderMode, + this.apiRendererD3.autoClear, + this.apiRendererD3.autoClearColor, + this.apiRendererD3.autoClearDepth, + this.apiRendererD3.autoClearStencil, + this.apiRendererD3.gammaFactor, + this.apiRendererD3.gammaInput, + this.apiRendererD3.gammaOutput, + this.apiRendererD3.maxMorphTargets, + this.apiRendererD3.maxMorphNormals, + this.apiRendererD3.physicallyCorrectLights, + this.apiRendererD3.shadowMapEnabled, + this.apiRendererD3.shadowMapAutoUpdate, + this.apiRendererD3.shadowMapNeedsUpdate, + this.apiRendererD3.shadowMapType, + this.apiRendererD3.shadowMapRenderReverseSided, + this.apiRendererD3.shadowMapRenderSingleSided, + this.apiRendererD3.sortObjects, + this.apiRendererD3.toneMapping, + this.apiRendererD3.toneMappingExposure, + this.apiRendererD3.toneMappingWhitePoint, + this.apiRendererD3.premultipliedAlpha, + this.apiRendererD3.antialias, + this.apiRendererD3.stencil, + this.apiRendererD3.preserveDrawingBuffer, + this.apiRendererD3.depth, + this.apiRendererD3.logarithmicDepthBuffer, + this.apiRendererD3.localClippingEnabled, + this.apiRendererD3.clippingPlanes, + this.apiRendererD3.clearColor, + this.apiRendererD3.viewports, + this.apiRendererD3.alpha, + this.apiRendererD3.opacity ); + if (R3.Utils.UndefinedOrNull(canvas)) { + canvas = new R3.API.Canvas(); + } + this.canvas = 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 +R3.API.Renderer.D3.Canvas.prototype = Object.create(R3.API.Renderer.D3.prototype); +R3.API.Renderer.D3.Canvas.prototype.constructor = R3.API.Renderer.D3.Canvas; \ No newline at end of file diff --git a/src/r3-api-renderer-d3-target.js b/src/r3-api-renderer-d3-target.js index d2b5038..5734393 100644 --- a/src/r3-api-renderer-d3-target.js +++ b/src/r3-api-renderer-d3-target.js @@ -1,296 +1,63 @@ /** - * 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 + * R3.API.Renderer.D3.Target * @constructor + * @param apiRendererD3 + * @param target */ 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 + apiRendererD3, + target ) { - if (R3.Utils.UndefinedOrNull(apiRenderer)) { - apiRenderer = { - rendererType : R3.API.Renderer.RENDERER_TYPE_3D - }; + if (R3.Utils.UndefinedOrNull(apiRendererD3)) { + apiRendererD3 = {}; } + this.apiRendererD3 = apiRendererD3; - 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( + R3.API.Renderer.D3.call( this, - apiRenderer.id, - apiRenderer.name, - apiRenderer.parent, - apiRenderer.rendererType, - apiRenderer.canvas + this.apiRendererD3, + this.apiRendererD3.renderMode, + this.apiRendererD3.autoClear, + this.apiRendererD3.autoClearColor, + this.apiRendererD3.autoClearDepth, + this.apiRendererD3.autoClearStencil, + this.apiRendererD3.gammaFactor, + this.apiRendererD3.gammaInput, + this.apiRendererD3.gammaOutput, + this.apiRendererD3.maxMorphTargets, + this.apiRendererD3.maxMorphNormals, + this.apiRendererD3.physicallyCorrectLights, + this.apiRendererD3.shadowMapEnabled, + this.apiRendererD3.shadowMapAutoUpdate, + this.apiRendererD3.shadowMapNeedsUpdate, + this.apiRendererD3.shadowMapType, + this.apiRendererD3.shadowMapRenderReverseSided, + this.apiRendererD3.shadowMapRenderSingleSided, + this.apiRendererD3.sortObjects, + this.apiRendererD3.toneMapping, + this.apiRendererD3.toneMappingExposure, + this.apiRendererD3.toneMappingWhitePoint, + this.apiRendererD3.premultipliedAlpha, + this.apiRendererD3.antialias, + this.apiRendererD3.stencil, + this.apiRendererD3.preserveDrawingBuffer, + this.apiRendererD3.depth, + this.apiRendererD3.logarithmicDepthBuffer, + this.apiRendererD3.localClippingEnabled, + this.apiRendererD3.clippingPlanes, + this.apiRendererD3.clearColor, + this.apiRendererD3.viewports, + this.apiRendererD3.alpha, + this.apiRendererD3.opacity ); + if (R3.Utils.UndefinedOrNull(target)) { + target = new R3.D3.API.RenderTarget(); + } + this.target = target; + }; -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 +R3.API.Renderer.D3.Target.prototype = Object.create(R3.API.Renderer.D3.prototype); +R3.API.Renderer.D3.Target.prototype.constructor = R3.API.Renderer.D3.Target; diff --git a/src/r3-api-renderer-d3.js b/src/r3-api-renderer-d3.js index 95cbb8b..011c246 100644 --- a/src/r3-api-renderer-d3.js +++ b/src/r3-api-renderer-d3.js @@ -29,16 +29,11 @@ * @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 = function( @@ -71,7 +66,6 @@ R3.API.Renderer.D3 = function( depth, logarithmicDepthBuffer, localClippingEnabled, - renderTarget, clippingPlanes, clearColor, viewports, @@ -80,14 +74,14 @@ R3.API.Renderer.D3 = function( ) { if (R3.Utils.UndefinedOrNull(apiRenderer)) { - apiRenderer = { - rendererType : R3.API.Renderer.RENDERER_TYPE_3D - }; + apiRenderer = {}; } + this.apiRenderer = apiRenderer; - if (R3.Utils.UndefinedOrNull(apiRenderer.rendererType)) { - apiRenderer.rendererType = R3.API.Renderer.RENDERER_TYPE_3D; - } + R3.API.Renderer.call( + this, + this.apiRenderer + ); if (R3.Utils.UndefinedOrNull(renderMode)) { renderMode = R3.API.Renderer.MODE_CANVAS; @@ -229,11 +223,6 @@ R3.API.Renderer.D3 = function( } this.localClippingEnabled = localClippingEnabled; - if (R3.Utils.UndefinedOrNull(renderTarget)) { - renderTarget = null; - } - this.renderTarget = renderTarget; - if (R3.Utils.UndefinedOrNull(clippingPlanes)) { clippingPlanes = []; } @@ -259,37 +248,6 @@ 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.canvas - ); - }; R3.API.Renderer.D3.prototype = Object.create(R3.API.Renderer.prototype); diff --git a/src/r3-api-server.js b/src/r3-api-server.js index 94f76b1..ccbe53f 100644 --- a/src/r3-api-server.js +++ b/src/r3-api-server.js @@ -1,7 +1,6 @@ /** * R3.API.Server - * @param id - * @param name + * @param apiComponent * @param protocol * @param context * @param application @@ -10,12 +9,10 @@ * @param preferIp - Set to true to use IP instead of resolving DNS at getUrl() runtime * @param port * @param protocols - * @param parent * @constructor */ R3.API.Server = function( - id, - name, + apiComponent, protocol, context, application, @@ -23,19 +20,10 @@ R3.API.Server = function( ip, preferIp, port, - protocols, - parent + protocols ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Server (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(protocol)) { protocol = R3.API.Server.PROTOCOL_HTTP_SSL; @@ -76,12 +64,6 @@ R3.API.Server = function( protocols = []; } this.protocols = protocols; - - R3.API.Component.call( - this, - R3.Component.SERVER, - parent - ); }; R3.API.Server.prototype = Object.create(R3.API.Component.prototype); @@ -93,4 +75,4 @@ R3.API.Server.PROTOCOL_WEBSOCKET = 'ws'; R3.API.Server.PROTOCOL_WEBSOCKET_SSL = 'wss'; R3.API.Server.PORT_INSECURE = 80; -R3.API.Server.PORT_SECURE = 443; \ No newline at end of file +R3.API.Server.PORT_SECURE = 443; diff --git a/src/r3-api-socket-0.js b/src/r3-api-socket-0.js index 9bba617..6689877 100644 --- a/src/r3-api-socket-0.js +++ b/src/r3-api-socket-0.js @@ -1,51 +1,19 @@ /** * R3.API.Socket - * @param id - * @param name - * @param socketType + * @param apiComponent * @param roomId * @param peerId * @param server R3.Server - * @param parent * @constructor */ R3.API.Socket = function( - id, - name, - socketType, + apiComponent, roomId, peerId, - server, - parent + server ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(socketType)) { - socketType = R3.API.Socket.SOCKET_TYPE_CAST; - } - this.socketType = socketType; - - if (R3.Utils.UndefinedOrNull(name)) { - - switch (this.socketType) { - case R3.API.Socket.SOCKET_TYPE_CAST : - name = 'Socket Cast'; - break; - case R3.API.Socket.SOCKET_TYPE_RECEIVE: - name = 'Socket Receive'; - break; - default : - console.warn('no nice name for socket'); - name = 'socket'; - } - name += ' (' + this.id + ')'; - } - this.name = name; - + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(roomId)) { roomId = 'room_' + R3.Utils.RandomId(); @@ -84,33 +52,7 @@ R3.API.Socket = function( } this.server = server; - R3.API.Component.call( - this, - R3.API.Socket.GetComponentType(this.socketType), - parent - ); -}; - -R3.API.Socket.GetComponentType = function(socketType) { - - var componentType = null; - - switch (socketType) { - case R3.API.Socket.SOCKET_TYPE_CAST : - componentType = R3.Component.SOCKET_CAST; - break; - case R3.API.Socket.SOCKET_TYPE_RECEIVE : - componentType = R3.Component.SOCKET_RECEIVE; - break; - default : - console.error('could not determine socket component type') - } - - return componentType; }; R3.API.Socket.prototype = Object.create(R3.API.Component.prototype); R3.API.Socket.prototype.constructor = R3.API.Socket; - -R3.API.Socket.SOCKET_TYPE_CAST = 0x1; -R3.API.Socket.SOCKET_TYPE_RECEIVE = 0x2; diff --git a/src/r3-api-socket-cast.js b/src/r3-api-socket-cast.js index e41021a..a7946ad 100644 --- a/src/r3-api-socket-cast.js +++ b/src/r3-api-socket-cast.js @@ -14,14 +14,17 @@ R3.API.Socket.Cast = function( ) { if (R3.Utils.UndefinedOrNull(apiSocket)) { - apiSocket = { - socketType : R3.API.Socket.SOCKET_TYPE_CAST - }; + apiSocket = {} } + this.apiSocket = apiSocket; - if (R3.Utils.UndefinedOrNull(apiSocket.socketType)) { - apiSocket.socketType = R3.API.Socket.SOCKET_TYPE_CAST; - } + R3.API.Socket.call( + this, + this.apiSocket, + this.apiSocket.roomId, + this.apiSocket.peerId, + this.apiSocket.server + ); if (R3.Utils.UndefinedOrNull(castType)) { castType = R3.API.Socket.Cast.CAST_TYPE_ROOM; @@ -38,16 +41,6 @@ R3.API.Socket.Cast = function( } this.sourceProperties = sourceProperties; - R3.API.Socket.call( - this, - apiSocket.id, - apiSocket.name, - apiSocket.socketType, - apiSocket.roomId, - apiSocket.peerId, - apiSocket.server, - apiSocket.parent - ); }; R3.API.Socket.Cast.prototype = Object.create(R3.API.Socket.prototype); @@ -56,4 +49,4 @@ R3.API.Socket.Cast.prototype.constructor = R3.API.Socket.Cast; R3.API.Socket.Cast.CAST_TYPE_ROOM = 0x1; R3.API.Socket.Cast.CAST_TYPE_PEER = 0x2; R3.API.Socket.Cast.CAST_TYPE_ALL = 0x3; -R3.API.Socket.Cast.CAST_TYPE_ALL_BUT_PEER = 0x4; \ No newline at end of file +R3.API.Socket.Cast.CAST_TYPE_ALL_BUT_PEER = 0x4; diff --git a/src/r3-api-socket-receive.js b/src/r3-api-socket-receive.js index 6a89ab9..f3151a7 100644 --- a/src/r3-api-socket-receive.js +++ b/src/r3-api-socket-receive.js @@ -14,14 +14,17 @@ R3.API.Socket.Receive = function( ) { if (R3.Utils.UndefinedOrNull(apiSocket)) { - apiSocket = { - socketType : R3.API.Socket.SOCKET_TYPE_RECEIVE - }; + apiSocket = {} } + this.apiSocket = apiSocket; - if (R3.Utils.UndefinedOrNull(apiSocket.socketType)) { - apiSocket.socketType = R3.API.Socket.SOCKET_TYPE_RECEIVE; - } + R3.API.Socket.call( + this, + this.apiSocket, + this.apiSocket.roomId, + this.apiSocket.peerId, + this.apiSocket.server + ); if (R3.Utils.UndefinedOrNull(receiveType)) { receiveType = R3.API.Socket.Receive.RECEIVE_TYPE_ROOM; @@ -38,16 +41,6 @@ R3.API.Socket.Receive = function( } this.destinationProperties = destinationProperties; - R3.API.Socket.call( - this, - apiSocket.id, - apiSocket.name, - apiSocket.socketType, - apiSocket.roomId, - apiSocket.peerId, - apiSocket.server, - apiSocket.parent - ); }; R3.API.Socket.Receive.prototype = Object.create(R3.API.Socket.prototype); diff --git a/src/r3-api-sphere.js b/src/r3-api-sphere.js index 7e59134..8aece3f 100644 --- a/src/r3-api-sphere.js +++ b/src/r3-api-sphere.js @@ -1,13 +1,18 @@ /** * R3.API.Sphere * @constructor + * @param apiComponent * @param center * @param radius */ R3.API.Sphere = function( + apiComponent, center, radius ) { + + __API_COMPONENT_MACRO__ + if (R3.Utils.UndefinedOrNull(center)) { center = new R3.API.Vector3(0,0,0); } @@ -18,3 +23,6 @@ R3.API.Sphere = function( } this.radius = radius; }; + +R3.API.Sphere.prototype = Object.create(R3.API.Sphere.prototype); +R3.API.Sphere.prototype.constructor = R3.API.Sphere; diff --git a/src/r3-api-stats.js b/src/r3-api-stats.js index c991120..7841d4d 100644 --- a/src/r3-api-stats.js +++ b/src/r3-api-stats.js @@ -1,64 +1,22 @@ /** * Raw Stats API object - should always correspond with the Stats Schema - * @param id - * @param name + * @param apiComponent * @param domElement - * @param parent * @constructor */ R3.API.Stats = function( - id, - name, - domElement, - parent + apiComponent, + domElement ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Stats (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(domElement)) { domElement = null; } this.domElement = domElement; - R3.API.Component.call( - this, - R3.Component.STATS, - parent - ); }; R3.API.Stats.prototype = Object.create(R3.API.Component.prototype); R3.API.Stats.prototype.constructor = R3.API.Stats; - -/** - * Creates an API Stats from an Object Stats - * @param objectStats - * @constructor - */ -R3.API.Stats.FromObject = function(objectStats) { - - var apiDomElement = null; - if (objectStats.domElement) { - if (objectStats.domElement instanceof Object) { - apiDomElement = R3.API.DomElement.FromObject(objectStats.domElement); - } else { - apiDomElement = objectStats.domElement; - } - } - - return new R3.API.Stats( - objectStats.id, - objectStats.name, - apiDomElement, - objectStats.parent - ); - -}; diff --git a/src/r3-api-system.js b/src/r3-api-system.js deleted file mode 100644 index a9869bb..0000000 --- a/src/r3-api-system.js +++ /dev/null @@ -1,104 +0,0 @@ -/** - * This component renders a scene - * @param id String - * @param name String - * @param systemType - * @param parent - * @constructor - */ -R3.API.System = function( - id, - name, - systemType, - parent -) { - - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - name = "System (" + this.id + ")"; - } - this.name = name; - - if (R3.Utils.UndefinedOrNull(systemType)) { - systemType = R3.System.SYSTEM_TYPE_NONE; - } - this.systemType = systemType; - - var componentType = R3.Component.SYSTEM; - - if (this.systemType === R3.System.SYSTEM_TYPE_NONE) { - componentType = R3.Component.SYSTEM; - } - - if (this.systemType === R3.System.SYSTEM_TYPE_ANIMATION) { - componentType = R3.Component.SYSTEM_ANIMATION; - } - - if (this.systemType === R3.System.SYSTEM_TYPE_CUSTOM) { - componentType = R3.Component.SYSTEM_CUSTOM_CODE; - } - - if (this.systemType === R3.System.SYSTEM_TYPE_GUI) { - componentType = R3.Component.SYSTEM_GUI; - } - - if (this.systemType === R3.System.SYSTEM_TYPE_INPUT) { - componentType = R3.Component.SYSTEM_INPUT; - } - - if (this.systemType === R3.System.SYSTEM_TYPE_LINKING) { - componentType = R3.Component.SYSTEM_LINKING; - } - - if (this.systemType === R3.System.SYSTEM_TYPE_PHYSICS) { - componentType = R3.Component.SYSTEM_PHYSICS; - } - - if (this.systemType === R3.System.SYSTEM_TYPE_RENDER) { - componentType = R3.Component.SYSTEM_RENDER; - } - - if (this.systemType === R3.System.SYSTEM_TYPE_STORAGE) { - componentType = R3.Component.SYSTEM_STORAGE; - } - - if (this.systemType === R3.System.SYSTEM_TYPE_VISUALIZATION) { - componentType = R3.Component.SYSTEM_VISUALIZATION; - } - - if (this.systemType === R3.System.SYSTEM_TYPE_PARTICLE) { - componentType = R3.Component.SYSTEM_PARTICLE; - } - - if (this.systemType === R3.System.SYSTEM_TYPE_AUDIO) { - componentType = R3.Component.SYSTEM_AUDIO; - } - - R3.API.Component.call( - this, - componentType, - parent - ); - -}; - -R3.API.System.prototype = Object.create(R3.API.Component.prototype); -R3.API.System.prototype.constructor = R3.API.System; - -/** - * Object to R3.D3.API.System - * @param objectComponent - * @constructor - */ -R3.API.System.FromObject = function(objectComponent) { - return new R3.API.System( - objectComponent.id, - objectComponent.name, - objectComponent.systemType, - objectComponent.parent - ); -}; diff --git a/src/r3-api-user.js b/src/r3-api-user.js index 259ad8f..bcb0e6d 100644 --- a/src/r3-api-user.js +++ b/src/r3-api-user.js @@ -1,8 +1,6 @@ /** * API User - * @param id - * @param name - * @param parent + * @param apiComponent * @param googleId * @param fullName * @param givenName @@ -14,9 +12,7 @@ * @constructor */ R3.API.User = function( - id, - name, - parent, + apiComponent, googleId, fullName, givenName, @@ -26,15 +22,8 @@ R3.API.User = function( uploadFolder, idToken ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'User (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(googleId)) { throw new Error('invalid user - no google ID'); @@ -75,12 +64,7 @@ R3.API.User = function( idToken = 'unknown ID token'; } this.idToken = idToken; - - R3.API.Component.call( - this, - R3.Component.USER, - parent - ); + }; R3.API.User.prototype = Object.create(R3.API.Component.prototype); diff --git a/src/r3-api-video.js b/src/r3-api-video.js index 4f562e4..dba474b 100644 --- a/src/r3-api-video.js +++ b/src/r3-api-video.js @@ -1,8 +1,6 @@ /** * R3.API.Video - * @param id - * @param name - * @param parent + * @param apiComponent * @param autoUpdateSize * @param width * @param height @@ -11,24 +9,15 @@ * @constructor */ R3.API.Video = function( - id, - name, - parent, + apiComponent, autoUpdateSize, width, height, offset, source ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Video (' + id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(autoUpdateSize)) { autoUpdateSize = true; @@ -57,11 +46,6 @@ R3.API.Video = function( } this.source = source; - R3.API.Component.call( - this, - R3.Component.VIDEO, - parent - ); }; R3.API.Video.prototype = Object.create(R3.API.Component.prototype); diff --git a/src/r3-box3.js b/src/r3-box3.js index 453b88c..6220315 100644 --- a/src/r3-box3.js +++ b/src/r3-box3.js @@ -1,21 +1,29 @@ /** * R3.Box3 + * @param parent * @param apiBox3 * @constructor */ R3.Box3 = function( + parent, apiBox3 ) { + if (R3.Utils.UndefinedOrNull(parent)) { + parent = null; + } + this.parent = parent; + if (R3.Utils.UndefinedOrNull(apiBox3)) { apiBox3 = {}; } + this.apiBox3 = apiBox3; R3.API.Box3.call( this, - apiBox3, - apiBox3.min, - apiBox3.max + this.apiBox3, + this.apiBox3.min, + this.apiBox3.max ); this.min = new R3.Vector3( @@ -39,7 +47,7 @@ R3.Box3 = function( }.bind(this) ); - this.componentRuntime = R3.Component.GetComponentRuntime(parent); + this.componentRuntime = R3.Component.GetComponentRuntime(this.parent); this.createInstance(); }; diff --git a/src/r3-color.js b/src/r3-color.js index cc214b4..fdf5680 100644 --- a/src/r3-color.js +++ b/src/r3-color.js @@ -1,42 +1,44 @@ /** * Runtime color for updating instance objects - * @param graphics R3.GraphicsRuntime - * @param parentObject R3.D3.* + * @param parent * @param apiColor R3.API.Color - * @param grain Number * @constructor */ R3.Color = function( - graphics, - apiColor, - parentObject, - grain + parent, + apiColor ) { - this.graphics = graphics; - this.graphics.isNotThreeThrow(); + if (R3.Utils.UndefinedOrNull(parent)) { + parent = null; + } + this.parent = parent; if (R3.Utils.UndefinedOrNull(apiColor)) { apiColor = {}; } + this.apiColor = apiColor; R3.API.Color.call( this, - apiColor.r, - apiColor.g, - apiColor.b, - apiColor.a + this.apiColor.r, + this.apiColor.g, + this.apiColor.b, + this.apiColor.a ); - 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,11 +51,17 @@ R3.Color.prototype.constructor = R3.Color; * @returns {*} */ R3.Color.prototype.createInstance = function() { - this.instance = new THREE.Color( - this.r, - this.g, - this.b - ); + + switch (this.componentRuntime) { + case R3.Component.GRAPHICS_RUNTIME : + this.instance = this.graphics.Color( + this.r, + this.g, + this.b, + this.a + ); + break; + } }; /** diff --git a/src/r3-d3-api-a-object.js b/src/r3-d3-api-a-object.js index aa5fbb1..2974177 100644 --- a/src/r3-d3-api-a-object.js +++ b/src/r3-d3-api-a-object.js @@ -1,9 +1,6 @@ /** * R3.D3.API.Object - * @param id - * @param name - * @param objectType - * @param parent + * @param apiComponent * @param useQuaternion * @param position * @param quaternion @@ -14,10 +11,7 @@ * @constructor */ R3.D3.API.Object = function( - id, - name, - objectType, - parent, + apiComponent, useQuaternion, position, quaternion, @@ -26,56 +20,8 @@ R3.D3.API.Object = function( up, lookAt ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(objectType)) { - objectType = 0; - } - this.objectType = objectType; - - if (R3.Utils.UndefinedOrNull(name)) { - switch (this.objectType) { - case R3.D3.API.Object.OBJECT_TYPE_NONE : - name = 'Object'; - break; - /** - * Cameras - */ - case R3.D3.API.Object.OBJECT_TYPE_CAMERA : - name = 'Camera'; - break; - case R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC : - name = 'Camera Orthographic'; - break; - case R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE : - name = 'Camera Perspective'; - break; - case R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE : - name = 'Camera Cube'; - break; - case R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE_STEREO : - name = 'Camera Stereo'; - break; - /** - * Meshes - */ - case R3.D3.API.Object.OBJECT_TYPE_MESH : - name = 'Mesh'; - break; - - /** - * Bones - */ - case R3.D3.API.Object.OBJECT_TYPE_BONE : - name = 'Bone'; - break; - } - name += ' (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(useQuaternion)) { useQuaternion = true; @@ -111,81 +57,8 @@ R3.D3.API.Object = function( lookAt = new R3.API.Vector3(); } this.lookAt = lookAt; - - R3.API.Component.call( - this, - R3.D3.API.Object.GetComponentType(this.objectType), - parent - ); + }; R3.D3.API.Object.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.Object.prototype.constructor = R3.D3.API.Object; - -R3.D3.API.Object.GetComponentType = function(objectType) { - - var componentType = null; - - switch (objectType) { - case R3.D3.API.Object.OBJECT_TYPE_NONE : - componentType = R3.Component.OBJECT; - break; - /** - * Cameras - */ - case R3.D3.API.Object.OBJECT_TYPE_CAMERA : - componentType = R3.Component.CAMERA; - break; - case R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE : - componentType = R3.Component.CAMERA_PERSPECTIVE; - break; - case R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC : - componentType = R3.Component.CAMERA_ORTHOGRAPHIC; - break; - case R3.D3.API.Object.OBJECT_TYPE_CAMERA_STEREO : - componentType = R3.Component.CAMERA_PERSPECTIVE_STEREO; - break; - case R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE : - componentType = R3.Component.CAMERA_CUBE; - break; - /** - * Meshes - */ - case R3.D3.API.Object.OBJECT_TYPE_MESH : - componentType = R3.Component.MESH; - break; - /** - * Bones - */ - case R3.D3.API.Object.OBJECT_TYPE_BONE : - componentType = R3.Component.BONE; - break; - default: - throw new Error('unsupported camera type: ' + objectType); - } - - return componentType; -}; - -R3.D3.API.Object.OBJECT_TYPE_NONE = 0x0; - -/** - * Cameras - * @type {number} - */ -R3.D3.API.Object.OBJECT_TYPE_CAMERA = 0x11; -R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE = 0x12;//0x1; -R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC = 0x13;//0x2; -R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE_STEREO = 0x14;//0x3; -R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE = 0x15;//0x4; - -/** - * Meshes - * @type {number} - */ -R3.D3.API.Object.OBJECT_TYPE_MESH = 0x21; - -/** - * Bones - */ -R3.D3.API.Object.OBJECT_TYPE_BONE = 0x31; \ No newline at end of file diff --git a/src/r3-d3-api-animation.js b/src/r3-d3-api-animation.js index 4ad3222..63761e8 100644 --- a/src/r3-d3-api-animation.js +++ b/src/r3-d3-api-animation.js @@ -1,7 +1,6 @@ /** - * Animation Component - * @param id - * @param name + * R3.D3.API.Animation + * @param apiComponent * @param rotationSpeed * @param translationSpeed * @param scaleSpeed @@ -10,13 +9,10 @@ * @param scaleFn * @param blocking * @param applyToMeshWhenDone - * @param meshes - * @param parent * @constructor */ R3.D3.API.Animation = function( - id, - name, + apiComponent, rotationSpeed, translationSpeed, scaleSpeed, @@ -24,19 +20,10 @@ R3.D3.API.Animation = function( translationFn, scaleFn, blocking, - applyToMeshWhenDone, - meshes, - parent + applyToMeshWhenDone ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Animation (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(rotationSpeed)) { rotationSpeed = 0; @@ -82,40 +69,7 @@ R3.D3.API.Animation = function( } this.applyToMeshWhenDone = applyToMeshWhenDone; - if (R3.Utils.UndefinedOrNull(meshes)) { - meshes = []; - } - this.meshes = meshes; - - R3.API.Component.call( - this, - R3.Component.ANIMATION, - parent - ); }; R3.D3.API.Animation.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.Animation.prototype.constructor = R3.D3.API.Animation; - -/** - * Object to R3.D3.API.Animation - * @param objectComponent - * @returns {R3.D3.API.Animation} - * @constructor - */ -R3.D3.API.Animation.FromObject = function(objectComponent) { - return new R3.D3.API.Animation( - objectComponent.id, - objectComponent.name, - objectComponent.rotationSpeed, - objectComponent.translationSpeed, - objectComponent.scaleSpeed, - objectComponent.rotationFn, - objectComponent.translationFn, - objectComponent.scaleFn, - objectComponent.blocking, - objectComponent.applyToMeshWhenDone, - objectComponent.meshes, - objectComponent.parent - ); -}; diff --git a/src/r3-d3-api-audio.js b/src/r3-d3-api-audio.js index acb3dbf..8719e57 100644 --- a/src/r3-d3-api-audio.js +++ b/src/r3-d3-api-audio.js @@ -1,37 +1,25 @@ /** - * Raw Audio API object - should always correspond with the Audio Schema - * @param id - * @param name + * R3.D3.API.Audio + * @param apiComponent * @param path * @param loop * @param volume * @param camera * @param overplay * @param paused - * @param parent * @constructor */ R3.D3.API.Audio = function( - id, - name, + apiComponent, path, loop, volume, camera, overplay, - paused, - parent + paused ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Audio (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(path)) { path = ''; @@ -63,42 +51,7 @@ R3.D3.API.Audio = function( } this.paused = paused; - R3.API.Component.call( - this, - R3.Component.AUDIO, - parent - ); }; R3.D3.API.Audio.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.Audio.prototype.constructor = R3.D3.API.Audio; - -/** - * Creates an API Audio from an Object Audio - * @param objectAudio - * @constructor - */ -R3.D3.API.Audio.FromObject = function(objectAudio) { - - var apiCamera = null; - if (objectAudio.camera) { - if (objectAudio.camera instanceof Object) { - apiCamera = R3.D3.API.Camera.FromObject(objectAudio.camera); - } else { - apiCamera = objectAudio.camera; - } - } - - return new R3.D3.API.Audio( - objectAudio.id, - objectAudio.name, - objectAudio.path, - objectAudio.loop, - objectAudio.volume, - apiCamera, - objectAudio.overplay, - objectAudio.paused, - objectAudio.parent - ); - -}; diff --git a/src/r3-d3-api-bone.js b/src/r3-d3-api-bone.js index dd16415..19a58f7 100644 --- a/src/r3-d3-api-bone.js +++ b/src/r3-d3-api-bone.js @@ -12,14 +12,21 @@ R3.D3.API.Bone = function( ) { if (R3.Utils.UndefinedOrNull(apiD3Object)) { - apiD3Object = { - objectType : R3.D3.API.Object.OBJECT_TYPE_BONE - }; + apiD3Object = {}; } + this.apiD3Object = apiD3Object; - if (R3.Utils.UndefinedOrNull(apiD3Object.objectType)) { - apiD3Object.objectType = R3.D3.API.Object.OBJECT_TYPE_BONE; - } + R3.D3.API.Object.call( + this, + this.apiD3Object, + this.apiD3Object.useQuaternion, + this.apiD3Object.position, + this.apiD3Object.quaternion, + this.apiD3Object.rotation, + this.apiD3Object.scale, + this.apiD3Object.up, + this.apiD3Object.lookAt + ); if (R3.Utils.UndefinedOrNull(childBoneIds)) { childBoneIds = []; @@ -31,20 +38,6 @@ R3.D3.API.Bone = function( } this.parentBoneIds = parentBoneIds; - R3.D3.API.Object.call( - this, - apiD3Object.id, - apiD3Object.name, - apiD3Object.objectType, - apiD3Object.parent, - apiD3Object.useQuaternion, - apiD3Object.position, - apiD3Object.quaternion, - apiD3Object.rotation, - apiD3Object.scale, - apiD3Object.up, - apiD3Object.lookAt - ); }; R3.D3.API.Bone.prototype = Object.create(R3.D3.API.Object.prototype); diff --git a/src/r3-d3-api-broadphase.js b/src/r3-d3-api-broadphase.js index 63e46bc..8570921 100644 --- a/src/r3-d3-api-broadphase.js +++ b/src/r3-d3-api-broadphase.js @@ -1,54 +1,22 @@ /** * Raw Broadphase API object - should always correspond with the Broadphase Schema - * @param id - * @param name + * @param apiComponent * @param broadphaseType - * @param parent * @constructor */ R3.D3.API.Broadphase = function( - id, - name, - broadphaseType, - parent + apiComponent, + broadphaseType ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Broadphase (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(broadphaseType)) { broadphaseType = R3.D3.Broadphase.BROADPHASE_TYPE_NAIVE; } this.broadphaseType = broadphaseType; - R3.API.Component.call( - this, - R3.Component.BROADPHASE, - parent - ); }; R3.D3.API.Broadphase.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.Broadphase.prototype.constructor = R3.D3.API.Broadphase; - -/** - * Creates an API Broadphase from an Object Broadphase - * @param objectBroadphase - * @constructor - */ -R3.D3.API.Broadphase.FromObject = function(objectBroadphase) { - return new R3.D3.API.Broadphase( - objectBroadphase.id, - objectBroadphase.name, - objectBroadphase.broadphaseType, - objectBroadphase.parent - ); -}; - diff --git a/src/r3-d3-api-camera-a.js b/src/r3-d3-api-camera-a.js index 4a3e0e2..d8c3cc0 100644 --- a/src/r3-d3-api-camera-a.js +++ b/src/r3-d3-api-camera-a.js @@ -10,19 +10,9 @@ R3.D3.API.Camera = function( ) { if (R3.Utils.UndefinedOrNull(apiD3Object)) { - apiD3Object = { - objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA - }; + apiD3Object = {}; } - - if (R3.Utils.UndefinedOrNull(apiD3Object.objectType)) { - apiD3Object.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA; - } - - if (R3.Utils.UndefinedOrNull(aspect)) { - aspect = 1; - } - this.aspect = aspect; + this.apiD3Object = apiD3Object; if (R3.Utils.UndefinedOrNull(apiD3Object.position)) { apiD3Object.position = new R3.API.Vector3( @@ -34,19 +24,28 @@ R3.D3.API.Camera = function( R3.D3.API.Object.call( this, - apiD3Object.id, - apiD3Object.name, - apiD3Object.objectType, - apiD3Object.parent, - apiD3Object.useQuaternion, - apiD3Object.position, - apiD3Object.quaternion, - apiD3Object.rotation, - apiD3Object.scale, - apiD3Object.up, - apiD3Object.lookAt + this.apiD3Object, + this.apiD3Object.useQuaternion, + this.apiD3Object.position, + this.apiD3Object.quaternion, + this.apiD3Object.rotation, + this.apiD3Object.scale, + this.apiD3Object.up, + this.apiD3Object.lookAt ); + + if (R3.Utils.UndefinedOrNull(aspect)) { + aspect = 1; + } + this.aspect = aspect; + }; R3.D3.API.Camera.prototype = Object.create(R3.D3.API.Object.prototype); R3.D3.API.Camera.prototype.constructor = R3.D3.API.Camera; + +R3.D3.API.Camera.ASPECT_RATIO_1_1 = 0x1; +R3.D3.API.Camera.ASPECT_RATIO_3_2 = 0x2; +R3.D3.API.Camera.ASPECT_RATIO_4_3 = 0x3; +R3.D3.API.Camera.ASPECT_RATIO_16_9 = 0x4; +R3.D3.API.Camera.ASPECT_RATIO_16_10 = 0x5; \ No newline at end of file diff --git a/src/r3-d3-api-camera-cube.js b/src/r3-d3-api-camera-cube.js index 48a7c85..41b225b 100644 --- a/src/r3-d3-api-camera-cube.js +++ b/src/r3-d3-api-camera-cube.js @@ -1,29 +1,33 @@ /** * R3.D3.API.Camera.Cube + * + * CubeCamera's have hardcoded fov=90 and aspect=1 + * * @constructor - * @param apiD3ObjectCamera + * @param apiD3Camera * @param near * @param far * @param cubeResolution * @param renderTarget */ R3.D3.API.Camera.Cube = function( - apiD3ObjectCamera, + apiD3Camera, near, far, cubeResolution, renderTarget ) { - if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera)) { - apiD3ObjectCamera = { - objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE - }; + if (R3.Utils.UndefinedOrNull(apiD3Camera)) { + apiD3Camera = {}; } + this.apiD3Camera = apiD3Camera; - if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) { - apiD3ObjectCamera.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA_CUBE; - } + R3.D3.API.Camera.call( + this, + this.apiD3Camera, + this.apiD3Camera.aspect + ); if (R3.Utils.UndefinedOrNull(near)) { near = 0.1; @@ -45,14 +49,6 @@ R3.D3.API.Camera.Cube = function( } this.renderTarget = renderTarget; - /** - * CubeCamera's have hardcoded fov=90 and aspect=1 - */ - R3.D3.API.Camera.call( - this, - apiD3ObjectCamera, - apiD3ObjectCamera.aspect - ); }; R3.D3.API.Camera.Cube.prototype = Object.create(R3.D3.API.Camera.prototype); diff --git a/src/r3-d3-api-camera-orthographic-fixed-aspect.js b/src/r3-d3-api-camera-orthographic-fixed-aspect.js new file mode 100644 index 0000000..f06c5cb --- /dev/null +++ b/src/r3-d3-api-camera-orthographic-fixed-aspect.js @@ -0,0 +1,37 @@ +/** + * R3.D3.API.Camera.Orthographic.FixedAspect + * + * This camera calculates left, right, top and bottom coordinates from the provided aspect ratio. It uses the inherited + * default values for near and far values for the Z space + * + * @param apiD3CameraOrthographic + * @param aspectRatio + * @constructor + */ +R3.D3.API.Camera.Orthographic.FixedAspect = function( + apiD3CameraOrthographic, + aspectRatio +) { + + if (R3.Utils.UndefinedOrNull(apiD3CameraOrthographic)) { + apiD3CameraOrthographic = {}; + } + this.apiD3CameraOrthographic = apiD3CameraOrthographic; + + R3.D3.API.Camera.Orthographic.call( + this, + this.apiD3CameraOrthographic, + this.apiD3CameraOrthographic.near, + this.apiD3CameraOrthographic.far, + this.apiD3CameraOrthographic.zoom + ); + + if (R3.Utils.UndefinedOrNull(aspectRatio)) { + aspectRatio = R3.D3.API.Camera.ASPECT_RATIO_1_1; + } + this.aspectRatio = aspectRatio; + +}; + +R3.D3.API.Camera.Orthographic.FixedAspect.prototype = Object.create(R3.D3.API.Camera.Orthographic.prototype); +R3.D3.API.Camera.Orthographic.FixedAspect.prototype.constructor = R3.D3.API.Camera.Orthographic.FixedAspect; diff --git a/src/r3-d3-api-camera-orthographic-zoomed-aspect.js b/src/r3-d3-api-camera-orthographic-zoomed-aspect.js new file mode 100644 index 0000000..374b249 --- /dev/null +++ b/src/r3-d3-api-camera-orthographic-zoomed-aspect.js @@ -0,0 +1,59 @@ +/** + * R3.D3.API.Camera.Orthographic.ZoomedAspect + * + * This camera does not automatically adjust its left, right, top and bottom values - it assumes they have been defined + * and are correct. It uses the inherited default near and far values for the Z space. It essentially ignores aspect + * ratio (you should manage that yourself to get things looking pretty) + * + * @param apiD3CameraOrthographic + * @param left + * @param right + * @param top + * @param bottom + * @constructor + */ +R3.D3.API.Camera.Orthographic.ZoomedAspect = function( + apiD3CameraOrthographic, + left, + right, + top, + bottom +) { + + if (R3.Utils.UndefinedOrNull(apiD3CameraOrthographic)) { + apiD3CameraOrthographic = {}; + } + this.apiD3CameraOrthographic = apiD3CameraOrthographic; + + R3.D3.API.Camera.Orthographic.call( + this, + this.apiD3CameraOrthographic, + this.apiD3CameraOrthographic.near, + this.apiD3CameraOrthographic.far, + this.apiD3CameraOrthographic.zoom + ); + + if (R3.Utils.UndefinedOrNull(left)) { + left = -5; + } + this.left = left; + + if (R3.Utils.UndefinedOrNull(right)) { + right = 5; + } + this.right = right; + + if (R3.Utils.UndefinedOrNull(top)) { + top = 5; + } + this.top = top; + + if (R3.Utils.UndefinedOrNull(bottom)) { + bottom = -5; + } + this.bottom = bottom; + +}; + +R3.D3.API.Camera.Orthographic.ZoomedAspect.prototype = Object.create(R3.D3.API.Camera.Orthographic.prototype); +R3.D3.API.Camera.Orthographic.ZoomedAspect.prototype.constructor = R3.D3.API.Camera.Orthographic.ZoomedAspect; diff --git a/src/r3-d3-api-camera-orthographic.js b/src/r3-d3-api-camera-orthographic.js index b8611d1..a10492f 100644 --- a/src/r3-d3-api-camera-orthographic.js +++ b/src/r3-d3-api-camera-orthographic.js @@ -1,98 +1,48 @@ /** * R3.D3.API.Camera.Orthographic * - * OK - since the introduction of fixed aspect ratio's for our canvases, we only need to know - * the aspect ratio and width - then we calculate the left, right, up and down coords - - * - * for the Z space - we simply use the values in near and far - you should know what you are doing when you - * create an orthographic camera - * - * There are two ways to update the camera - one is by affecting the aspect ratio - the other is modifying the left, - * right, top and bottom values - this also affects the aspect ratio. - * - * In both modes - the camera is assumed to be at position 0,0,10 and facing direction 0,0,-1 (in the positive Z facing - * the negative Z direction seeing what happens around the origin) - * - * Also - the offset is always respected + * Base class for Orthographic Cameras - do define an aspect ratio for the camera, use FixedAspect child class, to + * manually set the camera size, use the ZoomedAspect child class * * @constructor - * @param apiD3ObjectCamera - * @param aspectRatioMode - * @param minWidth - * @param minHeight - * @param width - * @param height + * @param apiD3Camera * @param near * @param far - * @param left - * @param right - * @param top - * @param bottom * @param zoom */ R3.D3.API.Camera.Orthographic = function( - apiD3ObjectCamera, - aspectRatioMode, - minWidth, - minHeight, - width, - height, + apiD3Camera, near, far, - left, - right, - top, - bottom, zoom ) { - if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera)) { - apiD3ObjectCamera = { - objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC - }; + if (R3.Utils.UndefinedOrNull(apiD3Camera)) { + apiD3Camera = {}; + } + this.apiD3Camera = apiD3Camera; + + if (R3.Utils.UndefinedOrNull(this.apiD3Camera.position)) { + this.apiD3Camera.position = new R3.API.Vector3( + 0, + 0, + 10 + ); } - if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) { - apiD3ObjectCamera.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC; + if (R3.Utils.UndefinedOrNull(this.apiD3Camera.lookAt)) { + this.apiD3Camera.lookAt = new R3.API.Vector3( + 0, + 0, + -10 + ); } - if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.position)) { - apiD3ObjectCamera.position = new R3.API.Vector3(0,0,10); - } - - if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.lookAt)) { - apiD3ObjectCamera.lookAt = new R3.API.Vector3(0,0,-10); - } - - if (R3.Utils.UndefinedOrNull(aspectRatioMode)) { - aspectRatioMode = R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT; - } - this.aspectRatioMode = aspectRatioMode; - - if (R3.Utils.UndefinedOrNull(minWidth)) { - minWidth = 10; - } - this.minWidth = minWidth; - - if (R3.Utils.UndefinedOrNull(minHeight)) { - minHeight = 10; - } - this.minHeight = minHeight; - - if (R3.Utils.UndefinedOrNull(height)) { - height = 10; - } - this.height = height; - - if (R3.Utils.UndefinedOrNull(width)) { - width = 10; - } - this.width = width; - - if (R3.Utils.UndefinedOrNull(height)) { - height = 10; - } - this.height = height; + R3.D3.API.Camera.call( + this, + this.apiD3Camera, + this.apiD3Camera.aspect + ); if (R3.Utils.UndefinedOrNull(near)) { near = 0.1; @@ -104,41 +54,12 @@ R3.D3.API.Camera.Orthographic = function( } this.far = far; - if (R3.Utils.UndefinedOrNull(left)) { - left = -5; - } - this.left = left; - - if (R3.Utils.UndefinedOrNull(right)) { - right = 5; - } - this.right = right; - - if (R3.Utils.UndefinedOrNull(top)) { - top = 5; - } - this.top = top; - - if (R3.Utils.UndefinedOrNull(bottom)) { - bottom = -5; - } - this.bottom = bottom; - if (R3.Utils.UndefinedOrNull(zoom)) { zoom = 1; } this.zoom = zoom; - R3.D3.API.Camera.call( - this, - apiD3ObjectCamera, - apiD3ObjectCamera.aspect - ); }; R3.D3.API.Camera.Orthographic.prototype = Object.create(R3.D3.API.Camera.prototype); R3.D3.API.Camera.Orthographic.prototype.constructor = R3.D3.API.Camera.Orthographic; - -R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE = 0x0; -R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED = 0x1; -R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT = 0x2; diff --git a/src/r3-d3-api-camera-perspective-stereo.js b/src/r3-d3-api-camera-perspective-stereo.js index 7dd19fe..23e5be5 100644 --- a/src/r3-d3-api-camera-perspective-stereo.js +++ b/src/r3-d3-api-camera-perspective-stereo.js @@ -1,40 +1,36 @@ /** * R3.D3.API.Camera.Perspective.Stereo * @constructor - * @param apiD3ObjectCameraPerspective + * @param apiD3CameraPerspective * @param stereoMode */ R3.D3.API.Camera.Perspective.Stereo = function( - apiD3ObjectCameraPerspective, + apiD3CameraPerspective, stereoMode ) { - if (R3.Utils.UndefinedOrNull(apiD3ObjectCameraPerspective)) { - apiD3ObjectCameraPerspective = { - objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE_STEREO - }; + if (R3.Utils.UndefinedOrNull(apiD3CameraPerspective)) { + apiD3CameraPerspective = {}; } + this.apiD3CameraPerspective = apiD3CameraPerspective; - if (R3.Utils.UndefinedOrNull(apiD3ObjectCameraPerspective.objectType)) { - apiD3ObjectCameraPerspective.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE_STEREO; - } + R3.D3.API.Camera.Perspective.call( + this, + this.apiD3CameraPerspective, + this.apiD3CameraPerspective.near, + this.apiD3CameraPerspective.far, + this.apiD3CameraPerspective.fov, + this.apiD3CameraPerspective.filmGauge, + this.apiD3CameraPerspective.filmOffset, + this.apiD3CameraPerspective.focus, + this.apiD3CameraPerspective.zoom + ); if (R3.Utils.UndefinedOrNull(stereoMode)) { stereoMode = R3.D3.API.Camera.Perspective.Stereo.STEREO_MODE_STEREO; } this.stereoMode = stereoMode; - R3.D3.API.Camera.Perspective.call( - this, - apiD3ObjectCameraPerspective, - apiD3ObjectCameraPerspective.near, - apiD3ObjectCameraPerspective.far, - apiD3ObjectCameraPerspective.fov, - apiD3ObjectCameraPerspective.filmGauge, - apiD3ObjectCameraPerspective.filmOffset, - apiD3ObjectCameraPerspective.focus, - apiD3ObjectCameraPerspective.zoom - ); }; R3.D3.API.Camera.Perspective.Stereo.prototype = Object.create(R3.D3.API.Camera.Perspective.prototype); diff --git a/src/r3-d3-api-camera-perspective.js b/src/r3-d3-api-camera-perspective.js index ad79bfc..67cfb7d 100644 --- a/src/r3-d3-api-camera-perspective.js +++ b/src/r3-d3-api-camera-perspective.js @@ -1,7 +1,7 @@ /** * R3.D3.API.Camera.Perspective * @constructor - * @param apiD3ObjectCamera + * @param apiD3Camera * @param fov * @param near * @param far @@ -11,7 +11,7 @@ * @param zoom */ R3.D3.API.Camera.Perspective = function( - apiD3ObjectCamera, + apiD3Camera, near, far, fov, @@ -21,64 +21,53 @@ R3.D3.API.Camera.Perspective = function( zoom ) { - if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera)) { - apiD3ObjectCamera = { - objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE - }; + if (R3.Utils.UndefinedOrNull(apiD3Camera)) { + apiD3Camera = {}; } + this.apiD3Camera = apiD3Camera; - if (R3.Utils.UndefinedOrNull(apiD3ObjectCamera.objectType)) { - apiD3ObjectCamera.objectType = R3.D3.API.Object.OBJECT_TYPE_CAMERA_PERSPECTIVE; - } + R3.D3.API.Camera.call( + this, + this.apiD3Camera, + this.apiD3Camera.aspect + ); if (R3.Utils.UndefinedOrNull(near)) { - // near = new R3.API.Number(0.1, 0.001, 0.001, 2000); near = 0.1; } this.near = near; if (R3.Utils.UndefinedOrNull(far)) { - // far = new R3.API.Number(2000, 1, 1, 4000); far = 2000; } this.far = far; if (R3.Utils.UndefinedOrNull(fov)) { - // fov = new R3.API.Number(50, 1, 0, 180); fov = 50; } this.fov = fov; if (R3.Utils.UndefinedOrNull(filmGauge)) { - // filmGauge = new R3.API.Number(35, 1, 0, 200); filmGauge = 35; } this.filmGauge = filmGauge; if (R3.Utils.UndefinedOrNull(filmOffset)) { - // filmOffset = new R3.API.Number(0, 1, 0, 200); filmOffset = 0; } this.filmOffset = filmOffset; if (R3.Utils.UndefinedOrNull(focus)) { - // focus = new R3.API.Number(10, 0.1, 0, 200); focus = 10; } this.focus = focus; if (R3.Utils.UndefinedOrNull(zoom)) { - // zoom = new R3.API.Number(1, 0.01, 0, 10); zoom = 1; } this.zoom = zoom; - R3.D3.API.Camera.call( - this, - apiD3ObjectCamera, - apiD3ObjectCamera.aspect - ); }; R3.D3.API.Camera.Perspective.prototype = Object.create(R3.D3.API.Camera.prototype); -R3.D3.API.Camera.Perspective.prototype.constructor = R3.D3.API.Camera.Perspective; \ No newline at end of file +R3.D3.API.Camera.Perspective.prototype.constructor = R3.D3.API.Camera.Perspective; diff --git a/src/r3-d3-api-composer.js b/src/r3-d3-api-composer.js index f846a24..23b0de1 100644 --- a/src/r3-d3-api-composer.js +++ b/src/r3-d3-api-composer.js @@ -1,42 +1,21 @@ /** * R3.D3.API.Composer - * @param id - * @param name - * @param parent + * @param apiComponent * @param autoUpdateSize * @param width * @param height - * @param renderer - * @param renderTarget * @param passes * @constructor */ R3.D3.API.Composer = function( - parent, - id, - name, + apiComponent, autoUpdateSize, width, height, - renderer, - renderTarget, passes ) { - if (R3.Utils.UndefinedOrNull(parent)) { - parent = null; - } - this.parent = parent; - - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Composer (' + id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(autoUpdateSize)) { autoUpdateSize = true; @@ -53,32 +32,11 @@ R3.D3.API.Composer = function( } this.height = height; - if (R3.Utils.UndefinedOrNull(renderer)) { - - if (this.parent && this.parent.parent.renderer) { - renderer = this.parent.parent.renderer; - } else { - renderer = null; - } - - } - this.renderer = renderer; - - if (R3.Utils.UndefinedOrNull(renderTarget)) { - renderTarget = null; - } - this.renderTarget = renderTarget; - if (R3.Utils.UndefinedOrNull(passes)) { passes = []; } this.passes = passes; - R3.API.Component.call( - this, - R3.Component.COMPOSER, - parent - ); }; R3.D3.API.Composer.prototype = Object.create(R3.API.Component.prototype); diff --git a/src/r3-d3-api-effect-a.js b/src/r3-d3-api-effect-a.js index 0688bf3..b8fd240 100644 --- a/src/r3-d3-api-effect-a.js +++ b/src/r3-d3-api-effect-a.js @@ -1,10 +1,6 @@ /** * R3.D3.API.Effect - * @param id - * @param name - * @param effectType - * @param parent - * @param renderer + * @param apiComponent * @param width * @param height * @@ -13,50 +9,12 @@ * @constructor */ R3.D3.API.Effect = function( - id, - name, - effectType, - parent, - renderer, + apiComponent, width, height ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(effectType)) { - effectType = R3.D3.API.Effect.EFFECT_TYPE_NONE; - } - this.effectType = effectType; - - if (R3.Utils.UndefinedOrNull(name)) { - - switch (this.effectType) { - case R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH : - name = 'Effect Anaglyph'; - break; - case R3.D3.API.Effect.EFFECT_TYPE_PARALLAX : - name = 'Effect Parallax'; - break; - case R3.D3.API.Effect.EFFECT_TYPE_STEREO : - name = 'Effect Stereo'; - break; - default : - console.warn('no nice name for effect'); - name = 'Effect'; - } - - name += ' (' + this.id + ')'; - } - this.name = name; - - if (R3.Utils.UndefinedOrNull(renderer)) { - renderer = null; - } - this.renderer = renderer; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(width)) { width = 512; @@ -67,34 +25,7 @@ R3.D3.API.Effect = function( height = 512; } this.height = height; - - var componentType = null; - - switch (this.effectType) { - case R3.D3.API.Effect.EFFECT_TYPE_STEREO : - componentType = R3.Component.EFFECT_STEREO; - break; - case R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH : - componentType = R3.Component.EFFECT_ANAGLYPH; - break; - case R3.D3.API.Effect.EFFECT_TYPE_PARALLAX : - componentType = R3.Component.EFFECT_PARALLAX; - break; - default: - throw new Error('unsupported effect type: ' + this.effectType); - } - - R3.API.Component.call( - this, - componentType, - parent - ); }; R3.D3.API.Effect.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.Effect.prototype.constructor = R3.D3.API.Effect; - -R3.D3.API.Effect.EFFECT_TYPE_NONE = 0x0; -R3.D3.API.Effect.EFFECT_TYPE_STEREO = 0x1; -R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH = 0x2; -R3.D3.API.Effect.EFFECT_TYPE_PARALLAX = 0x3; diff --git a/src/r3-d3-api-effect-anaglyph.js b/src/r3-d3-api-effect-anaglyph.js index 509f471..f02a30a 100644 --- a/src/r3-d3-api-effect-anaglyph.js +++ b/src/r3-d3-api-effect-anaglyph.js @@ -8,27 +8,18 @@ R3.D3.API.Effect.Anaglyph = function( ) { if (R3.Utils.UndefinedOrNull(apiEffect)) { - apiEffect = { - effectType : R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH - }; - } - - if (R3.Utils.UndefinedOrNull(apiEffect.cameraType)) { - apiEffect.effectType = R3.D3.API.Effect.EFFECT_TYPE_ANAGLYPH; + apiEffect = {}; } + this.apiEffect = apiEffect; R3.D3.API.Effect.call( this, - apiEffect.id, - apiEffect.name, - apiEffect.effectType, - apiEffect.parent, - apiEffect.renderer, - apiEffect.width, - apiEffect.height + this.apiEffect, + this.apiEffect.width, + this.apiEffect.height ); }; R3.D3.API.Effect.Anaglyph.prototype = Object.create(R3.D3.API.Effect.prototype); -R3.D3.API.Effect.Anaglyph.prototype.constructor = R3.D3.API.Effect.Anaglyph; \ No newline at end of file +R3.D3.API.Effect.Anaglyph.prototype.constructor = R3.D3.API.Effect.Anaglyph; diff --git a/src/r3-d3-api-effect-parallax.js b/src/r3-d3-api-effect-parallax.js index 868cfe6..f73060c 100644 --- a/src/r3-d3-api-effect-parallax.js +++ b/src/r3-d3-api-effect-parallax.js @@ -8,24 +8,15 @@ R3.D3.API.Effect.Parallax = function( ) { if (R3.Utils.UndefinedOrNull(apiEffect)) { - apiEffect = { - effectType : R3.D3.API.Effect.EFFECT_TYPE_PARALLAX - }; - } - - if (R3.Utils.UndefinedOrNull(apiEffect.cameraType)) { - apiEffect.effectType = R3.D3.API.Effect.EFFECT_TYPE_PARALLAX; + apiEffect = {}; } + this.apiEffect = apiEffect; R3.D3.API.Effect.call( this, - apiEffect.id, - apiEffect.name, - apiEffect.effectType, - apiEffect.parent, - apiEffect.renderer, - apiEffect.width, - apiEffect.height + this.apiEffect, + this.apiEffect.width, + this.apiEffect.height ); }; diff --git a/src/r3-d3-api-effect-stereo.js b/src/r3-d3-api-effect-stereo.js index 319ab88..c5913c8 100644 --- a/src/r3-d3-api-effect-stereo.js +++ b/src/r3-d3-api-effect-stereo.js @@ -10,31 +10,22 @@ R3.D3.API.Effect.Stereo = function( ) { if (R3.Utils.UndefinedOrNull(apiEffect)) { - apiEffect = { - effectType : R3.D3.API.Effect.EFFECT_TYPE_STEREO - }; + apiEffect = {}; } + this.apiEffect = apiEffect; - if (R3.Utils.UndefinedOrNull(apiEffect.cameraType)) { - apiEffect.effectType = R3.D3.API.Effect.EFFECT_TYPE_STEREO; - } + R3.D3.API.Effect.call( + this, + this.apiEffect, + this.apiEffect.width, + this.apiEffect.height + ); if (R3.Utils.UndefinedOrNull(eyeSeperation)) { eyeSeperation = 0.064; } this.eyeSeperation = eyeSeperation; - R3.D3.API.Effect.call( - this, - apiEffect.id, - apiEffect.name, - apiEffect.effectType, - apiEffect.parent, - apiEffect.renderer, - apiEffect.width, - apiEffect.height - ); - }; R3.D3.API.Effect.Stereo.prototype = Object.create(R3.D3.API.Effect.prototype); diff --git a/src/r3-d3-api-face.js b/src/r3-d3-api-face.js index 86255ea..7354ba3 100644 --- a/src/r3-d3-api-face.js +++ b/src/r3-d3-api-face.js @@ -1,7 +1,6 @@ /** - * Face - * @param id - * @param name + * R3.D3.API.Face + * @param apiComponent * @param v0index * @param v1index * @param v2index @@ -12,13 +11,10 @@ * @param vertexNormals * @param normal * @param selected - * @param parentGeometry - * @param parent * @constructor */ R3.D3.API.Face = function( - id, - name, + apiComponent, v0index, v1index, v2index, @@ -28,20 +24,10 @@ R3.D3.API.Face = function( vertexColors, vertexNormals, normal, - selected, - parentGeometry, - parent + selected ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Face ' + id; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(v0index)) { v0index = -1; @@ -69,15 +55,15 @@ R3.D3.API.Face = function( this.uvs = uvs; if (R3.Utils.UndefinedOrNull(color)) { - color = new R3.API.Color(this); + color = new R3.API.Color(); } this.color = color; if (R3.Utils.UndefinedOrNull(vertexColors)) { vertexColors = [ - new R3.API.Color(this), - new R3.API.Color(this), - new R3.API.Color(this) + new R3.API.Color(), + new R3.API.Color(), + new R3.API.Color() ]; } this.vertexColors = vertexColors; @@ -97,16 +83,6 @@ R3.D3.API.Face = function( } this.selected = selected; - if (R3.Utils.UndefinedOrNull(parentGeometry)) { - parentGeometry = null; - } - this.parentGeometry = parentGeometry; - - R3.API.Component.call( - this, - R3.Component.FACE, - parent - ); }; /** @@ -116,75 +92,13 @@ R3.D3.API.Face = function( R3.D3.API.Face.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.Face.prototype.constructor = R3.D3.API.Face; -/** - * Returns an API Face from a data object - * @constructor - * @param objectFace - */ -// R3.D3.API.Face.FromObject = function(objectFace) { -// -// var apiUvs = objectFace.uvs.reduce( -// -// function(result, uvArray, index) { -// -// result[index] = uvArray.reduce( -// function(uvResult, uv) { -// uvResult.push(R3.API.Vector2.FromObject(uv)); -// return uvResult; -// }, -// [] -// ); -// -// return result; -// }, -// [] -// ); -// -// var apiVertexColors = objectFace.vertexColors.map( -// function(vertexColor) { -// return R3.API.Color.FromObject(vertexColor); -// } -// ); -// -// var apiColor = null; -// if (objectFace.color) { -// apiColor = R3.API.Color.FromObject(objectFace.color); -// } -// -// var apiVertexNormals = objectFace.vertexNormals.map( -// function(vertexNormal) { -// return R3.API.Vector3.FromObject(vertexNormal); -// } -// ); -// -// var apiNormal = null; -// if (objectFace.normal) { -// apiNormal = R3.API.Vector3.FromObject(objectFace.normal); -// } -// -// return new R3.D3.API.Face( -// objectFace.id, -// objectFace.name, -// objectFace.v0index, -// objectFace.v1index, -// objectFace.v2index, -// objectFace.materialIndex, -// apiUvs, -// apiColor, -// apiVertexColors, -// apiVertexNormals, -// apiNormal -// ); -// }; -// /** * Clone a Face * @returns {R3.D3.API.Face} */ R3.D3.API.Face.prototype.clone = function(){ return new R3.D3.API.Face( - this.id, - this.name, + null, this.v0index, this.v1index, this.v2index, @@ -193,7 +107,8 @@ R3.D3.API.Face.prototype.clone = function(){ this.color, this.vertexColors, this.vertexNormals, - this.normal + this.normal, + this.selected ); }; diff --git a/src/r3-d3-api-fog.js b/src/r3-d3-api-fog.js index 47cbb5f..9ff0ea0 100644 --- a/src/r3-d3-api-fog.js +++ b/src/r3-d3-api-fog.js @@ -1,35 +1,23 @@ /** - * Raw Fog API object - should always correspond with the Fog Schema - * @param id String - * @param name String + * R3.D3.API.Fog + * @param apiComponent * @param exponential * @param color * @param near * @param far * @param density - * @param parent * @constructor */ R3.D3.API.Fog = function( - id, - name, + apiComponent, exponential, color, near, far, - density, - parent + density ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Fog (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(exponential)) { exponential = false; @@ -56,11 +44,6 @@ R3.D3.API.Fog = function( } this.density = density; - R3.API.Component.call( - this, - R3.Component.FOG, - parent - ); }; R3.D3.API.Fog.prototype = Object.create(R3.API.Component.prototype); diff --git a/src/r3-d3-api-font.js b/src/r3-d3-api-font.js index 2c586d1..3cc8e2e 100644 --- a/src/r3-d3-api-font.js +++ b/src/r3-d3-api-font.js @@ -1,52 +1,22 @@ /** - * Raw Font API object - should always correspond with the Font Schema - * @param id - * @param name - * @param url - * @param parent + * R3.D3.API.Font + * @param apiComponent + * @param path - Relative to API URL * @constructor */ R3.D3.API.Font = function( - id, - name, - url, - parent + apiComponent, + path ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Font (' + id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ - if (R3.Utils.UndefinedOrNull(url)) { - url = '/apiRelative/path/to/font'; + if (R3.Utils.UndefinedOrNull(path)) { + path = ''; } - this.url = url; + this.path = path; - R3.API.Component.call( - this, - R3.Component.FONT, - parent - ); }; R3.D3.API.Font.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.Font.prototype.constructor = R3.D3.API.Font; - -/** - * Returns an API light from an Object light - * @param objectFont - * @constructor - */ -R3.D3.API.Font.FromObject = function(objectFont) { - return new R3.D3.API.Font( - objectFont.id, - objectFont.name, - objectFont.url, - objectFont.parent - ); -}; diff --git a/src/r3-d3-api-friction-contact-material.js b/src/r3-d3-api-friction-contact-material.js index ef6d3fd..70bc262 100644 --- a/src/r3-d3-api-friction-contact-material.js +++ b/src/r3-d3-api-friction-contact-material.js @@ -1,7 +1,6 @@ /** - * Raw FrictionContactMaterial API object - should always correspond with the FrictionContactMaterial Schema - * @param id - * @param name + * R3.D3.API.FrictionContactMaterial + * @param apiComponent * @param materials * @param friction * @param restitution @@ -9,31 +8,20 @@ * @param contactEquationRelaxation * @param frictionEquationStiffness * @param frictionEquationRelaxation - * @param parent * @constructor */ R3.D3.API.FrictionContactMaterial = function( - id, - name, + apiComponent, materials, friction, restitution, contactEquationStiffness, contactEquationRelaxation, frictionEquationStiffness, - frictionEquationRelaxation, - parent + frictionEquationRelaxation ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Friction Material (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(materials)) { materials = []; @@ -70,33 +58,7 @@ R3.D3.API.FrictionContactMaterial = function( } this.frictionEquationRelaxation = frictionEquationRelaxation; - R3.API.Component.call( - this, - R3.Component.FRICTION_CONTACT_MATERIAL, - parent - ); }; R3.D3.API.FrictionContactMaterial.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.FrictionContactMaterial.prototype.constructor = R3.D3.API.FrictionContactMaterial; - -/** - * Creates an API FrictionContactMaterial from an Object FrictionContactMaterial - * @param objectFrictionContactMaterial - * @constructor - */ -R3.D3.API.FrictionContactMaterial.FromObject = function(objectFrictionContactMaterial) { - return new R3.D3.API.FrictionContactMaterial( - objectFrictionContactMaterial.id, - objectFrictionContactMaterial.name, - objectFrictionContactMaterial.materials, - objectFrictionContactMaterial.friction, - objectFrictionContactMaterial.restitution, - objectFrictionContactMaterial.contactEquationStiffness, - objectFrictionContactMaterial.contactEquationRelaxation, - objectFrictionContactMaterial.frictionEquationStiffness, - objectFrictionContactMaterial.frictionEquationRelaxation, - objectFrictionContactMaterial.parent - ); -}; - diff --git a/src/r3-d3-api-friction-material.js b/src/r3-d3-api-friction-material.js index 1846ae4..a3f26ef 100644 --- a/src/r3-d3-api-friction-material.js +++ b/src/r3-d3-api-friction-material.js @@ -1,29 +1,17 @@ /** - * Raw FrictionMaterial API object - should always correspond with the FrictionMaterial Schema - * @param id - * @param name + * R3.D3.API.FrictionMaterial + * @param apiComponent * @param friction * @param restitution - * @param parent * @constructor */ R3.D3.API.FrictionMaterial = function( - id, - name, + apiComponent, friction, - restitution, - parent + restitution ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(name)) { - name = 'Friction Material (' + this.id + ')'; - } - this.name = name; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(friction)) { friction = -1; @@ -35,28 +23,7 @@ R3.D3.API.FrictionMaterial = function( } this.restitution = restitution; - R3.API.Component.call( - this, - R3.Component.FRICTION_MATERIAL, - parent - ); }; R3.D3.API.FrictionMaterial.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.FrictionMaterial.prototype.constructor = R3.D3.API.FrictionMaterial; - -/** - * Creates an API FrictionMaterial from an Object FrictionMaterial - * @param objectFrictionMaterial - * @constructor - */ -R3.D3.API.FrictionMaterial.FromObject = function(objectFrictionMaterial) { - return new R3.D3.API.FrictionMaterial( - objectFrictionMaterial.id, - objectFrictionMaterial.name, - objectFrictionMaterial.friction, - objectFrictionMaterial.restitution, - objectFrictionMaterial.parent - ); -}; - diff --git a/src/r3-d3-api-geometry-a.js b/src/r3-d3-api-geometry-a.js index 650fa3d..745a128 100644 --- a/src/r3-d3-api-geometry-a.js +++ b/src/r3-d3-api-geometry-a.js @@ -1,10 +1,6 @@ /** * R3.D3.API.Geometry - * @param id - * @param name - * @param geometryType - * @param parent - * @param parentMesh + * @param apiComponent * @param boundingBox * @param boundingSphere * @param faces @@ -12,177 +8,14 @@ * @constructor */ R3.D3.API.Geometry = function( - id, - name, - geometryType, - parent, - parentMesh, + apiComponent, boundingBox, boundingSphere, faces, vertices ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - if (R3.Utils.UndefinedOrNull(geometryType)) { - geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NONE; - } - this.geometryType = geometryType; - - if (R3.Utils.UndefinedOrNull(name)) { - - switch (this.geometryType) { - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL : - name = 'Geometry'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX : - name = 'Geometry Normal Box'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE : - name = 'Geometry Normal Circle'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE : - name = 'Geometry Normal Cone'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER : - name = 'Geometry Normal Cylinder'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON : - name = 'Geometry Normal Dodecahedron'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES : - name = 'Geometry Normal Edges'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE : - name = 'Geometry Normal Extrude'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON : - name = 'Geometry Normal Icosahedron'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE : - name = 'Geometry Normal Lathe'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON : - name = 'Geometry Normal Octahedron'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC : - name = 'Geometry Normal Parametric'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE : - name = 'Geometry Normal Plane'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON : - name = 'Geometry Normal Polyhedron'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING : - name = 'Geometry Normal Ring'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE : - name = 'Geometry Normal Shape'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE : - name = 'Geometry Normal Sphere'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON : - name = 'Geometry Normal Tetrahedron'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT : - name = 'Geometry Normal Text'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS : - name = 'Geometry Normal Torus'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT : - name = 'Geometry Normal Torus Knot'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE : - name = 'Geometry Normal Tube'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME : - name = 'Geometry Normal Wireframe'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER : - name = 'Geometry Buffer'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX : - name = 'Geometry Buffer Box'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE : - name = 'Geometry Buffer Circle'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE : - name = 'Geometry Buffer Cone'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER : - name = 'Geometry Buffer Cylinder'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON : - name = 'Geometry Buffer Dodecahedron'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE : - name = 'Geometry Buffer Extrude'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON : - name = 'Geometry Buffer Icosahedron'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE : - name = 'Geometry Buffer Lathe'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON : - name = 'Geometry Buffer Octahedron'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC : - name = 'Geometry Buffer Parametric'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE : - name = 'Geometry Buffer Plane'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON : - name = 'Geometry Buffer Polyhedron'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING : - name = 'Geometry Buffer Ring'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE : - name = 'Geometry Buffer Shape'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE : - name = 'Geometry Buffer Sphere'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON : - name = 'Geometry Buffer Tetrahedron'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT : - name = 'Geometry Buffer Text'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS : - name = 'Geometry Buffer Torus'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT : - name = 'Geometry Buffer Torus Knot'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE : - name = 'Geometry Buffer Tube'; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED : - name = 'Geometry Buffer Instanced'; - break; - default : - console.warn('no nice name for geometry'); - name = 'Geometry'; - } - - name += ' (' + id + ')'; - } - this.name = name; - - if (R3.Utils.UndefinedOrNull(parentMesh)) { - parentMesh = null; - } - this.parentMesh = parentMesh; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(boundingBox)) { boundingBox = new R3.API.Box3(); @@ -203,211 +36,7 @@ R3.D3.API.Geometry = function( vertices = []; } this.vertices = vertices; - - R3.API.Component.call( - this, - R3.D3.API.Geometry.GetComponentType(this.geometryType), - parent - ); }; R3.D3.API.Geometry.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.Geometry.prototype.constructor = R3.D3.API.Geometry; - -R3.D3.API.Geometry.GetComponentType = function(geometryType) { - - var componentType = null; - - switch (geometryType) { - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL : - componentType = R3.Component.GEOMETRY_NORMAL; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX : - componentType = R3.Component.GEOMETRY_NORMAL_BOX; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE : - componentType = R3.Component.GEOMETRY_NORMAL_CIRCLE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE : - componentType = R3.Component.GEOMETRY_NORMAL_CONE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER : - componentType = R3.Component.GEOMETRY_NORMAL_CYLINDER; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON : - componentType = R3.Component.GEOMETRY_NORMAL_DODECAHEDRON; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES : - componentType = R3.Component.GEOMETRY_NORMAL_EDGES; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE : - componentType = R3.Component.GEOMETRY_NORMAL_EXTRUDE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON : - componentType = R3.Component.GEOMETRY_NORMAL_ICOSAHEDRON; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE : - componentType = R3.Component.GEOMETRY_NORMAL_LATHE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON : - componentType = R3.Component.GEOMETRY_NORMAL_OCTAHEDRON; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC : - componentType = R3.Component.GEOMETRY_NORMAL_PARAMETRIC; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE : - componentType = R3.Component.GEOMETRY_NORMAL_PLANE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON : - componentType = R3.Component.GEOMETRY_NORMAL_POLYHEDRON; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING : - componentType = R3.Component.GEOMETRY_NORMAL_RING; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE : - componentType = R3.Component.GEOMETRY_NORMAL_SHAPE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE : - componentType = R3.Component.GEOMETRY_NORMAL_SPHERE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON : - componentType = R3.Component.GEOMETRY_NORMAL_TETRAHEDRON; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT : - componentType = R3.Component.GEOMETRY_NORMAL_TEXT; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS : - componentType = R3.Component.GEOMETRY_NORMAL_TORUS; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT : - componentType = R3.Component.GEOMETRY_NORMAL_TORUS_KNOT; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE : - componentType = R3.Component.GEOMETRY_NORMAL_TUBE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME : - componentType = R3.Component.GEOMETRY_NORMAL_WIREFRAME; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER : - componentType = R3.Component.GEOMETRY_BUFFER; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX : - componentType = R3.Component.GEOMETRY_BUFFER_BOX; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE : - componentType = R3.Component.GEOMETRY_BUFFER_CIRCLE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE : - componentType = R3.Component.GEOMETRY_BUFFER_CONE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER : - componentType = R3.Component.GEOMETRY_BUFFER_CYLINDER; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON : - componentType = R3.Component.GEOMETRY_BUFFER_DODECAHEDRON; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE : - componentType = R3.Component.GEOMETRY_BUFFER_EXTRUDE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON : - componentType = R3.Component.GEOMETRY_BUFFER_ICOSAHEDRON; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE : - componentType = R3.Component.GEOMETRY_BUFFER_LATHE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON : - componentType = R3.Component.GEOMETRY_BUFFER_OCTAHEDRON; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC: - componentType = R3.Component.GEOMETRY_BUFFER_PARAMETRIC; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE : - componentType = R3.Component.GEOMETRY_BUFFER_PLANE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON : - componentType = R3.Component.GEOMETRY_BUFFER_POLYHEDRON; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING: - componentType = R3.Component.GEOMETRY_BUFFER_RING; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE : - componentType = R3.Component.GEOMETRY_BUFFER_SHAPE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE : - componentType = R3.Component.GEOMETRY_BUFFER_SPHERE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON : - componentType = R3.Component.GEOMETRY_BUFFER_TETRAHEDRON; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT : - componentType = R3.Component.GEOMETRY_BUFFER_TEXT; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS : - componentType = R3.Component.GEOMETRY_BUFFER_TORUS; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT : - componentType = R3.Component.GEOMETRY_BUFFER_TORUS_KNOT; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE : - componentType = R3.Component.GEOMETRY_BUFFER_TUBE; - break; - case R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED : - componentType = R3.Component.GEOMETRY_BUFFER_INSTANCED; - break; - default: - throw new Error('unhandled geometry type: ' + geometryType); - } - - return componentType; -}; - -/** - * Geometry Type - * @type {number} - */ -R3.D3.API.Geometry.GEOMETRY_TYPE_NONE = 0x0; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL = 0x1; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_BOX = 0x2; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CIRCLE = 0x3; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CONE = 0x4; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_CYLINDER = 0x5; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_DODECAHEDRON = 0x6; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EDGES = 0x7; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_EXTRUDE = 0x8; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_ICOSAHEDRON = 0x9; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_LATHE = 0xa; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_OCTAHEDRON = 0xb; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC = 0xc; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE = 0xd; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON = 0xe; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING = 0xf; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE = 0x10; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE = 0x11; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON = 0x12; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT = 0x13; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS = 0x14; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TORUS_KNOT = 0x15; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TUBE = 0x16; -R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_WIREFRAME = 0x17; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER = 0x18; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX = 0x19; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE = 0x1a; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE = 0x1b; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER = 0x1c; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON = 0x1d; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE = 0x1e; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON = 0x1f; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE = 0x20; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON = 0x21; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC = 0x22; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE = 0x23; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON = 0x24; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING = 0x25; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE = 0x26; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE = 0x27; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON = 0x28; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT = 0x29; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS = 0x2a; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TORUS_KNOT = 0x2b; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TUBE = 0x2c; -R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED = 0x2d; diff --git a/src/r3-d3-api-geometry-buffer-a.js b/src/r3-d3-api-geometry-buffer-a.js index 8ef9c9c..f19f81d 100644 --- a/src/r3-d3-api-geometry-buffer-a.js +++ b/src/r3-d3-api-geometry-buffer-a.js @@ -17,14 +17,18 @@ R3.D3.API.Geometry.Buffer = function( morphAttributes ) { if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER - }; + apiGeometry = {}; } + this.apiGeometry = apiGeometry; - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER; - } + R3.D3.API.Geometry.call( + this, + this.apiGeometry, + this.apiGeometry.boundingBox, + this.apiGeometry.boundingSphere, + this.apiGeometry.faces, + this.apiGeometry.vertices + ); if (R3.Utils.UndefinedOrNull(attributes)) { attributes = []; @@ -51,18 +55,6 @@ R3.D3.API.Geometry.Buffer = function( } this.morphAttributes = morphAttributes; - R3.D3.API.Geometry.call( - this, - apiGeometry.id, - apiGeometry.name, - apiGeometry.geometryType, - apiGeometry.parent, - apiGeometry.parentMesh, - apiGeometry.boundingBox, - apiGeometry.boundingSphere, - apiGeometry.faces, - apiGeometry.vertices - ); }; R3.D3.API.Geometry.Buffer.prototype = Object.create(R3.D3.API.Geometry.prototype); diff --git a/src/r3-d3-api-geometry-buffer-box.js b/src/r3-d3-api-geometry-buffer-box.js index a61e41c..fafea83 100644 --- a/src/r3-d3-api-geometry-buffer-box.js +++ b/src/r3-d3-api-geometry-buffer-box.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Buffer.Box - * @param apiGeometry + * @param apiGeometryBuffer * @param width * @param height * @param depth @@ -10,7 +10,7 @@ * @constructor */ R3.D3.API.Geometry.Buffer.Box = function( - apiGeometry, + apiGeometryBuffer, width, height, depth, @@ -19,15 +19,7 @@ R3.D3.API.Geometry.Buffer.Box = function( depthSegments ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_BOX; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(width)) { width = 1; @@ -58,16 +50,7 @@ R3.D3.API.Geometry.Buffer.Box = function( depthSegments = 1; } this.depthSegments = depthSegments; - - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); + }; R3.D3.API.Geometry.Buffer.Box.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-circle.js b/src/r3-d3-api-geometry-buffer-circle.js index f831fb6..628c06e 100644 --- a/src/r3-d3-api-geometry-buffer-circle.js +++ b/src/r3-d3-api-geometry-buffer-circle.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Buffer.Circle - * @param apiGeometry + * @param apiGeometryBuffer * @param radius * @param segments * @param thetaStart @@ -8,22 +8,14 @@ * @constructor */ R3.D3.API.Geometry.Buffer.Circle = function( - apiGeometry, + apiGeometryBuffer, radius, segments, thetaStart, thetaLength ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CIRCLE; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(radius)) { radius = 1; @@ -44,16 +36,6 @@ R3.D3.API.Geometry.Buffer.Circle = function( thetaLength = Math.PI * 2; } this.thetaLength = thetaLength; - - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Circle.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-cone.js b/src/r3-d3-api-geometry-buffer-cone.js index 89bc745..6969b5c 100644 --- a/src/r3-d3-api-geometry-buffer-cone.js +++ b/src/r3-d3-api-geometry-buffer-cone.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Buffer.Cone - * @param apiGeometry + * @param apiGeometryBuffer * @param radius * @param height * @param radialSegments @@ -11,7 +11,7 @@ * @constructor */ R3.D3.API.Geometry.Buffer.Cone = function( - apiGeometry, + apiGeometryBuffer, radius, height, radialSegments, @@ -21,15 +21,7 @@ R3.D3.API.Geometry.Buffer.Cone = function( thetaLength ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CONE; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(radius)) { radius = 1; @@ -66,15 +58,6 @@ R3.D3.API.Geometry.Buffer.Cone = function( } this.thetaLength = thetaLength; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Cone.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-cylinder.js b/src/r3-d3-api-geometry-buffer-cylinder.js index 565c757..bd2628c 100644 --- a/src/r3-d3-api-geometry-buffer-cylinder.js +++ b/src/r3-d3-api-geometry-buffer-cylinder.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Buffer.Cylinder - * @param apiGeometry + * @param apiGeometryBuffer * @param radiusTop * @param radiusBottom * @param height @@ -12,7 +12,7 @@ * @constructor */ R3.D3.API.Geometry.Buffer.Cylinder = function( - apiGeometry, + apiGeometryBuffer, radiusTop, radiusBottom, height, @@ -23,15 +23,7 @@ R3.D3.API.Geometry.Buffer.Cylinder = function( thetaLength ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_CYLINDER; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(radiusTop)) { radiusTop = 1; @@ -73,15 +65,6 @@ R3.D3.API.Geometry.Buffer.Cylinder = function( } this.thetaLength = thetaLength; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Cylinder.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-dodecahedron.js b/src/r3-d3-api-geometry-buffer-dodecahedron.js index fd63e60..5446a5e 100644 --- a/src/r3-d3-api-geometry-buffer-dodecahedron.js +++ b/src/r3-d3-api-geometry-buffer-dodecahedron.js @@ -1,25 +1,17 @@ /** * R3.D3.API.Geometry.Buffer.Dodecahedron - * @param apiGeometry + * @param apiGeometryBuffer * @param radius * @param detail * @constructor */ R3.D3.API.Geometry.Buffer.Dodecahedron = function( - apiGeometry, + apiGeometryBuffer, radius, detail ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_DODECAHEDRON; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(radius)) { radius = 1; @@ -31,15 +23,6 @@ R3.D3.API.Geometry.Buffer.Dodecahedron = function( } this.detail = detail; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Dodecahedron.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-extrude.js b/src/r3-d3-api-geometry-buffer-extrude.js index 078e189..c2235cc 100644 --- a/src/r3-d3-api-geometry-buffer-extrude.js +++ b/src/r3-d3-api-geometry-buffer-extrude.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Buffer.Extrude - * @param apiGeometry + * @param apiGeometryBuffer * @param shapes * @param curveSegments * @param steps @@ -15,7 +15,7 @@ * @constructor */ R3.D3.API.Geometry.Buffer.Extrude = function( - apiGeometry, + apiGeometryBuffer, shapes, curveSegments, steps, @@ -29,15 +29,7 @@ R3.D3.API.Geometry.Buffer.Extrude = function( UVGenerator ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_EXTRUDE; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(shapes)) { shapes = []; @@ -89,15 +81,6 @@ R3.D3.API.Geometry.Buffer.Extrude = function( } this.UVGenerator = UVGenerator; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Extrude.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-icosahedron.js b/src/r3-d3-api-geometry-buffer-icosahedron.js index 60e2d70..328a11f 100644 --- a/src/r3-d3-api-geometry-buffer-icosahedron.js +++ b/src/r3-d3-api-geometry-buffer-icosahedron.js @@ -1,25 +1,17 @@ /** * R3.D3.API.Geometry.Buffer.Icosahedron - * @param apiGeometry + * @param apiGeometryBuffer * @param radius * @param detail * @constructor */ R3.D3.API.Geometry.Buffer.Icosahedron = function( - apiGeometry, + apiGeometryBuffer, radius, detail ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_ICOSAHEDRON; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(radius)) { radius = 1; @@ -31,15 +23,6 @@ R3.D3.API.Geometry.Buffer.Icosahedron = function( } this.detail = detail; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Icosahedron.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-instanced.js b/src/r3-d3-api-geometry-buffer-instanced.js index 420397f..6f5849a 100644 --- a/src/r3-d3-api-geometry-buffer-instanced.js +++ b/src/r3-d3-api-geometry-buffer-instanced.js @@ -1,38 +1,21 @@ /** * R3.D3.API.Geometry.Buffer.Instanced - * @param apiGeometry + * @param apiGeometryBuffer * @param maxInstancedCount * @constructor */ R3.D3.API.Geometry.Buffer.Instanced = function( - apiGeometry, + apiGeometryBuffer, maxInstancedCount ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_INSTANCED; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(maxInstancedCount)) { maxInstancedCount = null; } this.maxInstancedCount = maxInstancedCount; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Instanced.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-lathe.js b/src/r3-d3-api-geometry-buffer-lathe.js index 2c541d4..c6bd9b1 100644 --- a/src/r3-d3-api-geometry-buffer-lathe.js +++ b/src/r3-d3-api-geometry-buffer-lathe.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Buffer.Lathe - * @param apiGeometry + * @param apiGeometryBuffer * @param points [R3.Vector2] (x must be larger than 0) * @param segments * @param phiStart @@ -8,22 +8,14 @@ * @constructor */ R3.D3.API.Geometry.Buffer.Lathe = function( - apiGeometry, + apiGeometryBuffer, points, segments, phiStart, phiLength ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_LATHE; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(points)) { points = []; @@ -45,15 +37,6 @@ R3.D3.API.Geometry.Buffer.Lathe = function( } this.phiLength = phiLength; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Lathe.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-octahedron.js b/src/r3-d3-api-geometry-buffer-octahedron.js index 191655f..2300e59 100644 --- a/src/r3-d3-api-geometry-buffer-octahedron.js +++ b/src/r3-d3-api-geometry-buffer-octahedron.js @@ -1,25 +1,17 @@ /** * R3.D3.API.Geometry.Buffer.Octahedron - * @param apiGeometry + * @param apiGeometryBuffer * @param radius * @param detail * @constructor */ R3.D3.API.Geometry.Buffer.Octahedron = function( - apiGeometry, + apiGeometryBuffer, radius, detail ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_OCTAHEDRON; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(radius)) { radius = 1; @@ -31,15 +23,6 @@ R3.D3.API.Geometry.Buffer.Octahedron = function( } this.detail = detail; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Octahedron.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-parametric.js b/src/r3-d3-api-geometry-buffer-parametric.js index 15bf883..232b519 100644 --- a/src/r3-d3-api-geometry-buffer-parametric.js +++ b/src/r3-d3-api-geometry-buffer-parametric.js @@ -1,27 +1,19 @@ /** * R3.D3.API.Geometry.Buffer.Parametric - * @param apiGeometry + * @param apiGeometryBuffer * @param generatorFn(u,v) => returns Vector3, u and v is values between 0 and 1 * @param slices * @param stacks * @constructor */ R3.D3.API.Geometry.Buffer.Parametric = function( - apiGeometry, + apiGeometryBuffer, generatorFn, slices, stacks ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PARAMETRIC; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(generatorFn)) { generatorFn = ''; @@ -38,15 +30,6 @@ R3.D3.API.Geometry.Buffer.Parametric = function( } this.stacks = stacks; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Parametric.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-plane.js b/src/r3-d3-api-geometry-buffer-plane.js index 506cbd2..227ef77 100644 --- a/src/r3-d3-api-geometry-buffer-plane.js +++ b/src/r3-d3-api-geometry-buffer-plane.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Buffer.Plane - * @param apiGeometry + * @param apiGeometryBuffer * @param width * @param height * @param widthSegments @@ -8,22 +8,14 @@ * @constructor */ R3.D3.API.Geometry.Buffer.Plane = function( - apiGeometry, + apiGeometryBuffer, width, height, widthSegments, heightSegments ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_PLANE; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(width)) { width = 1; @@ -45,15 +37,6 @@ R3.D3.API.Geometry.Buffer.Plane = function( } this.heightSegments = heightSegments; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Plane.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-polyhedron.js b/src/r3-d3-api-geometry-buffer-polyhedron.js index ddbcb6c..f392036 100644 --- a/src/r3-d3-api-geometry-buffer-polyhedron.js +++ b/src/r3-d3-api-geometry-buffer-polyhedron.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Buffer.Polyhedron - * @param apiGeometry + * @param apiGeometryBuffer * @param vertices * @param indices * @param radius @@ -8,22 +8,14 @@ * @constructor */ R3.D3.API.Geometry.Buffer.Polyhedron = function( - apiGeometry, + apiGeometryBuffer, vertices, indices, radius, detail ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_POLYHEDRON; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(vertices)) { vertices = []; @@ -45,15 +37,6 @@ R3.D3.API.Geometry.Buffer.Polyhedron = function( } this.detail = detail; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Polyhedron.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-ring.js b/src/r3-d3-api-geometry-buffer-ring.js index 88a3805..6a3009b 100644 --- a/src/r3-d3-api-geometry-buffer-ring.js +++ b/src/r3-d3-api-geometry-buffer-ring.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Buffer.Ring - * @param apiGeometry + * @param apiGeometryBuffer * @param innerRadius * @param outerRadius * @param thetaSegments @@ -10,7 +10,7 @@ * @constructor */ R3.D3.API.Geometry.Buffer.Ring = function( - apiGeometry, + apiGeometryBuffer, innerRadius, outerRadius, thetaSegments, @@ -19,15 +19,7 @@ R3.D3.API.Geometry.Buffer.Ring = function( thetaLength ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_RING; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(innerRadius)) { innerRadius = 0.5; @@ -59,15 +51,6 @@ R3.D3.API.Geometry.Buffer.Ring = function( } this.thetaLength = thetaLength; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Ring.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-shape.js b/src/r3-d3-api-geometry-buffer-shape.js index 062d309..789acf8 100644 --- a/src/r3-d3-api-geometry-buffer-shape.js +++ b/src/r3-d3-api-geometry-buffer-shape.js @@ -1,25 +1,17 @@ /** * R3.D3.API.Geometry.Buffer.Shape - * @param apiGeometry + * @param apiGeometryBuffer * @param shapes * @param curveSegments * @constructor */ R3.D3.API.Geometry.Buffer.Shape = function( - apiGeometry, + apiGeometryBuffer, shapes, curveSegments ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SHAPE; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(shapes)) { shapes = []; @@ -31,15 +23,6 @@ R3.D3.API.Geometry.Buffer.Shape = function( } this.curveSegments = curveSegments; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Shape.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-sphere.js b/src/r3-d3-api-geometry-buffer-sphere.js index f7651de..dfe482a 100644 --- a/src/r3-d3-api-geometry-buffer-sphere.js +++ b/src/r3-d3-api-geometry-buffer-sphere.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Buffer.Sphere - * @param apiGeometry + * @param apiGeometryBuffer * @param radius * @param widthSegments * @param heightSegments @@ -11,7 +11,7 @@ * @constructor */ R3.D3.API.Geometry.Buffer.Sphere = function( - apiGeometry, + apiGeometryBuffer, radius, widthSegments, heightSegments, @@ -21,15 +21,7 @@ R3.D3.API.Geometry.Buffer.Sphere = function( thetaLength ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_SPHERE; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(radius)) { radius = 1; @@ -66,15 +58,6 @@ R3.D3.API.Geometry.Buffer.Sphere = function( } this.thetaLength = thetaLength; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Sphere.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-tetrahedron.js b/src/r3-d3-api-geometry-buffer-tetrahedron.js index 734e0f9..f6b153b 100644 --- a/src/r3-d3-api-geometry-buffer-tetrahedron.js +++ b/src/r3-d3-api-geometry-buffer-tetrahedron.js @@ -1,25 +1,17 @@ /** * R3.D3.API.Geometry.Buffer.Tetrahedron - * @param apiGeometry + * @param apiGeometryBuffer * @param radius * @param detail * @constructor */ R3.D3.API.Geometry.Buffer.Tetrahedron = function( - apiGeometry, + apiGeometryBuffer, radius, detail ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TETRAHEDRON; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(radius)) { radius = 1; @@ -31,15 +23,6 @@ R3.D3.API.Geometry.Buffer.Tetrahedron = function( } this.detail = detail; - R3.D3.API.Geometry.Buffer.call( - this, - apiGeometry, - apiGeometry.attributes, - apiGeometry.drawRange, - apiGeometry.groups, - apiGeometry.index, - apiGeometry.morphAttributes - ); }; R3.D3.API.Geometry.Buffer.Tetrahedron.prototype = Object.create(R3.D3.API.Geometry.Buffer.prototype); diff --git a/src/r3-d3-api-geometry-buffer-text.js b/src/r3-d3-api-geometry-buffer-text.js index 2b6d5de..c418236 100644 --- a/src/r3-d3-api-geometry-buffer-text.js +++ b/src/r3-d3-api-geometry-buffer-text.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Buffer.Text - * @param apiGeometry + * @param apiGeometryBuffer * @param text * @param font * @param size @@ -13,7 +13,7 @@ * @constructor */ R3.D3.API.Geometry.Buffer.Text = function( - apiGeometry, + apiGeometryBuffer, text, font, size, @@ -25,15 +25,7 @@ R3.D3.API.Geometry.Buffer.Text = function( bevelSegments ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_BUFFER_TEXT; - } + __API_GEOMETRY_BUFFER_MACRO__ if (R3.Utils.UndefinedOrNull(text)) { text = '-= returns Vector3, u and v is values between 0 and 1 * @param slices * @param stacks * @constructor */ R3.D3.API.Geometry.Normal.Parametric = function( - apiGeometry, + apiGeometryNormal, generatorFn, slices, stacks ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PARAMETRIC; - } + __API_GEOMETRY_NORMAL_MACRO__ if (R3.Utils.UndefinedOrNull(generatorFn)) { generatorFn = ''; @@ -38,23 +30,6 @@ R3.D3.API.Geometry.Normal.Parametric = function( } this.stacks = stacks; - R3.D3.API.Geometry.Normal.call( - this, - apiGeometry, - apiGeometry.colors, - apiGeometry.lineDistances, - apiGeometry.morphTargets, - apiGeometry.morphNormals, - apiGeometry.skinWeights, - apiGeometry.skinIndices, - apiGeometry.verticesNeedsUpdate, - apiGeometry.elementsNeedUpdate, - apiGeometry.uvsNeedUpdate, - apiGeometry.normalsNeedUpdate, - apiGeometry.colorsNeedUpdate, - apiGeometry.groupsNeedUpdate, - apiGeometry.lineDistancesNeedUpdate - ); }; R3.D3.API.Geometry.Normal.Parametric.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); diff --git a/src/r3-d3-api-geometry-normal-plane.js b/src/r3-d3-api-geometry-normal-plane.js index ec54326..594cc6f 100644 --- a/src/r3-d3-api-geometry-normal-plane.js +++ b/src/r3-d3-api-geometry-normal-plane.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Normal.Plane - * @param apiGeometry + * @param apiGeometryNormal * @param width * @param height * @param widthSegments @@ -8,22 +8,14 @@ * @constructor */ R3.D3.API.Geometry.Normal.Plane = function( - apiGeometry, + apiGeometryNormal, width, height, widthSegments, heightSegments ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_PLANE; - } + __API_GEOMETRY_NORMAL_MACRO__ if (R3.Utils.UndefinedOrNull(width)) { width = 1; @@ -45,23 +37,6 @@ R3.D3.API.Geometry.Normal.Plane = function( } this.heightSegments = heightSegments; - R3.D3.API.Geometry.Normal.call( - this, - apiGeometry, - apiGeometry.colors, - apiGeometry.lineDistances, - apiGeometry.morphTargets, - apiGeometry.morphNormals, - apiGeometry.skinWeights, - apiGeometry.skinIndices, - apiGeometry.verticesNeedsUpdate, - apiGeometry.elementsNeedUpdate, - apiGeometry.uvsNeedUpdate, - apiGeometry.normalsNeedUpdate, - apiGeometry.colorsNeedUpdate, - apiGeometry.groupsNeedUpdate, - apiGeometry.lineDistancesNeedUpdate - ); }; R3.D3.API.Geometry.Normal.Plane.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); diff --git a/src/r3-d3-api-geometry-normal-polyhedron.js b/src/r3-d3-api-geometry-normal-polyhedron.js index 652531f..a55983c 100644 --- a/src/r3-d3-api-geometry-normal-polyhedron.js +++ b/src/r3-d3-api-geometry-normal-polyhedron.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Normal.Polyhedron - * @param apiGeometry + * @param apiGeometryNormal * @param vertices * @param indices * @param radius @@ -8,22 +8,14 @@ * @constructor */ R3.D3.API.Geometry.Normal.Polyhedron = function( - apiGeometry, + apiGeometryNormal, vertices, indices, radius, detail ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_POLYHEDRON; - } + __API_GEOMETRY_NORMAL_MACRO__ if (R3.Utils.UndefinedOrNull(vertices)) { vertices = []; @@ -45,23 +37,6 @@ R3.D3.API.Geometry.Normal.Polyhedron = function( } this.detail = detail; - R3.D3.API.Geometry.Normal.call( - this, - apiGeometry, - apiGeometry.colors, - apiGeometry.lineDistances, - apiGeometry.morphTargets, - apiGeometry.morphNormals, - apiGeometry.skinWeights, - apiGeometry.skinIndices, - apiGeometry.verticesNeedsUpdate, - apiGeometry.elementsNeedUpdate, - apiGeometry.uvsNeedUpdate, - apiGeometry.normalsNeedUpdate, - apiGeometry.colorsNeedUpdate, - apiGeometry.groupsNeedUpdate, - apiGeometry.lineDistancesNeedUpdate - ); }; R3.D3.API.Geometry.Normal.Polyhedron.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); diff --git a/src/r3-d3-api-geometry-normal-ring.js b/src/r3-d3-api-geometry-normal-ring.js index 0873d80..7a2d2b8 100644 --- a/src/r3-d3-api-geometry-normal-ring.js +++ b/src/r3-d3-api-geometry-normal-ring.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Normal.Ring - * @param apiGeometry + * @param apiGeometryNormal * @param innerRadius * @param outerRadius * @param thetaSegments @@ -10,7 +10,7 @@ * @constructor */ R3.D3.API.Geometry.Normal.Ring = function( - apiGeometry, + apiGeometryNormal, innerRadius, outerRadius, thetaSegments, @@ -19,15 +19,7 @@ R3.D3.API.Geometry.Normal.Ring = function( thetaLength ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_RING; - } + __API_GEOMETRY_NORMAL_MACRO__ if (R3.Utils.UndefinedOrNull(innerRadius)) { innerRadius = 0.5; @@ -59,23 +51,6 @@ R3.D3.API.Geometry.Normal.Ring = function( } this.thetaLength = thetaLength; - R3.D3.API.Geometry.Normal.call( - this, - apiGeometry, - apiGeometry.colors, - apiGeometry.lineDistances, - apiGeometry.morphTargets, - apiGeometry.morphNormals, - apiGeometry.skinWeights, - apiGeometry.skinIndices, - apiGeometry.verticesNeedsUpdate, - apiGeometry.elementsNeedUpdate, - apiGeometry.uvsNeedUpdate, - apiGeometry.normalsNeedUpdate, - apiGeometry.colorsNeedUpdate, - apiGeometry.groupsNeedUpdate, - apiGeometry.lineDistancesNeedUpdate - ); }; R3.D3.API.Geometry.Normal.Ring.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); diff --git a/src/r3-d3-api-geometry-normal-shape.js b/src/r3-d3-api-geometry-normal-shape.js index 1730c0e..61dda35 100644 --- a/src/r3-d3-api-geometry-normal-shape.js +++ b/src/r3-d3-api-geometry-normal-shape.js @@ -1,25 +1,17 @@ /** * R3.D3.API.Geometry.Normal.Shape - * @param apiGeometry + * @param apiGeometryNormal * @param shapes * @param curveSegments * @constructor */ R3.D3.API.Geometry.Normal.Shape = function( - apiGeometry, + apiGeometryNormal, shapes, curveSegments ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SHAPE; - } + __API_GEOMETRY_NORMAL_MACRO__ if (R3.Utils.UndefinedOrNull(shapes)) { shapes = []; @@ -31,23 +23,6 @@ R3.D3.API.Geometry.Normal.Shape = function( } this.curveSegments = curveSegments; - R3.D3.API.Geometry.Normal.call( - this, - apiGeometry, - apiGeometry.colors, - apiGeometry.lineDistances, - apiGeometry.morphTargets, - apiGeometry.morphNormals, - apiGeometry.skinWeights, - apiGeometry.skinIndices, - apiGeometry.verticesNeedsUpdate, - apiGeometry.elementsNeedUpdate, - apiGeometry.uvsNeedUpdate, - apiGeometry.normalsNeedUpdate, - apiGeometry.colorsNeedUpdate, - apiGeometry.groupsNeedUpdate, - apiGeometry.lineDistancesNeedUpdate - ); }; R3.D3.API.Geometry.Normal.Shape.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); diff --git a/src/r3-d3-api-geometry-normal-sphere.js b/src/r3-d3-api-geometry-normal-sphere.js index 2da46a7..5574e2d 100644 --- a/src/r3-d3-api-geometry-normal-sphere.js +++ b/src/r3-d3-api-geometry-normal-sphere.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Normal.Sphere - * @param apiGeometry + * @param apiGeometryNormal * @param radius * @param widthSegments * @param heightSegments @@ -11,7 +11,7 @@ * @constructor */ R3.D3.API.Geometry.Normal.Sphere = function( - apiGeometry, + apiGeometryNormal, radius, widthSegments, heightSegments, @@ -21,15 +21,7 @@ R3.D3.API.Geometry.Normal.Sphere = function( thetaLength ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_SPHERE; - } + __API_GEOMETRY_NORMAL_MACRO__ if (R3.Utils.UndefinedOrNull(radius)) { radius = 1; @@ -66,23 +58,6 @@ R3.D3.API.Geometry.Normal.Sphere = function( } this.thetaLength = thetaLength; - R3.D3.API.Geometry.Normal.call( - this, - apiGeometry, - apiGeometry.colors, - apiGeometry.lineDistances, - apiGeometry.morphTargets, - apiGeometry.morphNormals, - apiGeometry.skinWeights, - apiGeometry.skinIndices, - apiGeometry.verticesNeedsUpdate, - apiGeometry.elementsNeedUpdate, - apiGeometry.uvsNeedUpdate, - apiGeometry.normalsNeedUpdate, - apiGeometry.colorsNeedUpdate, - apiGeometry.groupsNeedUpdate, - apiGeometry.lineDistancesNeedUpdate - ); }; R3.D3.API.Geometry.Normal.Sphere.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); diff --git a/src/r3-d3-api-geometry-normal-tetrahedron.js b/src/r3-d3-api-geometry-normal-tetrahedron.js index 43dade8..1275def 100644 --- a/src/r3-d3-api-geometry-normal-tetrahedron.js +++ b/src/r3-d3-api-geometry-normal-tetrahedron.js @@ -1,25 +1,17 @@ /** * R3.D3.API.Geometry.Normal.Tetrahedron - * @param apiGeometry + * @param apiGeometryNormal * @param radius * @param detail * @constructor */ R3.D3.API.Geometry.Normal.Tetrahedron = function( - apiGeometry, + apiGeometryNormal, radius, detail ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TETRAHEDRON; - } + __API_GEOMETRY_NORMAL_MACRO__ if (R3.Utils.UndefinedOrNull(radius)) { radius = 1; @@ -31,23 +23,6 @@ R3.D3.API.Geometry.Normal.Tetrahedron = function( } this.detail = detail; - R3.D3.API.Geometry.Normal.call( - this, - apiGeometry, - apiGeometry.colors, - apiGeometry.lineDistances, - apiGeometry.morphTargets, - apiGeometry.morphNormals, - apiGeometry.skinWeights, - apiGeometry.skinIndices, - apiGeometry.verticesNeedsUpdate, - apiGeometry.elementsNeedUpdate, - apiGeometry.uvsNeedUpdate, - apiGeometry.normalsNeedUpdate, - apiGeometry.colorsNeedUpdate, - apiGeometry.groupsNeedUpdate, - apiGeometry.lineDistancesNeedUpdate - ); }; R3.D3.API.Geometry.Normal.Tetrahedron.prototype = Object.create(R3.D3.API.Geometry.Normal.prototype); diff --git a/src/r3-d3-api-geometry-normal-text.js b/src/r3-d3-api-geometry-normal-text.js index b9f06ba..4c7afd7 100644 --- a/src/r3-d3-api-geometry-normal-text.js +++ b/src/r3-d3-api-geometry-normal-text.js @@ -1,6 +1,6 @@ /** * R3.D3.API.Geometry.Normal.Text - * @param apiGeometry + * @param apiGeometryNormal * @param text * @param font * @param size @@ -13,7 +13,7 @@ * @constructor */ R3.D3.API.Geometry.Normal.Text = function( - apiGeometry, + apiGeometryNormal, text, font, size, @@ -25,15 +25,7 @@ R3.D3.API.Geometry.Normal.Text = function( bevelSegments ) { - if (R3.Utils.UndefinedOrNull(apiGeometry)) { - apiGeometry = { - geometryType: R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT - }; - } - - if (R3.Utils.UndefinedOrNull(apiGeometry.geometryType)) { - apiGeometry.geometryType = R3.D3.API.Geometry.GEOMETRY_TYPE_NORMAL_TEXT; - } + __API_GEOMETRY_NORMAL_MACRO__ if (R3.Utils.UndefinedOrNull(text)) { text = '-= 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?) + * * @constructor * @param apiViewport * @param aspectRatio @@ -14,14 +36,19 @@ R3.D3.API.Viewport.ZoomedAspect = function( ) { if (R3.Utils.UndefinedOrNull(apiViewport)) { - apiViewport = { - viewportType: R3.D3.API.Viewport.VIEWPORT_TYPE_ZOOMED_ASPECT - }; + apiViewport = {}; } + this.apiViewport = apiViewport; - if (R3.Utils.UndefinedOrNull(apiViewport.viewportType)) { - apiViewport.viewportType = R3.D3.API.Viewport.VIEWPORT_TYPE_ZOOMED_ASPECT; - } + R3.D3.API.Viewport.call( + this, + this.apiViewport, + this.apiViewport.width, + this.apiViewport.height, + this.apiViewport.x, + this.apiViewport.y, + this.apiViewport.scenes + ); if (R3.Utils.UndefinedOrNull(aspectRatio)) { aspectRatio = R3.D3.API.Viewport.ASPECT_RATIO_16_9; @@ -38,17 +65,6 @@ R3.D3.API.Viewport.ZoomedAspect = function( } 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); diff --git a/src/r3-d3-api-viewport.js b/src/r3-d3-api-viewport.js index b9e6421..98cebb1 100644 --- a/src/r3-d3-api-viewport.js +++ b/src/r3-d3-api-viewport.js @@ -1,69 +1,26 @@ /** - * Raw Viewport API object - should always correspond with the Viewport Schema - * @param id - * @param name - * @param viewportType + * R3.D3.API.Viewport + * + * Ignore aspect ratio and make viewport respect x,y,width and height as is + * + * @param apiComponent * @param width * @param height * @param x * @param y - * @param parent - * @param scene - * @param controls - * @param cameraIndexEdit - * @param cameraIndexRun - * @param composer - * @param effect - * @param enableComposer - * @param enableEffect + * @param scenes * @constructor */ R3.D3.API.Viewport = function( - id, - name, - viewportType, - parent, + apiComponent, width, height, x, y, - scene, - cameraIndexEdit, - cameraIndexRun, - controls, - composer, - effect, - enableComposer, - enableEffect + scenes ) { - if (R3.Utils.UndefinedOrNull(id)) { - id = R3.Utils.RandomId(); - } - this.id = id; - - if (R3.Utils.UndefinedOrNull(viewportType)) { - viewportType = R3.D3.API.Viewport.VIEWPORT_TYPE_NORMAL; - } - this.viewportType = viewportType; - - if (R3.Utils.UndefinedOrNull(name)) { - - 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; + __API_COMPONENT_MACRO__ if (R3.Utils.UndefinedOrNull(width)) { width = 1; @@ -85,123 +42,19 @@ R3.D3.API.Viewport = function( } this.y = y; - if (R3.Utils.UndefinedOrNull(scene)) { - scene = new R3.D3.API.Scene(); + if (R3.Utils.UndefinedOrNull(scenes)) { + scenes = [new R3.D3.API.Scene()]; } - this.scene = scene; + this.scenes = scenes; - 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.D3.API.Texture.GetComponentType(this.viewportType), - parent - ); }; R3.D3.API.Viewport.prototype = Object.create(R3.API.Component.prototype); R3.D3.API.Viewport.prototype.constructor = R3.D3.API.Viewport; -/** - * Returns Component type based on Viewport type - * @param viewportType - * @returns {number} - * @constructor - */ -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 +R3.D3.API.Viewport.ASPECT_RATIO_16_9 = 0x6; diff --git a/src/r3-d3-camera-orthographic-fixed-aspect.js b/src/r3-d3-camera-orthographic-fixed-aspect.js new file mode 100644 index 0000000..f4a1eeb --- /dev/null +++ b/src/r3-d3-camera-orthographic-fixed-aspect.js @@ -0,0 +1,289 @@ +/** + * R3.D3.Camera.Orthographic + * @param graphics R3.GraphicsRuntime + * @param apiD3OBjectOrthographicCamera + * @constructor + */ +R3.D3.Camera.Orthographic.FixedAspect = function( + graphics, + apiD3OBjectOrthographicCamera +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiD3OBjectOrthographicCamera)) { + apiD3OBjectOrthographicCamera = { + objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC, + position : R3.API.Vector3(0,0,10), + lookAt: R3.API.Vector3(0,0,-10) + }; + } + + R3.D3.API.Camera.Orthographic.call( + this, + apiD3OBjectOrthographicCamera, + apiD3OBjectOrthographicCamera.aspectRatioMode, + apiD3OBjectOrthographicCamera.minWidth, + apiD3OBjectOrthographicCamera.minHeight, + apiD3OBjectOrthographicCamera.width, + apiD3OBjectOrthographicCamera.height, + apiD3OBjectOrthographicCamera.near, + apiD3OBjectOrthographicCamera.far, + apiD3OBjectOrthographicCamera.left, + apiD3OBjectOrthographicCamera.right, + apiD3OBjectOrthographicCamera.top, + apiD3OBjectOrthographicCamera.bottom, + apiD3OBjectOrthographicCamera.zoom + ); + + R3.D3.Camera.call( + this, + this.graphics, + this + ); + +}; + +R3.D3.Camera.Orthographic.prototype = Object.create(R3.D3.Camera.prototype); +R3.D3.Camera.Orthographic.prototype.constructor = R3.D3.Camera.Orthographic; + +/** + * Creates a camera instance + * @returns {*} + */ +R3.D3.Camera.Orthographic.prototype.createInstance = function() { + + this.instance = new THREE.OrthographicCamera( + this.left, + this.right, + this.top, + this.bottom, + this.near, + this.far + ); + + if ( + this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED || + this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT + ) { + + if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) { + + var size = R3.Utils.GetWindowSize(); + + this.aspect = size.width / size.height; + } + + this.updateFromAspectRatio(); + } + + R3.D3.Camera.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.D3.Camera.Orthographic.prototype.updateInstance = function(property) { + + var size; + + if (property === 'aspectRatioMode') { + + if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE) { + this.updateFromDimensions(); + return; + } + + if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED) { + this.updateFromAspectRatio(); + return; + } + + if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) { + + size = R3.Utils.GetWindowSize(); + + this.aspect = size.width / size.height; + + this.updateFromAspectRatio(); + return; + } + } + + if ( + property === 'width' || + property === 'height' || + property === 'minWidth' || + property === 'minHeight' || + property === 'aspect' + ) { + + if ( + this.aspectRatioMode !== R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED && + this.aspectRatioMode !== R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT + ) { + console.warn('changing the this value when this camera is not in the right aspect ratio mode has no effect'); + return; + } + + if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) { + size = R3.Utils.GetWindowSize(); + this.aspect = size.width / size.height; + } + + this.updateFromAspectRatio(); + + return; + } + + if ( + property === 'left' || + property === 'right' || + property === 'top' || + property === 'bottom' + ) { + + if ( + this.aspectRatioMode === R3.D3.API.Camera.ASPECT_RATIO_MODE_FIXED || + this.aspectRatioMode === R3.D3.API.Camera.ASPECT_RATIO_MODE_BASED_ON_CURRENT + ) { + console.warn('changing this value within a fixed aspect ratio has no effect'); + return; + } + + this.updateFromDimensions(); + + return; + } + + if (property === 'zoom') { + this.instance.zoom = this.zoom; + this.instance.updateProjectionMatrix(); + } + + R3.D3.Camera.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.D3.Camera to a R3.D3.API.Camera + * @returns {R3.D3.API.Camera} + */ +R3.D3.Camera.Orthographic.prototype.toApiObject = function() { + + var apiCamera = R3.D3.Camera.prototype.toApiObject.call(this); + + var apiOrthographicCamera = new R3.D3.API.Camera.Orthographic( + apiCamera, + this.aspectRatioMode, + this.minWidth, + this.minHeight, + this.width, + this.height, + this.near, + this.far, + this.left, + this.right, + this.top, + this.bottom, + this.zoom + ); + + return apiOrthographicCamera; +}; + +R3.D3.Camera.Orthographic.prototype.updateFromInstance = function() { + this.width = this.instance.right - this.instance.left; + this.height = this.instance.top - this.instance.bottom; + this.near = this.instance.near; + this.far = this.instance.far; + this.left = this.instance.left; + this.right = this.instance.right; + this.top = this.instance.top; + this.bottom = this.instance.bottom; + this.zoom = this.instance.zoom; + R3.D3.Camera.prototype.updateFromInstance.call(this); +}; + +R3.D3.Camera.Orthographic.prototype.updateFromAspectRatio = function() { + + var requiredAspect = this.minWidth / this.minHeight; + + if (this.aspect < requiredAspect) { + /** + * Make height dependend on width + */ + this.width = this.minWidth; + this.height = this.minWidth / this.aspect; + + // if (this.height < this.minHeight) { + // /** + // * We have a problem - our new height is less than our minimum height + // */ + // + // + // ; + // + // if (requiredAspect < this.aspect) { + // this.width = requiredAspect * this.height; + // } else { + // this.height = this.minHeight; + // this.width = this.aspect * this.height; + // } + // + // + // } else { + // + // /** + // * Try to fit our game into the window + // * @type {number} + // */ + // // var requiredAspect = this.minWidth / this.minHeight; + // // this.width = requiredAspect * this.height; + // } + + } else { + /** + * Make width dependend on height + */ + this.height = this.minHeight; + this.width = this.aspect * this.minHeight; + // + // if (this.width < this.minWidth) { + // /** + // * We have a problem - our new width is less than our minimum width + // */ + // this.width = this.minWidth; + // this.height = this.width / this.aspect; + // } + } + + this.left = this.width / -2; + this.right = this.width / 2; + + this.top = this.height / 2; + this.bottom = this.height / -2; + + this.instance.left = this.left; + this.instance.right = this.right; + this.instance.top = this.top; + this.instance.bottom = this.bottom; + + this.instance.updateProjectionMatrix(); + +}; + +R3.D3.Camera.Orthographic.prototype.updateFromDimensions = function() { + + this.instance.left = this.left; + this.instance.right = this.right; + this.instance.top = this.top; + this.instance.bottom = this.bottom; + + this.width = this.right - this.left; + this.height = this.top - this.bottom; + + this.aspect = this.width / this.height; + + this.instance.updateProjectionMatrix(); +}; \ No newline at end of file diff --git a/src/r3-d3-camera-orthographic-zoomed-aspect.js b/src/r3-d3-camera-orthographic-zoomed-aspect.js new file mode 100644 index 0000000..f4a1eeb --- /dev/null +++ b/src/r3-d3-camera-orthographic-zoomed-aspect.js @@ -0,0 +1,289 @@ +/** + * R3.D3.Camera.Orthographic + * @param graphics R3.GraphicsRuntime + * @param apiD3OBjectOrthographicCamera + * @constructor + */ +R3.D3.Camera.Orthographic.FixedAspect = function( + graphics, + apiD3OBjectOrthographicCamera +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (R3.Utils.UndefinedOrNull(apiD3OBjectOrthographicCamera)) { + apiD3OBjectOrthographicCamera = { + objectType : R3.D3.API.Object.OBJECT_TYPE_CAMERA_ORTHOGRAPHIC, + position : R3.API.Vector3(0,0,10), + lookAt: R3.API.Vector3(0,0,-10) + }; + } + + R3.D3.API.Camera.Orthographic.call( + this, + apiD3OBjectOrthographicCamera, + apiD3OBjectOrthographicCamera.aspectRatioMode, + apiD3OBjectOrthographicCamera.minWidth, + apiD3OBjectOrthographicCamera.minHeight, + apiD3OBjectOrthographicCamera.width, + apiD3OBjectOrthographicCamera.height, + apiD3OBjectOrthographicCamera.near, + apiD3OBjectOrthographicCamera.far, + apiD3OBjectOrthographicCamera.left, + apiD3OBjectOrthographicCamera.right, + apiD3OBjectOrthographicCamera.top, + apiD3OBjectOrthographicCamera.bottom, + apiD3OBjectOrthographicCamera.zoom + ); + + R3.D3.Camera.call( + this, + this.graphics, + this + ); + +}; + +R3.D3.Camera.Orthographic.prototype = Object.create(R3.D3.Camera.prototype); +R3.D3.Camera.Orthographic.prototype.constructor = R3.D3.Camera.Orthographic; + +/** + * Creates a camera instance + * @returns {*} + */ +R3.D3.Camera.Orthographic.prototype.createInstance = function() { + + this.instance = new THREE.OrthographicCamera( + this.left, + this.right, + this.top, + this.bottom, + this.near, + this.far + ); + + if ( + this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED || + this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT + ) { + + if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) { + + var size = R3.Utils.GetWindowSize(); + + this.aspect = size.width / size.height; + } + + this.updateFromAspectRatio(); + } + + R3.D3.Camera.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +R3.D3.Camera.Orthographic.prototype.updateInstance = function(property) { + + var size; + + if (property === 'aspectRatioMode') { + + if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_NONE) { + this.updateFromDimensions(); + return; + } + + if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED) { + this.updateFromAspectRatio(); + return; + } + + if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) { + + size = R3.Utils.GetWindowSize(); + + this.aspect = size.width / size.height; + + this.updateFromAspectRatio(); + return; + } + } + + if ( + property === 'width' || + property === 'height' || + property === 'minWidth' || + property === 'minHeight' || + property === 'aspect' + ) { + + if ( + this.aspectRatioMode !== R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_FIXED && + this.aspectRatioMode !== R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT + ) { + console.warn('changing the this value when this camera is not in the right aspect ratio mode has no effect'); + return; + } + + if (this.aspectRatioMode === R3.D3.API.Camera.Orthographic.ASPECT_RATIO_MODE_BASED_ON_CURRENT) { + size = R3.Utils.GetWindowSize(); + this.aspect = size.width / size.height; + } + + this.updateFromAspectRatio(); + + return; + } + + if ( + property === 'left' || + property === 'right' || + property === 'top' || + property === 'bottom' + ) { + + if ( + this.aspectRatioMode === R3.D3.API.Camera.ASPECT_RATIO_MODE_FIXED || + this.aspectRatioMode === R3.D3.API.Camera.ASPECT_RATIO_MODE_BASED_ON_CURRENT + ) { + console.warn('changing this value within a fixed aspect ratio has no effect'); + return; + } + + this.updateFromDimensions(); + + return; + } + + if (property === 'zoom') { + this.instance.zoom = this.zoom; + this.instance.updateProjectionMatrix(); + } + + R3.D3.Camera.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a R3.D3.Camera to a R3.D3.API.Camera + * @returns {R3.D3.API.Camera} + */ +R3.D3.Camera.Orthographic.prototype.toApiObject = function() { + + var apiCamera = R3.D3.Camera.prototype.toApiObject.call(this); + + var apiOrthographicCamera = new R3.D3.API.Camera.Orthographic( + apiCamera, + this.aspectRatioMode, + this.minWidth, + this.minHeight, + this.width, + this.height, + this.near, + this.far, + this.left, + this.right, + this.top, + this.bottom, + this.zoom + ); + + return apiOrthographicCamera; +}; + +R3.D3.Camera.Orthographic.prototype.updateFromInstance = function() { + this.width = this.instance.right - this.instance.left; + this.height = this.instance.top - this.instance.bottom; + this.near = this.instance.near; + this.far = this.instance.far; + this.left = this.instance.left; + this.right = this.instance.right; + this.top = this.instance.top; + this.bottom = this.instance.bottom; + this.zoom = this.instance.zoom; + R3.D3.Camera.prototype.updateFromInstance.call(this); +}; + +R3.D3.Camera.Orthographic.prototype.updateFromAspectRatio = function() { + + var requiredAspect = this.minWidth / this.minHeight; + + if (this.aspect < requiredAspect) { + /** + * Make height dependend on width + */ + this.width = this.minWidth; + this.height = this.minWidth / this.aspect; + + // if (this.height < this.minHeight) { + // /** + // * We have a problem - our new height is less than our minimum height + // */ + // + // + // ; + // + // if (requiredAspect < this.aspect) { + // this.width = requiredAspect * this.height; + // } else { + // this.height = this.minHeight; + // this.width = this.aspect * this.height; + // } + // + // + // } else { + // + // /** + // * Try to fit our game into the window + // * @type {number} + // */ + // // var requiredAspect = this.minWidth / this.minHeight; + // // this.width = requiredAspect * this.height; + // } + + } else { + /** + * Make width dependend on height + */ + this.height = this.minHeight; + this.width = this.aspect * this.minHeight; + // + // if (this.width < this.minWidth) { + // /** + // * We have a problem - our new width is less than our minimum width + // */ + // this.width = this.minWidth; + // this.height = this.width / this.aspect; + // } + } + + this.left = this.width / -2; + this.right = this.width / 2; + + this.top = this.height / 2; + this.bottom = this.height / -2; + + this.instance.left = this.left; + this.instance.right = this.right; + this.instance.top = this.top; + this.instance.bottom = this.bottom; + + this.instance.updateProjectionMatrix(); + +}; + +R3.D3.Camera.Orthographic.prototype.updateFromDimensions = function() { + + this.instance.left = this.left; + this.instance.right = this.right; + this.instance.top = this.top; + this.instance.bottom = this.bottom; + + this.width = this.right - this.left; + this.height = this.top - this.bottom; + + this.aspect = this.width / this.height; + + this.instance.updateProjectionMatrix(); +}; \ No newline at end of file diff --git a/src/r3-graphics-runtime-a.js b/src/r3-graphics-runtime-a.js index 66ef6de..fe1f035 100644 --- a/src/r3-graphics-runtime-a.js +++ b/src/r3-graphics-runtime-a.js @@ -20,6 +20,18 @@ R3.GraphicsRuntime.prototype.Box3 = function(x,y,z) { console.warn('override Box3 in child class'); }; +R3.GraphicsRuntime.prototype.Color = function(r,g,b,a) { + console.warn('override Color in child class'); +}; + +R3.GraphicsRuntime.prototype.Matrix4 = function(rows) { + console.warn('override Matrix4 in child class'); +}; + +R3.GraphicsRuntime.prototype.Quaternion = function(x, y, z, w) { + console.warn('override Quaternion in child class'); +}; + /** * R3.GraphicsRuntime Types diff --git a/src/r3-graphics-runtime-three.js b/src/r3-graphics-runtime-three.js index dfee0d5..948199d 100644 --- a/src/r3-graphics-runtime-three.js +++ b/src/r3-graphics-runtime-three.js @@ -34,6 +34,40 @@ R3.GraphicsRuntime.Three.prototype.Vector4 = function(x,y,z,w) { return new this.instance.Quaternion(x,y,z,w); }; +R3.GraphicsRuntime.Three.prototype.Color = function(r,g,b,a) { + return new this.instance.Color(r,g,b,a); +}; + +R3.GraphicsRuntime.Three.prototype.Matrix4 = function(rows) { + + var instance = new THREE.Matrix4(); + + /** + * We transpose our matrix when we send it to three since we use a different ordering system + * They say they use + */ + instance.set( + rows[0].x, + rows[1].x, + rows[2].x, + rows[3].x, + rows[0].y, + rows[1].y, + rows[2].y, + rows[3].y, + rows[0].z, + rows[1].z, + rows[2].z, + rows[3].z, + rows[0].w, + rows[1].w, + rows[2].w, + rows[3].w + ); + + return instance; +}; + /** * R3.GraphicsRuntime.Three.prototype.Box3 * @param min {R3.Vector3|R3.API.Vector3} @@ -44,3 +78,7 @@ R3.GraphicsRuntime.Three.prototype.Vector4 = function(x,y,z,w) { R3.GraphicsRuntime.Three.prototype.Box3 = function(min,max) { return new this.instance.Box3(min.instance, max.instance); }; + +R3.GraphicsRuntime.Three.prototype.Quaternion = function(x, y, z, w) { + return new this.instance.Quaternion(x,y,z,w); +}; \ No newline at end of file diff --git a/src/r3-matrix-4.js b/src/r3-matrix-4.js index 54b33f1..87e0384 100644 --- a/src/r3-matrix-4.js +++ b/src/r3-matrix-4.js @@ -1,24 +1,23 @@ /** * Runtime Matrix4 - * @param graphics - * @param parentObject + * @param parent * @param apiMatrix4 - * @param grain * @constructor */ R3.Matrix4 = function( - graphics, - apiMatrix4, - parentObject, - grain + parent, + apiMatrix4 ) { - this.graphics = graphics; - this.graphics.isNotThreeThrow(); + if (R3.Utils.UndefinedOrNull(parent)) { + parent = null; + } + this.parent = parent; if (R3.Utils.UndefinedOrNull(apiMatrix4)) { apiMatrix4 = {}; } + this.apiMatrix4 = apiMatrix4; R3.API.Matrix4.call( this, @@ -28,116 +27,86 @@ R3.Matrix4 = function( apiMatrix4.rows[3] ); - if (R3.Utils.UndefinedOrNull(parentObject)) { - parentObject = null; - } - this.parentObject = parentObject; + this.rows = this.rows.reduce( + function(result, row) { - if (R3.Utils.UndefinedOrNull(grain)) { - grain = 0.001; - } - this.grain = grain; - - this.rows = this.rows.map( - function(row) { - - return new R3.Vector4( - this.graphics, - row, - this, - this.grain + result.push( + new R3.Vector4( + this.parent, + row + ) ); + return result; + }.bind(this), + [] + ); + + 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.forward = new R3.Vector4( - this.graphics, - this.forward, - this, - this.grain - ); - - this.left = new R3.Vector4( - this.graphics, - this.left, - this, - this.grain - ); - - this.up = new R3.Vector4( - this.graphics, - this.up, - this, - this.grain - ); + this.componentRuntime = R3.Component.GetComponentRuntime(this.parent); this.createInstance(); }; -R3.Matrix4.prototype = Object.create(R3.Component.prototype); +R3.Matrix4.prototype = Object.create(R3.API.Matrix4.prototype); R3.Matrix4.prototype.constructor = R3.Matrix4; /** - * Creates a matrix 4 instance (currently from graphics lib) - * @param update + * R3.Matrix4.prototype.createInstance */ -R3.Matrix4.prototype.createInstance = function(update) { +R3.Matrix4.prototype.createInstance = function() { - this.instance = new THREE.Matrix4(); - - /** - * We transpose our matrix when we send it to three since we use a different ordering system - * They say they use - */ - this.instance.set( - this.rows[0].x, - this.rows[1].x, - this.rows[2].x, - this.rows[3].x, - this.rows[0].y, - this.rows[1].y, - this.rows[2].y, - this.rows[3].y, - this.rows[0].z, - this.rows[1].z, - this.rows[2].z, - this.rows[3].z, - this.rows[0].w, - this.rows[1].w, - this.rows[2].w, - this.rows[3].w - ); + switch (this.componentRuntime) { + case R3.Component.GRAPHICS_RUNTIME : + this.instance = this.graphics.Matrix4( + this.rows + ); + break; + default : + case R3.Component.PHYSICS_RUNTIME : + this.instance = this.physics.Matrix4( + this.rows + ); + break; + } }; /** * Updates this instance */ -R3.Matrix4.prototype.updateInstance = function() { +R3.Matrix4.prototype.updateInstance = function(property) { - this.instance.set( - this.rows[0].x, - this.rows[1].x, - this.rows[2].x, - this.rows[3].x, - this.rows[0].y, - this.rows[1].y, - this.rows[2].y, - this.rows[3].y, - this.rows[0].z, - this.rows[1].z, - this.rows[2].z, - this.rows[3].z, - this.rows[0].w, - this.rows[1].w, - this.rows[2].w, - this.rows[3].w - ); - - if (this.parentObject && - this.parentObject.updateInstance) { - this.parentObject.updateInstance(); + if (property === 'rows') { + this.instance.set( + this.rows[0].x, + this.rows[1].x, + this.rows[2].x, + this.rows[3].x, + this.rows[0].y, + this.rows[1].y, + this.rows[2].y, + this.rows[3].y, + this.rows[0].z, + this.rows[1].z, + this.rows[2].z, + this.rows[3].z, + this.rows[0].w, + this.rows[1].w, + this.rows[2].w, + this.rows[3].w + ); } + }; /** @@ -155,25 +124,6 @@ R3.Matrix4.prototype.toApiObject = function() { }; -/** - * Creates a R3.Matrix4 from an Object matrix - * @param graphics R3.GraphicsRuntime - * @param objectMatrix Object - * @param parentObject - * @returns {R3.Matrix4} - * @constructor - */ -R3.Matrix4.FromObject = function(graphics, objectMatrix, parentObject) { - - var apiMatrix = new R3.API.Matrix4.FromObject(objectMatrix); - - return new R3.Matrix4( - graphics, - parentObject, - apiMatrix - ) -}; - /** * Lookat * @param position @@ -183,7 +133,11 @@ R3.Matrix4.FromObject = function(graphics, objectMatrix, parentObject) { */ R3.Matrix4.prototype.lookAt = function(position, target, up) { - var pv = new R3.API.Vector3(position.x, position.y, position.z); + var pv = new R3.API.Vector3( + position.x, + position.y, + position.z + ); var forward = pv.subtract(target).normalize(); @@ -224,7 +178,7 @@ R3.Matrix4.prototype.lookAt = function(position, target, up) { this.up.y = _up.y; this.up.z = _up.z; - this.updateInstance(); + this.updateInstance('rows'); return this; }; @@ -235,28 +189,20 @@ R3.Matrix4.prototype.lookAt = function(position, target, up) { R3.Matrix4.prototype.identity = function() { this.rows = [ new R3.Vector4( - this.graphics, - new R3.API.Vector4(1,0,0,0), - this, - this.grain + this.parent, + new R3.API.Vector4(1,0,0,0) ), new R3.Vector4( - this.graphics, - new R3.API.Vector4(0,1,0,0), - this, - this.grain + this.parent, + new R3.API.Vector4(0,1,0,0) ), new R3.Vector4( - this.graphics, - new R3.API.Vector4(0,0,1,0), - this, - this.grain + this.parent, + new R3.API.Vector4(0,0,1,0) ), new R3.Vector4( - this.graphics, - new R3.API.Vector4(0,0,0,1), - this, - this.grain + this.parent, + new R3.API.Vector4(0,0,0,1) ) ]; }; @@ -267,45 +213,47 @@ R3.Matrix4.prototype.identity = function() { */ R3.Matrix4.prototype.transpose = function() { - this.temp[0].x = this.rows[0].x; - this.temp[0].y = this.rows[1].x; - this.temp[0].z = this.rows[2].x; - this.temp[0].w = this.rows[3].x; + var temp = new R3.API.Matrix4(); - this.temp[1].x = this.rows[0].y; - this.temp[1].y = this.rows[1].y; - this.temp[1].z = this.rows[2].y; - this.temp[1].w = this.rows[3].y; + temp[0].x = this.rows[0].x; + temp[0].y = this.rows[1].x; + temp[0].z = this.rows[2].x; + temp[0].w = this.rows[3].x; - this.temp[2].x = this.rows[0].z; - this.temp[2].y = this.rows[1].z; - this.temp[2].z = this.rows[2].z; - this.temp[2].w = this.rows[3].z; + temp[1].x = this.rows[0].y; + temp[1].y = this.rows[1].y; + temp[1].z = this.rows[2].y; + temp[1].w = this.rows[3].y; - this.temp[3].x = this.rows[0].w; - this.temp[3].y = this.rows[1].w; - this.temp[3].z = this.rows[2].w; - this.temp[3].w = this.rows[3].w; + temp[2].x = this.rows[0].z; + temp[2].y = this.rows[1].z; + temp[2].z = this.rows[2].z; + temp[2].w = this.rows[3].z; + + temp[3].x = this.rows[0].w; + temp[3].y = this.rows[1].w; + temp[3].z = this.rows[2].w; + temp[3].w = this.rows[3].w; - this.rows[0].x = this.temp[0].x; - this.rows[0].y = this.temp[0].y; - this.rows[0].z = this.temp[0].z; - this.rows[0].w = this.temp[0].w; + this.rows[0].x = temp[0].x; + this.rows[0].y = temp[0].y; + this.rows[0].z = temp[0].z; + this.rows[0].w = temp[0].w; - this.rows[1].x = this.temp[1].x; - this.rows[1].y = this.temp[1].y; - this.rows[1].z = this.temp[1].z; - this.rows[1].w = this.temp[1].w; + this.rows[1].x = temp[1].x; + this.rows[1].y = temp[1].y; + this.rows[1].z = temp[1].z; + this.rows[1].w = temp[1].w; - this.rows[2].x = this.temp[2].x; - this.rows[2].y = this.temp[2].y; - this.rows[2].z = this.temp[2].z; - this.rows[2].w = this.temp[2].w; + this.rows[2].x = temp[2].x; + this.rows[2].y = temp[2].y; + this.rows[2].z = temp[2].z; + this.rows[2].w = temp[2].w; - this.rows[3].x = this.temp[3].x; - this.rows[3].y = this.temp[3].y; - this.rows[3].z = this.temp[3].z; - this.rows[3].w = this.temp[3].w; + this.rows[3].x = temp[3].x; + this.rows[3].y = temp[3].y; + this.rows[3].z = temp[3].z; + this.rows[3].w = temp[3].w; return this; }; diff --git a/src/r3-physics-runtime-cannon.js b/src/r3-physics-runtime-cannon.js index ae3f5b9..e1dd934 100644 --- a/src/r3-physics-runtime-cannon.js +++ b/src/r3-physics-runtime-cannon.js @@ -25,13 +25,14 @@ 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.Matrix4 = function(rows) { + console.warn('TODO: implement cannon physics matrix 4'); +}; + R3.PhysicsRuntime.Cannon.prototype.Box3 = function(min,max) { console.log('return cannon implementation of box3') -}; \ No newline at end of file +}; + +R3.PhysicsRuntime.Cannon.prototype.Quaternion = function(x,y,z,w) { + console.log('return cannon implementation of quaternion') +}; diff --git a/src/r3-physics-runtime.js b/src/r3-physics-runtime.js index 5e9c8bc..ad45bc2 100644 --- a/src/r3-physics-runtime.js +++ b/src/r3-physics-runtime.js @@ -16,6 +16,18 @@ R3.PhysicsRuntime.prototype.Vector4 = function(x,y,z,w) { console.warn('override Vector4 in child class'); }; +R3.PhysicsRuntime.prototype.Matrix4 = function(rows) { + console.warn('override Matrix4 in child class'); +}; + +R3.PhysicsRuntime.prototype.Box3 = function(rows) { + console.warn('override Box3 in child class'); +}; + +R3.PhysicsRuntime.prototype.Quaternion = function(x,y,z,w) { + console.log('override Quaternion in child class') +}; + /** * R3.PhysicsRuntime Types * @type {number} diff --git a/src/r3-quaternion.js b/src/r3-quaternion.js index b2a07b4..8f48bf2 100644 --- a/src/r3-quaternion.js +++ b/src/r3-quaternion.js @@ -1,55 +1,37 @@ /** * Runtime quaternion for updating instance objects - * @param implementation - * @param parentObject R3.D3.* + * @param parent * @param apiQuaternion R3.API.Quaternion - * @param grain Number * @constructor */ R3.Quaternion = function( - implementation, - apiQuaternion, - parentObject, - grain + parent, + apiQuaternion ) { - 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(apiQuaternion)) { apiQuaternion = {}; } + this.apiQuaternion = apiQuaternion; R3.API.Quaternion.call( this, - apiQuaternion.x, - apiQuaternion.y, - apiQuaternion.z, - apiQuaternion.w, - apiQuaternion.axis, - apiQuaternion.angle + this.apiQuaternion.x, + this.apiQuaternion.y, + this.apiQuaternion.z, + this.apiQuaternion.w, + this.apiQuaternion.axis, + this.apiQuaternion.angle ); - if (R3.Utils.UndefinedOrNull(parentObject)) { - parentObject = null; - } - this.parentObject = parentObject; - this.axis = new R3.Vector3( - this.implementation, - this.axis, - this, - this.grain + this.parent, + this.axis ); Object.defineProperty( @@ -58,15 +40,23 @@ R3.Quaternion = function( R3.Utils.LimitToPI('angle', this.angle) ); - if (R3.Utils.UndefinedOrNull(grain)) { - grain = 0.001; - } - this.grain = grain; + 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(this.parent); this.createInstance(); }; -R3.Quaternion.prototype = Object.create(R3.Component.prototype); +R3.Quaternion.prototype = Object.create(R3.API.Quaternion.prototype); R3.Quaternion.prototype.constructor = R3.Quaternion; /** @@ -76,7 +66,7 @@ R3.Quaternion.prototype.constructor = R3.Quaternion; R3.Quaternion.prototype.createInstance = function() { if (this.graphics) { - this.instance = new THREE.Quaternion( + this.instance = new this.graphics.Quaternion( this.x, this.y, this.z, @@ -85,7 +75,7 @@ R3.Quaternion.prototype.createInstance = function() { } if (this.physics) { - this.instance = new CANNON.Quaternion( + this.instance = new this.physics.Quaternion( this.x, this.y, this.z, @@ -99,15 +89,22 @@ R3.Quaternion.prototype.createInstance = function() { */ R3.Quaternion.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 (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; + } + + if (property === 'z') { + this.instance.z = this.z; + } + + if (property === 'w') { + this.instance.w = this.w; + } + }; /** @@ -153,5 +150,5 @@ R3.Quaternion.prototype.setFrom = function(quaternion) { }; R3.Quaternion.prototype.copy = function(quaternion) { -console.log('todo'); + console.log('todo quaternion copy'); }; \ No newline at end of file diff --git a/src/r3-vector2.js b/src/r3-vector2.js index fb0132e..b45f119 100644 --- a/src/r3-vector2.js +++ b/src/r3-vector2.js @@ -35,7 +35,7 @@ R3.Vector2 = function( }.bind(this) ); - this.componentRuntime = R3.Component.GetComponentRuntime(parent); + this.componentRuntime = R3.Component.GetComponentRuntime(this.parent); this.createInstance(); }; diff --git a/src/r3-vector3.js b/src/r3-vector3.js index 2cf71d3..d24ce58 100644 --- a/src/r3-vector3.js +++ b/src/r3-vector3.js @@ -6,7 +6,7 @@ */ R3.Vector3 = function( parent, - apiVector + apiVector3 ) { if (R3.Utils.UndefinedOrNull(parent)) { @@ -14,16 +14,16 @@ R3.Vector3 = function( } this.parent = parent; - if (R3.Utils.UndefinedOrNull(apiVector)) { - apiVector = {}; + if (R3.Utils.UndefinedOrNull(apiVector3)) { + apiVector3 = {}; } - this.apiVector = apiVector; + this.apiVector3 = apiVector3; R3.API.Vector3.call( this, - apiVector.x, - apiVector.y, - apiVector.z + apiVector3.x, + apiVector3.y, + apiVector3.z ); this.graphics = null; @@ -37,7 +37,7 @@ R3.Vector3 = function( }.bind(this) ); - this.componentRuntime = R3.Component.GetComponentRuntime(parent); + this.componentRuntime = R3.Component.GetComponentRuntime(this.parent); this.createInstance(); }; diff --git a/src/r3-vector4.js b/src/r3-vector4.js index 6815c4c..ca9a988 100644 --- a/src/r3-vector4.js +++ b/src/r3-vector4.js @@ -38,7 +38,7 @@ R3.Vector4 = function( }.bind(this) ); - this.componentRuntime = R3.Component.GetComponentRuntime(parent); + this.componentRuntime = R3.Component.GetComponentRuntime(this.parent); this.createInstance(); };