Merge branch 'beta.r3js.org'
commit
b91b20b016
|
@ -0,0 +1,4 @@
|
|||
node_modules/
|
||||
build/
|
||||
*.swp
|
||||
package-lock.json
|
|
@ -0,0 +1,18 @@
|
|||
#R3 3D
|
||||
######
|
||||
|
||||
A 3D library - based on the Entity Component System model - with the following features:
|
||||
|
||||
* Blender file import (import objects directly from .blend files)
|
||||
* Saving and Loading of 3D objects to mongoDB API
|
||||
* Multiple materials textures
|
||||
* Variety of materials
|
||||
* Cubemaps
|
||||
* Stereo camera
|
||||
* Custom shaders
|
||||
* Shadows
|
||||
* Effects
|
||||
* Audio System
|
||||
* Particles
|
||||
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* R3.API.AR
|
||||
* @param id
|
||||
* @param name
|
||||
* @param parent
|
||||
* @param video
|
||||
* @param pathCamera
|
||||
* @param pathMarker
|
||||
* @param scene
|
||||
* @param camera
|
||||
* @param videoScene
|
||||
* @param videoCamera
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.AR = function(
|
||||
id,
|
||||
name,
|
||||
parent,
|
||||
video,
|
||||
pathCamera,
|
||||
pathMarker,
|
||||
scene,
|
||||
camera,
|
||||
videoScene,
|
||||
videoCamera
|
||||
) {
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = 'AR (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(video)) {
|
||||
video = new R3.API.Video();
|
||||
}
|
||||
this.video = video;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(pathCamera)) {
|
||||
pathCamera = 'data/camera_para.dat';
|
||||
}
|
||||
this.pathCamera = pathCamera;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(pathMarker)) {
|
||||
pathMarker = 'data/patt.hiro';
|
||||
}
|
||||
this.pathMarker = pathMarker;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(scene)) {
|
||||
scene = null;
|
||||
}
|
||||
this.scene = scene;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(camera)) {
|
||||
camera = null;
|
||||
}
|
||||
this.camera = camera;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(videoScene)) {
|
||||
videoScene = new R3.D3.API.Scene(
|
||||
null,
|
||||
'Scene - AR Video'
|
||||
);
|
||||
}
|
||||
this.videoScene = videoScene;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(videoCamera)) {
|
||||
videoCamera = new R3.D3.API.Camera.Orthographic(
|
||||
{
|
||||
name : 'Camera Orthgraphic - AR Video'
|
||||
}
|
||||
);
|
||||
}
|
||||
this.videoCamera = videoCamera;
|
||||
|
||||
R3.API.Component.call(
|
||||
this,
|
||||
R3.Component.AR,
|
||||
parent
|
||||
);
|
||||
};
|
||||
|
||||
R3.API.AR.prototype = Object.create(R3.API.Component.prototype);
|
||||
R3.API.AR.prototype.constructor = R3.API.AR;
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* R3.API.Controls.D3.Editor
|
||||
* @param apiComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.Controls.D3.Editor = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
R3.API.Controls.D3.call(
|
||||
this,
|
||||
apiComponent
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.raycaster)) {
|
||||
apiComponent.raycaster = new R3.D3.API.Raycaster(
|
||||
{
|
||||
parent : this
|
||||
}
|
||||
);
|
||||
}
|
||||
this.raycaster = apiComponent.raycaster;
|
||||
|
||||
};
|
||||
|
||||
R3.API.Controls.D3.Editor.prototype = Object.create(R3.API.Controls.D3.prototype);
|
||||
R3.API.Controls.D3.Editor.prototype.constructor = R3.API.Controls.D3.Editor;
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* R3.API.GraphicsRuntime
|
||||
* @param id
|
||||
* @param name
|
||||
* @param graphicsType
|
||||
* @param parent
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.GraphicsRuntime = function(
|
||||
id,
|
||||
name,
|
||||
graphicsType,
|
||||
parent
|
||||
) {
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Graphics Runtime (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(graphicsType)) {
|
||||
graphicsType = null;
|
||||
}
|
||||
this.graphicsType = graphicsType;
|
||||
|
||||
R3.API.Component.call(
|
||||
this,
|
||||
R3.API.GraphicsRuntime.GetComponentType(this.graphicsType),
|
||||
parent
|
||||
);
|
||||
};
|
||||
|
||||
R3.API.GraphicsRuntime.prototype = Object.create(R3.API.Component.prototype);
|
||||
R3.API.GraphicsRuntime.prototype.constructor = R3.API.GraphicsRuntime;
|
||||
|
||||
R3.API.GraphicsRuntime.GetComponentType = function(graphicsType) {
|
||||
|
||||
var componentType = null;
|
||||
|
||||
switch (graphicsType) {
|
||||
case R3.API.GraphicsRuntime.GRAPHICS_TYPE_NONE :
|
||||
componentType = R3.Component.GRAPHICS;
|
||||
break;
|
||||
case R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS :
|
||||
componentType = R3.Component.GRAPHICS_THREE;
|
||||
break;
|
||||
case R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS :
|
||||
componentType = R3.Component.GRAPHICS_IMPACT;
|
||||
break;
|
||||
default:
|
||||
throw new Error('Invalid graphics type');
|
||||
|
||||
}
|
||||
|
||||
return componentType;
|
||||
};
|
||||
|
||||
R3.API.GraphicsRuntime.GRAPHICS_TYPE_NONE = 0x0;
|
||||
R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS = 0x1;
|
||||
R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS = 0x2;
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* R3.API.GraphicsRuntime.Impact
|
||||
* @constructor
|
||||
* @param apiGraphicsRuntime
|
||||
*/
|
||||
R3.API.GraphicsRuntime.Impact = function(
|
||||
apiGraphicsRuntime
|
||||
) {
|
||||
if (R3.Utils.UndefinedOrNull(apiGraphicsRuntime)) {
|
||||
apiGraphicsRuntime = {
|
||||
graphicsType : R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS
|
||||
};
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiGraphicsRuntime.graphicsType)) {
|
||||
apiGraphicsRuntime.graphicsType = R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS;
|
||||
}
|
||||
|
||||
R3.API.GraphicsRuntime.call(
|
||||
this,
|
||||
apiGraphicsRuntime.id,
|
||||
apiGraphicsRuntime.name,
|
||||
apiGraphicsRuntime.graphicsType,
|
||||
apiGraphicsRuntime.parent
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
R3.API.GraphicsRuntime.Impact.prototype = Object.create(R3.API.GraphicsRuntime.prototype);
|
||||
R3.API.GraphicsRuntime.Impact.prototype.constructor = R3.API.GraphicsRuntime.Impact;
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* R3.API.GraphicsRuntime.Three
|
||||
* @constructor
|
||||
* @param apiGraphicsRuntime
|
||||
*/
|
||||
R3.API.GraphicsRuntime.Three = function(
|
||||
apiGraphicsRuntime
|
||||
) {
|
||||
if (R3.Utils.UndefinedOrNull(apiGraphicsRuntime)) {
|
||||
apiGraphicsRuntime = {
|
||||
graphicsType : R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS
|
||||
};
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiGraphicsRuntime.graphicsType)) {
|
||||
apiGraphicsRuntime.graphicsType = R3.API.GraphicsRuntime.GRAPHICS_TYPE_THREE_JS;
|
||||
}
|
||||
|
||||
R3.API.GraphicsRuntime.call(
|
||||
this,
|
||||
apiGraphicsRuntime.id,
|
||||
apiGraphicsRuntime.name,
|
||||
apiGraphicsRuntime.graphicsType,
|
||||
apiGraphicsRuntime.parent
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
R3.API.GraphicsRuntime.Three.prototype = Object.create(R3.API.GraphicsRuntime.prototype);
|
||||
R3.API.GraphicsRuntime.Three.prototype.constructor = R3.API.GraphicsRuntime.Three;
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* R3.API.Number
|
||||
* @constructor
|
||||
* @param value
|
||||
* @param grain
|
||||
* @param min
|
||||
* @param max
|
||||
*/
|
||||
R3.API.Number = function(
|
||||
value,
|
||||
grain,
|
||||
min,
|
||||
max
|
||||
) {
|
||||
if (R3.Utils.UndefinedOrNull(value)) {
|
||||
value = 0;
|
||||
}
|
||||
this.value = value;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(grain)) {
|
||||
grain = 0.1;
|
||||
}
|
||||
this.grain = grain;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(min)) {
|
||||
min = 0;
|
||||
}
|
||||
this.min = min;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(max)) {
|
||||
max = 100;
|
||||
}
|
||||
this.max = max;
|
||||
};
|
|
@ -0,0 +1,107 @@
|
|||
/**
|
||||
* R3.API.RenderConfiguration
|
||||
* @param id
|
||||
* @param name
|
||||
* @param parentEntity
|
||||
* @param logicalSize
|
||||
* @param aspectRatio
|
||||
* @param scaleMode
|
||||
* @param activeCamera
|
||||
* @param activeScene
|
||||
* @param activeScenes
|
||||
* @param activeComposer
|
||||
* @param activeEffect
|
||||
* @param activeRenderer
|
||||
* @param enableComposer
|
||||
* @param enableEffect
|
||||
* @param defaultMode
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.RenderConfiguration = function (
|
||||
id,
|
||||
name,
|
||||
parentEntity,
|
||||
|
||||
) {
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = "RenderConfiguration (" + this.id + ")";
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(logicalSize)) {
|
||||
logicalSize = new R3.API.Vector2(
|
||||
480,
|
||||
320
|
||||
);
|
||||
}
|
||||
this.logicalSize = logicalSize;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(aspectRatio)) {
|
||||
aspectRatio = R3.API.Renderer.ASPECT_RATIO_3_2;
|
||||
}
|
||||
this.aspectRatio = aspectRatio;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(scaleMode)) {
|
||||
scaleMode = R3.API.Renderer.SCALE_MODE_LETTERBOX;
|
||||
}
|
||||
this.scaleMode = scaleMode;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(activeCamera)) {
|
||||
activeCamera = null;
|
||||
}
|
||||
this.activeCamera = activeCamera;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(activeScene)) {
|
||||
activeScene = null;
|
||||
}
|
||||
this.activeScene = activeScene;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(activeScenes)) {
|
||||
activeScenes = [];
|
||||
}
|
||||
this.activeScenes = activeScenes;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(activeRenderer)) {
|
||||
activeRenderer = null;
|
||||
}
|
||||
this.activeRenderer = activeRenderer;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(activeComposer)) {
|
||||
activeComposer = null;
|
||||
}
|
||||
this.activeComposer = activeComposer;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(activeEffect)) {
|
||||
activeEffect = null;
|
||||
}
|
||||
this.activeEffect = activeEffect;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(enableComposer)) {
|
||||
enableComposer = false;
|
||||
}
|
||||
this.enableComposer = enableComposer;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(enableEffect)) {
|
||||
enableEffect = false;
|
||||
}
|
||||
this.enableEffect = enableEffect;
|
||||
|
||||
|
||||
|
||||
R3.API.Component.call(
|
||||
this,
|
||||
R3.Component.RENDER_CONFIGURATION,
|
||||
parentEntity
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
R3.API.RenderConfiguration.prototype = Object.create(R3.API.Component.prototype);
|
||||
R3.API.RenderConfiguration.prototype.constructor = R3.API.RenderConfiguration;
|
||||
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* R3.API.Renderer.D3.Target
|
||||
* @constructor
|
||||
* @param apiRendererD3
|
||||
* @param target
|
||||
*/
|
||||
R3.API.Renderer.D3.Target = function(
|
||||
apiRendererD3,
|
||||
target
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiRendererD3)) {
|
||||
apiRendererD3 = {};
|
||||
}
|
||||
this.apiRendererD3 = apiRendererD3;
|
||||
|
||||
R3.API.Renderer.D3.call(
|
||||
this,
|
||||
this.apiRendererD3,
|
||||
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,
|
||||
this.apiRendererD3.pixelRatio
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(target)) {
|
||||
target = new R3.D3.API.RenderTarget();
|
||||
}
|
||||
this.target = target;
|
||||
|
||||
};
|
||||
|
||||
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;
|
|
@ -0,0 +1,482 @@
|
|||
/**
|
||||
* AR object
|
||||
* @param augmented
|
||||
* @param apiAR
|
||||
* @returns {R3.AR}
|
||||
* @constructor
|
||||
*/
|
||||
R3.AR = function(
|
||||
augmented,
|
||||
apiAR
|
||||
) {
|
||||
this.augmented = augmented;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiAR)) {
|
||||
apiAR = {};
|
||||
}
|
||||
|
||||
R3.API.AR.call(
|
||||
this,
|
||||
apiAR.id,
|
||||
apiAR.name,
|
||||
apiAR.parent,
|
||||
apiAR.video,
|
||||
apiAR.pathCamera,
|
||||
apiAR.pathMarker,
|
||||
apiAR.scene,
|
||||
apiAR.camera,
|
||||
apiAR.videoScene,
|
||||
apiAR.videoCamera
|
||||
);
|
||||
|
||||
if (
|
||||
R3.Utils.Defined(this.video) &&
|
||||
R3.Utils.Defined(this.video.componentType) &&
|
||||
!(this.video instanceof R3.Video)
|
||||
) {
|
||||
this.video = R3.Component.ConstructFromObject(this.video);
|
||||
}
|
||||
|
||||
if (
|
||||
R3.Utils.Defined(this.scene) &&
|
||||
R3.Utils.Defined(this.scene.componentType) &&
|
||||
!(this.scene instanceof R3.D3.Scene)
|
||||
) {
|
||||
this.scene = R3.Component.ConstructFromObject(this.scene);
|
||||
}
|
||||
|
||||
if (
|
||||
R3.Utils.Defined(this.camera) &&
|
||||
R3.Utils.Defined(this.camera.componentType) &&
|
||||
!(this.camera instanceof R3.D3.Camera.Orthographic)
|
||||
) {
|
||||
this.camera = R3.Component.ConstructFromObject(this.camera);
|
||||
}
|
||||
|
||||
if (
|
||||
R3.Utils.Defined(this.videoScene) &&
|
||||
R3.Utils.Defined(this.videoScene.componentType) &&
|
||||
!(this.videoScene instanceof R3.D3.Scene)
|
||||
) {
|
||||
this.videoScene = R3.Component.ConstructFromObject(this.videoScene);
|
||||
}
|
||||
|
||||
if (
|
||||
R3.Utils.Defined(this.videoCamera) &&
|
||||
R3.Utils.Defined(this.videoCamera.componentType) &&
|
||||
!(this.videoCamera instanceof R3.D3.Camera.Orthographic)
|
||||
) {
|
||||
this.videoCamera = R3.Component.ConstructFromObject(this.videoCamera);
|
||||
}
|
||||
|
||||
R3.Component.call(
|
||||
this,
|
||||
{
|
||||
'video' : R3.Video,
|
||||
'scene' : R3.D3.Scene,
|
||||
'camera' : R3.D3.Camera,
|
||||
'videoScene' : R3.D3.Scene,
|
||||
'videoCamera' : R3.D3.Camera
|
||||
}
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
R3.AR.prototype = Object.create(R3.Component.prototype);
|
||||
R3.AR.prototype.constructor = R3.AR;
|
||||
|
||||
/**
|
||||
* Creates a light instance
|
||||
* @returns {*}
|
||||
*/
|
||||
R3.AR.prototype.createInstance = function() {
|
||||
|
||||
ARController.prototype.setupThree = function(arComponent) {
|
||||
|
||||
return function() {
|
||||
|
||||
if (this.THREE_JS_ENABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.THREE_JS_ENABLED = true;
|
||||
|
||||
/*
|
||||
Listen to getMarker events to keep track of Three.js markers.
|
||||
*/
|
||||
this.addEventListener(
|
||||
'getMarker',
|
||||
function (event) {
|
||||
|
||||
if (event.data.type === artoolkit.PATTERN_MARKER) {
|
||||
|
||||
// console.log('found marker');
|
||||
|
||||
/**
|
||||
* We want to update the camera
|
||||
*/
|
||||
var modelViewMatrix = new THREE.Matrix4().fromArray(event.data.matrix);
|
||||
|
||||
/**
|
||||
* Apply context._axisTransformMatrix - change artoolkit axis to match usual webgl one
|
||||
*/
|
||||
var tmpMatrix = new THREE.Matrix4().copy(this._artoolkitProjectionAxisTransformMatrix);
|
||||
|
||||
tmpMatrix.multiply(modelViewMatrix);
|
||||
|
||||
modelViewMatrix.copy(tmpMatrix);
|
||||
|
||||
/**
|
||||
* Change axis orientation on marker - artoolkit say Z is normal to the marker - ar.js say Y is normal to the marker
|
||||
*/
|
||||
var markerAxisTransformMatrix = new THREE.Matrix4().makeRotationX(Math.PI / 2);
|
||||
modelViewMatrix.multiply(markerAxisTransformMatrix);
|
||||
arComponent.camera.instance.matrix.getInverse(modelViewMatrix);
|
||||
|
||||
/**
|
||||
* Decompose - the matrix into .position, .quaternion, .scale
|
||||
*/
|
||||
arComponent.camera.instance.matrix.decompose(
|
||||
arComponent.camera.instance.position,
|
||||
arComponent.camera.instance.quaternion,
|
||||
arComponent.camera.instance.scale
|
||||
);
|
||||
|
||||
// get projectionMatrixArr from artoolkit
|
||||
var projectionMatrixArr = this.camera_mat;
|
||||
|
||||
var projectionMatrix = new THREE.Matrix4().fromArray(projectionMatrixArr);
|
||||
|
||||
// apply context._axisTransformMatrix - change artoolkit axis to match usual webgl one
|
||||
projectionMatrix.multiply(this._artoolkitProjectionAxisTransformMatrix);
|
||||
|
||||
arComponent.camera.instance.projectionMatrix.copy(projectionMatrix);
|
||||
|
||||
arComponent.camera.updateFromInstance();
|
||||
|
||||
arComponent.camera.instance.fov = arComponent.camera.fov;
|
||||
arComponent.camera.instance.near = arComponent.camera.near;
|
||||
arComponent.camera.instance.far = arComponent.camera.far;
|
||||
arComponent.camera.instance.filmGauge = arComponent.camera.filmGauge;
|
||||
arComponent.camera.instance.filmOffset = arComponent.camera.filmOffset;
|
||||
arComponent.camera.instance.focus = arComponent.camera.focus;
|
||||
arComponent.camera.instance.zoom = arComponent.camera.zoom;
|
||||
arComponent.camera.instance.aspect = arComponent.camera.aspect;
|
||||
arComponent.camera.instance.updateProjectionMatrix();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
this.threePatternMarkers = {};
|
||||
|
||||
this._artoolkitProjectionAxisTransformMatrix = new THREE.Matrix4();
|
||||
this._artoolkitProjectionAxisTransformMatrix.multiply(new THREE.Matrix4().makeRotationY(Math.PI));
|
||||
this._artoolkitProjectionAxisTransformMatrix.multiply(new THREE.Matrix4().makeRotationZ(Math.PI));
|
||||
}
|
||||
}(this);
|
||||
|
||||
R3.Event.Emit(
|
||||
R3.Event.GET_RENDER_CONFIGURATION,
|
||||
null,
|
||||
function (renderConfiguration) {
|
||||
|
||||
if (this.scene === null) {
|
||||
this.scene = renderConfiguration.activeScene;
|
||||
}
|
||||
|
||||
if (this.camera === null) {
|
||||
this.camera = renderConfiguration.activeCamera;
|
||||
}
|
||||
|
||||
if (this.renderer === null) {
|
||||
this.renderer = renderConfiguration.activeRenderer;
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
if (this.augmented.augmentedType === R3.AugmentedRuntime.JS_AR_TOOLKIT_5) {
|
||||
|
||||
console.warn('Using js artoolkit 5');
|
||||
|
||||
if (this.scene === null) {
|
||||
console.warn('there is no default scene to create an AR component with');
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.camera === null) {
|
||||
console.warn('there is no default camera to create an AR component with');
|
||||
return;
|
||||
}
|
||||
|
||||
ARController.getUserMediaThreeScene(
|
||||
{
|
||||
maxARVideoSize: 320,
|
||||
cameraParam: this.pathCamera,
|
||||
|
||||
onSuccess: function (arScene,
|
||||
arController,
|
||||
arCamera) {
|
||||
|
||||
R3.Event.Emit(
|
||||
R3.Event.GET_RENDER_CONFIGURATION,
|
||||
null,
|
||||
function(renderConfiguration) {
|
||||
|
||||
this.videoCamera.instance = arScene.videoCamera;
|
||||
|
||||
this.videoScene.instance = arScene.videoScene;
|
||||
|
||||
this.videoScene.camera = this.videoCamera;
|
||||
|
||||
//arScene.videoScene.children[0].material.map.flipY = true;
|
||||
|
||||
/**
|
||||
* Also update the video texture before render
|
||||
*/
|
||||
this.subscribe(
|
||||
R3.Event.BEFORE_RENDER,
|
||||
function() {
|
||||
arScene.videoScene.children[0].material.map.needsUpdate = true;
|
||||
}
|
||||
);
|
||||
|
||||
if (renderConfiguration.activeScenes.indexOf(this.videoScene) === -1) {
|
||||
console.log('not adding video scene to default active scenes');
|
||||
//renderConfiguration.activeScenes.unshift(this.videoScene);
|
||||
}
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
arController.loadMarker(
|
||||
this.pathMarker,
|
||||
function (markerId) {
|
||||
|
||||
var markerRoot = arController.createThreeMarker(markerId);
|
||||
|
||||
markerRoot.add(this.scene.instance);
|
||||
|
||||
this.instance = {
|
||||
arScene: arScene,
|
||||
arController: arController,
|
||||
arCamera: arCamera
|
||||
};
|
||||
|
||||
R3.Component.prototype.createInstance.call(this);
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
}.bind(this)
|
||||
}
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.augmented.augmentedType === R3.AugmentedRuntime.AR_JS) {
|
||||
|
||||
console.log('using ar.js');
|
||||
|
||||
var size = R3.Utils.GetWindowSize();
|
||||
|
||||
this.arToolkitSource = new THREEx.ArToolkitSource(
|
||||
{
|
||||
sourceType: 'webcam',
|
||||
sourceWidth: size.width,
|
||||
sourceHeight: size.height,
|
||||
displayWidth: size.width,
|
||||
displayHeight: size.height
|
||||
}
|
||||
);
|
||||
|
||||
this.arToolkitSource.init(
|
||||
|
||||
function initialized() {
|
||||
|
||||
this.arToolkitSource.domElement.setAttribute('muted', '');
|
||||
|
||||
this.video.instance = this.arToolkitSource.domElement;
|
||||
|
||||
this.arToolkitContext = new THREEx.ArToolkitContext(
|
||||
{
|
||||
cameraParametersUrl: this.pathCamera,
|
||||
detectionMode: 'mono',
|
||||
maxDetectionRate: 30,
|
||||
canvasWidth: 80*3,
|
||||
canvasHeight: 60*3
|
||||
}
|
||||
);
|
||||
|
||||
this.arToolkitContext.init(
|
||||
|
||||
function initialized() {
|
||||
|
||||
this.controls = new THREEx.ArMarkerControls(
|
||||
this.arToolkitContext,
|
||||
this.camera.instance,
|
||||
{
|
||||
type: 'pattern',
|
||||
patternUrl: this.pathMarker,
|
||||
changeMatrixMode: 'cameraTransformMatrix'
|
||||
}
|
||||
);
|
||||
|
||||
this.instance = {
|
||||
arToolkitContext: this.arToolkitContext,
|
||||
arToolkitSource: this.arToolkitSource
|
||||
};
|
||||
|
||||
this.scene.instance.add(this.camera.instance);
|
||||
|
||||
this.resize();
|
||||
|
||||
/**
|
||||
* Copy the projectionmatrix of the context to our camera
|
||||
* UPDATE - don't do this cause it messes up the projection matrix
|
||||
*/
|
||||
// this.camera.instance.projectionMatrix.copy(
|
||||
// this.arToolkitContext.getProjectionMatrix()
|
||||
// );
|
||||
|
||||
|
||||
R3.Component.prototype.createInstance.call(this);
|
||||
|
||||
}.bind(this)
|
||||
)
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
R3.AR.prototype.updateInstance = function(property) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(property)) {
|
||||
console.warn('unknown property update for AR: ' + property);
|
||||
}
|
||||
|
||||
if (property === 'id') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'name') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'video') {
|
||||
console.warn('todo: update video');
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'pathCamera') {
|
||||
console.warn('todo: update pathCamera');
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'pathMarker') {
|
||||
console.warn('todo: update pathMarker');
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'scene') {
|
||||
console.warn('todo: update scene');
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'camera') {
|
||||
console.warn('todo: update camera');
|
||||
//
|
||||
// if (this.augmented.augmentedType === R3.AugmentedRuntime.AR_JS) {
|
||||
//
|
||||
// if (this.camera) {
|
||||
// this.controls = new THREEx.ArMarkerControls(
|
||||
// this.arToolkitContext,
|
||||
// this.camera.instance,
|
||||
// {
|
||||
// type: 'pattern',
|
||||
// patternUrl: this.pathMarker,
|
||||
// changeMatrixMode: 'cameraTransformMatrix'
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'videoScene') {
|
||||
console.warn('todo: update videoScene');
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'videoCamera') {
|
||||
console.warn('todo: update videoCamera');
|
||||
return;
|
||||
}
|
||||
|
||||
R3.Component.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a R3.AR to a R3.API.AR
|
||||
* @returns {R3.API.AR}
|
||||
*/
|
||||
R3.AR.prototype.toApiObject = function() {
|
||||
|
||||
return new R3.API.AR(
|
||||
this.id,
|
||||
this.name,
|
||||
R3.Utils.IdOrNull(this.parent),
|
||||
R3.Utils.IdOrNull(this.video),
|
||||
this.pathCamera,
|
||||
this.pathMarker,
|
||||
R3.Utils.IdOrNull(this.scene),
|
||||
R3.Utils.IdOrNull(this.camera),
|
||||
R3.Utils.IdOrNull(this.videoScene),
|
||||
R3.Utils.IdOrNull(this.videoCamera)
|
||||
);
|
||||
};
|
||||
|
||||
R3.AR.prototype.beforeRender = function() {
|
||||
|
||||
if (this.augmented.augmentedType === R3.AugmentedRuntime.JS_AR_TOOLKIT_5) {
|
||||
this.instance.arScene.process();
|
||||
this.instance.arScene.renderOn(renderer.instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.augmented.augmentedType === R3.AugmentedRuntime.AR_JS) {
|
||||
this.arToolkitContext.update(
|
||||
this.arToolkitSource.domElement
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
R3.AR.prototype.resize = function() {
|
||||
|
||||
if (this.augmented.augmentedType === R3.AugmentedRuntime.AR_JS) {
|
||||
|
||||
console.log('updating AR size');
|
||||
|
||||
this.arToolkitSource.onResizeElement();
|
||||
|
||||
if (this.arToolkitContext.arController !== null){
|
||||
this.arToolkitSource.copyElementSizeTo(
|
||||
this.arToolkitContext.arController.canvas
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Augmented
|
||||
* @param id
|
||||
* @param name
|
||||
* @param augmentedType
|
||||
* @constructor
|
||||
*/
|
||||
R3.AugmentedRuntime = function(
|
||||
id,
|
||||
name,
|
||||
augmentedType
|
||||
) {
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Augmented (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(augmentedType)) {
|
||||
augmentedType = R3.AugmentedRuntime.JS_AR_TOOLKIT_5;
|
||||
}
|
||||
this.augmentedType = augmentedType;
|
||||
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
* R3.AugmentedRuntime Types
|
||||
* @type {number}
|
||||
*/
|
||||
R3.AugmentedRuntime.JS_AR_TOOLKIT_5 = 0x1;
|
||||
R3.AugmentedRuntime.AR_JS = 0x2;
|
||||
|
||||
R3.AugmentedRuntime.prototype.createInstance = function() {
|
||||
if (this.augmentedType === R3.AugmentedRuntime.JS_AR_TOOLKIT_5) {
|
||||
this.instance = {
|
||||
ARController : ARController,
|
||||
ARCameraParam : ARCameraParam
|
||||
};
|
||||
} else {
|
||||
this.instance = null;
|
||||
}
|
||||
};
|
||||
|
||||
R3.AugmentedRuntime.prototype.updateInstance = function(property) {
|
||||
if (property === 'augmentedType') {
|
||||
this.createInstance();
|
||||
}
|
||||
};
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* R3.Controls.D3.Editor
|
||||
* @param apiComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.Controls.D3.Editor = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
__RUNTIME_COMPONENT__;
|
||||
|
||||
R3.Controls.D3.call(
|
||||
this,
|
||||
true
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Inheritance
|
||||
* @type {R3.Controls}
|
||||
*/
|
||||
R3.Controls.D3.Editor.prototype = Object.create(R3.Controls.D3.prototype);
|
||||
R3.Controls.D3.Editor.prototype.constructor = R3.Controls.D3.Editor;
|
||||
|
||||
/**
|
||||
* Create Instance
|
||||
*/
|
||||
R3.Controls.D3.Editor.prototype.createInstance = function() {
|
||||
|
||||
this.instance = this.graphics.EditorControls(this);
|
||||
|
||||
__CREATE_INSTANCE__;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update Instance
|
||||
*/
|
||||
R3.Controls.D3.Editor.prototype.updateInstance = function(property) {
|
||||
|
||||
if (
|
||||
property === 'raycaster'
|
||||
) {
|
||||
console.warn('todo : update raycaster');
|
||||
}
|
||||
|
||||
R3.Controls.D3.prototype.updateInstance.call(this, property);
|
||||
};
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* R3.D3.API.Camera.Stereo.Anaglyph
|
||||
* @constructor
|
||||
* @param apiStereoCamera
|
||||
* @param colorMatrixLeft
|
||||
* @param colorMatrixRight
|
||||
* @param orthographicCamera
|
||||
* @param orthographicScene
|
||||
*/
|
||||
R3.D3.API.Camera.Stereo.Anaglyph = function(
|
||||
apiStereoCamera,
|
||||
colorMatrixLeft,
|
||||
colorMatrixRight,
|
||||
orthographicCamera,
|
||||
orthographicScene,
|
||||
renderTargetL,
|
||||
renderTargetR,
|
||||
shaderMaterial,
|
||||
meshPlane
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiStereoCamera)) {
|
||||
apiStereoCamera = {
|
||||
stereoType : R3.D3.API.Camera.Stereo.STEREO_MODE_ANAGLYPH
|
||||
};
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiStereoCamera.stereoType)) {
|
||||
apiStereoCamera.stereoType = R3.D3.API.Camera.Stereo.STEREO_MODE_ANAGLYPH;
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(colorMatrixLeft)) {
|
||||
colorMatrixLeft = [
|
||||
1.0671679973602295, -0.0016435992438346148, 0.0001777536963345483, // r out
|
||||
-0.028107794001698494, -0.00019593400065787137, -0.0002875397040043026, // g out
|
||||
-0.04279090091586113, 0.000015809757314855233, -0.00024287120322696865 // b out
|
||||
]
|
||||
}
|
||||
this.colorMatrixLeft = colorMatrixLeft;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(colorMatrixRight)) {
|
||||
colorMatrixRight = [
|
||||
-0.0355340838432312, -0.06440307199954987, 0.018319187685847282, // r out
|
||||
-0.10269022732973099, 0.8079727292060852, -0.04835830628871918, // g out
|
||||
0.0001224992738571018, -0.009558862075209618, 0.567823588848114 // b out
|
||||
]
|
||||
}
|
||||
this.colorMatrixRight = colorMatrixRight;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(orthographicCamera)) {
|
||||
orthographicCamera = new R3.D3.API.Camera.Orthographic(null, null, 0, 1, -1, 1, 1, -1);
|
||||
}
|
||||
this.orthographicCamera = orthographicCamera;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(orthographicScene)) {
|
||||
orthographicScene = new R3.D3.API.Scene(null, 'Orthographic Stereo Anaglyph Scene');
|
||||
}
|
||||
this.orthographicScene = orthographicScene;
|
||||
//
|
||||
// if (R3.Utils.UndefinedOrNull(renderTargetL)) {
|
||||
// renderTargetL = new R3.D3.API.RenderTarget(null, null, null, )
|
||||
// }
|
||||
//
|
||||
// renderTargetL,
|
||||
// renderTargetR,
|
||||
// shaderMaterial,
|
||||
// meshPlane
|
||||
|
||||
R3.D3.API.Camera.Stereo.call(
|
||||
this,
|
||||
apiStereoCamera,
|
||||
apiStereoCamera.stereoType,
|
||||
apiStereoCamera.eyeSep,
|
||||
apiStereoCamera.main,
|
||||
apiStereoCamera.cameraL,
|
||||
apiStereoCamera.cameraR
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.API.Camera.Stereo.Anaglyph.prototype = Object.create(R3.D3.API.Camera.Stereo.prototype);
|
||||
R3.D3.API.Camera.Stereo.Anaglyph.prototype.constructor = R3.D3.API.Camera.Stereo.Anaglyph;
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* R3.D3.API.Camera.Stereo.Normal
|
||||
* @constructor
|
||||
* @param apiStereoCamera
|
||||
*/
|
||||
R3.D3.API.Camera.Stereo.Normal = function(
|
||||
apiStereoCamera
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiStereoCamera)) {
|
||||
apiStereoCamera = {
|
||||
stereoType : R3.D3.API.Camera.Stereo.STEREO_TYPE_NORMAL
|
||||
};
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiStereoCamera.stereoType)) {
|
||||
apiStereoCamera.stereoType = R3.D3.API.Camera.Stereo.STEREO_TYPE_NORMAL;
|
||||
}
|
||||
|
||||
R3.D3.API.Camera.Stereo.call(
|
||||
this,
|
||||
apiStereoCamera,
|
||||
apiStereoCamera.stereoType,
|
||||
apiStereoCamera.eyeSep,
|
||||
apiStereoCamera.main,
|
||||
apiStereoCamera.cameraL,
|
||||
apiStereoCamera.cameraR
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.API.Camera.Stereo.Normal.prototype = Object.create(R3.D3.API.Camera.Stereo.prototype);
|
||||
R3.D3.API.Camera.Stereo.Normal.prototype.constructor = R3.D3.API.Camera.Stereo.Normal;
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* R3.D3.API.Composer.RenderTarget
|
||||
* @param apiComponent
|
||||
*
|
||||
* @property renderTarget
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Composer.RenderTarget = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
R3.D3.API.Composer.call(
|
||||
this,
|
||||
apiComponent
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.renderTarget)) {
|
||||
apiComponent.renderTarget = new R3.D3.API.RenderTarget(
|
||||
{
|
||||
parent : this
|
||||
}
|
||||
);
|
||||
}
|
||||
this.renderTarget = apiComponent.renderTarget
|
||||
|
||||
};
|
||||
|
||||
R3.D3.API.Composer.RenderTarget.prototype = Object.create(R3.D3.API.Composer.prototype);
|
||||
R3.D3.API.Composer.RenderTarget.prototype.constructor = R3.D3.API.Composer.RenderTarget;
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* R3.D3.API.Composer.Renderer
|
||||
* @param apiComposer
|
||||
*
|
||||
* @property renderer
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Composer.Renderer = function(
|
||||
apiComposer
|
||||
) {
|
||||
|
||||
R3.D3.API.Composer.call(
|
||||
this,
|
||||
apiComponent
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.renderer)) {
|
||||
apiComponent.renderer = this.getFirstParent(R3.API.Renderer.D3);
|
||||
}
|
||||
this.renderer = apiComponent.renderer;
|
||||
|
||||
};
|
||||
|
||||
R3.D3.API.Composer.Renderer.prototype = Object.create(R3.D3.API.Composer.prototype);
|
||||
R3.D3.API.Composer.Renderer.prototype.constructor = R3.D3.API.Composer.Renderer;
|
|
@ -0,0 +1,255 @@
|
|||
/**
|
||||
* Raw Editor API object - should always correspond with the Editor Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param baseUrl
|
||||
* @param path
|
||||
* @param imageFactory
|
||||
* @param games [R3.API.D3.Game]
|
||||
* @param scenes
|
||||
* @param cameras
|
||||
* @param composers
|
||||
* @param viewports
|
||||
* @param renderers
|
||||
* @param renderTargets
|
||||
* @param systems
|
||||
* @param entityManager
|
||||
* @param allSelected
|
||||
* @param selectedObjects
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Editor = function(
|
||||
id,
|
||||
name,
|
||||
baseUrl,
|
||||
path,
|
||||
imageFactory,
|
||||
games,
|
||||
scenes,
|
||||
cameras,
|
||||
composers,
|
||||
viewports,
|
||||
renderers,
|
||||
renderTargets,
|
||||
systems,
|
||||
entityManager,
|
||||
allSelected,
|
||||
selectedObjects,
|
||||
parentEntity
|
||||
) {
|
||||
R3.Component.call(
|
||||
this,
|
||||
R3.Component.COMPONENT_EDITOR,
|
||||
{
|
||||
'imageFactory' : R3.D3.ImageFactory,
|
||||
'games' : [R3.D3.Game],
|
||||
'scenes' : [R3.D3.Scene],
|
||||
'cameras' : [R3.D3.Camera],
|
||||
'composers' : [R3.D3.Composer],
|
||||
'viewports' : [R3.D3.Viewport],
|
||||
'renderers' : [R3.D3.Renderer],
|
||||
'renderTargets' : [R3.D3.RenderTarget],
|
||||
'systems' : [R3.System],
|
||||
'entityManager' : R3.EntityManager
|
||||
},
|
||||
null,
|
||||
parentEntity
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Editor (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(baseUrl)) {
|
||||
baseUrl = '';
|
||||
}
|
||||
this.baseUrl = baseUrl;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(path)) {
|
||||
path = '';
|
||||
}
|
||||
this.path = path;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(imageFactory)) {
|
||||
imageFactory = null;
|
||||
}
|
||||
this.imageFactory = imageFactory;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(games)) {
|
||||
games = [];
|
||||
}
|
||||
this.games = games;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(scenes)) {
|
||||
scenes = [];
|
||||
}
|
||||
this.scenes = scenes;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(cameras)) {
|
||||
cameras = [];
|
||||
}
|
||||
this.cameras = cameras;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(composers)) {
|
||||
composers = [];
|
||||
}
|
||||
this.composers = composers;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(viewports)) {
|
||||
viewports = [];
|
||||
}
|
||||
this.viewports = viewports;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(renderers)) {
|
||||
renderers = [];
|
||||
}
|
||||
this.renderers = renderers;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(renderTargets)) {
|
||||
renderTargets = [];
|
||||
}
|
||||
this.renderTargets = renderTargets;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(systems)) {
|
||||
systems = [];
|
||||
}
|
||||
this.systems = systems;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(entityManager)) {
|
||||
entityManager = new R3.API.EntityManager();
|
||||
}
|
||||
this.entityManager = entityManager;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(allSelected)) {
|
||||
allSelected = false;
|
||||
}
|
||||
this.allSelected = allSelected;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(selectedObjects)) {
|
||||
selectedObjects = [];
|
||||
}
|
||||
this.selectedObjects = selectedObjects;
|
||||
|
||||
};
|
||||
|
||||
R3.D3.API.Editor.prototype = Object.create(R3.Component.prototype);
|
||||
R3.D3.API.Editor.prototype.constructor = R3.D3.API.Editor;
|
||||
|
||||
/**
|
||||
* Creates an API Editor from an Object Editor
|
||||
* @param objectEditor
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Editor.FromObjectEditor = function(objectEditor) {
|
||||
|
||||
var apiImageFactory = null;
|
||||
var apiGames = [];
|
||||
var apiScenes = [];
|
||||
var apiCameras = [];
|
||||
var apiComposers = [];
|
||||
var apiViewports = [];
|
||||
var apiRenderers = [];
|
||||
var apiRenderTargets = [];
|
||||
var apiSystems = [];
|
||||
var apiEntityManager = null;
|
||||
|
||||
if (objectEditor.imageFactory) {
|
||||
apiImageFactory = R3.D3.API.ImageFactory.FromObjectImageFactory(objectEditor.imageFactory);
|
||||
}
|
||||
|
||||
if (objectEditor.games) {
|
||||
apiGames = objectEditor.games.map(
|
||||
function(objectGame){
|
||||
return R3.D3.API.Game.FromObjectGame(objectGame);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectEditor.scenes) {
|
||||
apiScenes = objectEditor.scenes.map(
|
||||
function(objectScene){
|
||||
return R3.D3.API.Scene.FromObjectScene(objectScene);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectEditor.cameras) {
|
||||
apiCameras = objectEditor.cameras.map(
|
||||
function(objectCamera){
|
||||
return R3.D3.API.Camera.FromObjectCamera(objectCamera);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectEditor.composers) {
|
||||
apiComposers = objectEditor.composers.map(
|
||||
function(objectComposer){
|
||||
return R3.D3.API.Composer.FromObjectComponent(objectComposer);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectEditor.viewports) {
|
||||
apiViewports = objectEditor.viewports.map(
|
||||
function(objectViewport){
|
||||
return R3.D3.API.Viewport.FromObjectViewport(objectViewport);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectEditor.renderers) {
|
||||
apiRenderers = objectEditor.renderers.map(
|
||||
function(objectRenderer){
|
||||
return R3.D3.API.Renderer.FromObjectComponent(objectRenderer);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectEditor.renderTargets) {
|
||||
apiRenderTargets = objectEditor.renderTargets.map(
|
||||
function(objectRenderTarget){
|
||||
return R3.D3.API.RenderTarget.FromObjectComponent(objectRenderTarget);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectEditor.systems) {
|
||||
apiSystems = objectEditor.systems.map(
|
||||
function(objectSystem){
|
||||
return R3.API.System.FromObjectComponent(objectSystem);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectEditor.entityManager) {
|
||||
apiEntityManager = R3.API.EntityManager.FromObjectEntityManager(objectEditor.entityManager);
|
||||
}
|
||||
|
||||
return new R3.D3.API.Editor(
|
||||
objectEditor.id,
|
||||
objectEditor.name,
|
||||
objectEditor.baseUrl,
|
||||
objectEditor.path,
|
||||
apiImageFactory,
|
||||
apiGames,
|
||||
apiScenes,
|
||||
apiCameras,
|
||||
apiComposers,
|
||||
apiViewports,
|
||||
apiRenderers,
|
||||
apiRenderTargets,
|
||||
apiSystems,
|
||||
apiEntityManager,
|
||||
objectEditor.allSelected,
|
||||
objectEditor.selectedObjects,
|
||||
objectEditor.parentEntity
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
/**
|
||||
* Follow Component
|
||||
* @param id
|
||||
* @param name
|
||||
* @param currentComponent R3.Component
|
||||
* @param targetComponent R3.Component
|
||||
* @param targetPositionOffset R3.API.Vector3
|
||||
* @param minDistance
|
||||
* @param moveSpeed
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Follow = function (
|
||||
id,
|
||||
name,
|
||||
currentComponent,
|
||||
targetComponent,
|
||||
targetPositionOffset,
|
||||
minDistance,
|
||||
moveSpeed,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
R3.Component.call(
|
||||
this,
|
||||
R3.Component.COMPONENT_FOLLOW,
|
||||
{
|
||||
'currentComponent': R3.Component,
|
||||
'targetComponent': R3.Component
|
||||
},
|
||||
parentEntity
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = this.constructor.name;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(currentComponent)) {
|
||||
currentComponent = null;
|
||||
}
|
||||
this.currentComponent = currentComponent;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(targetComponent)) {
|
||||
targetComponent = null;
|
||||
}
|
||||
this.targetComponent = targetComponent;
|
||||
|
||||
if(R3.Utils.UndefinedOrNull(targetPositionOffset)) {
|
||||
targetPositionOffset = new R3.API.Vector3(0, 0, 0);
|
||||
}
|
||||
this.targetPositionOffset = targetPositionOffset;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(minDistance)) {
|
||||
minDistance = 2;
|
||||
}
|
||||
this.minDistance = minDistance;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(moveSpeed)) {
|
||||
moveSpeed = 12.5;
|
||||
}
|
||||
this.moveSpeed = moveSpeed;
|
||||
|
||||
this.target = new R3.API.Vector3(0, 0, 0);
|
||||
|
||||
this.targetToParent = new R3.API.Vector3(0, 0, 0);
|
||||
|
||||
this.rotatedTargetOffset = new R3.API.Vector3(0, 0, 0);
|
||||
|
||||
this.rotated = new R3.API.Quaternion();
|
||||
};
|
||||
|
||||
R3.D3.API.Follow.prototype = Object.create(R3.Component.prototype);
|
||||
R3.D3.API.Follow.prototype.constructor = R3.D3.API.Follow;
|
||||
|
||||
/**
|
||||
* Object to R3.D3.API.Follow
|
||||
* @param objectComponent
|
||||
* @returns {R3.D3.API.Follow}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Follow.FromObject = function(objectComponent) {
|
||||
return new R3.D3.API.Follow(
|
||||
objectComponent.id,
|
||||
objectComponent.name,
|
||||
objectComponent.currentComponent,
|
||||
objectComponent.targetComponent,
|
||||
R3.API.Vector3.FromObject(objectComponent.targetPositionOffset),
|
||||
objectComponent.minDistance,
|
||||
objectComponent.moveSpeed,
|
||||
objectComponent.parentEntity
|
||||
);
|
||||
};
|
|
@ -0,0 +1,215 @@
|
|||
/**
|
||||
* Raw Game API object - should always correspond with the Game Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param gameType
|
||||
* @param imageFactory
|
||||
* @param width
|
||||
* @param height
|
||||
* @param baseUrl
|
||||
* @param path
|
||||
* @param cameras
|
||||
* @param renderers
|
||||
* @param composers
|
||||
* @param renderTargets
|
||||
* @param systems
|
||||
* @param viewports
|
||||
* @param entityManager
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Game = function(
|
||||
id,
|
||||
name,
|
||||
baseUrl,
|
||||
path,
|
||||
imageFactory,
|
||||
gameType,
|
||||
cameras,
|
||||
composers,
|
||||
viewports,
|
||||
renderers,
|
||||
renderTargets,
|
||||
systems,
|
||||
entityManager,
|
||||
parentEntity
|
||||
) {
|
||||
R3.Component.call(
|
||||
this,
|
||||
R3.Component.COMPONENT_GAME,
|
||||
{
|
||||
'imageFactory' : R3.D3.ImageFactory,
|
||||
'cameras' : [R3.D3.Camera],
|
||||
'composers' : [R3.D3.Composer],
|
||||
'viewports' : [R3.D3.Viewport],
|
||||
'renderers' : [R3.D3.Renderer],
|
||||
'renderTargets' : [R3.D3.RenderTarget],
|
||||
'systems' : [R3.System],
|
||||
'entityManager' : R3.EntityManager
|
||||
},
|
||||
null,
|
||||
parentEntity
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Game (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(baseUrl)) {
|
||||
baseUrl = '';
|
||||
console.warn('The base URL required for downloading images is not set - textured meshes will not render properly');
|
||||
}
|
||||
this.baseUrl = baseUrl;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(path)) {
|
||||
path = '';
|
||||
}
|
||||
this.path = path;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(imageFactory)) {
|
||||
imageFactory = null;
|
||||
}
|
||||
this.imageFactory = imageFactory;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(gameType)) {
|
||||
gameType = R3.D3.Game.GAME_TYPE_VR_PONG;
|
||||
}
|
||||
this.gameType = gameType;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(cameras)) {
|
||||
cameras = [];
|
||||
}
|
||||
this.cameras = cameras;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(composers)) {
|
||||
composers = [];
|
||||
}
|
||||
this.composers = composers;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(viewports)) {
|
||||
viewports = [];
|
||||
}
|
||||
this.viewports = viewports;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(renderers)) {
|
||||
renderers = [];
|
||||
}
|
||||
this.renderers = renderers;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(renderTargets)) {
|
||||
renderTargets = [];
|
||||
}
|
||||
this.renderTargets = renderTargets;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(systems)) {
|
||||
systems = [];
|
||||
}
|
||||
this.systems = systems;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(entityManager)) {
|
||||
entityManager = null;
|
||||
}
|
||||
this.entityManager = entityManager;
|
||||
|
||||
};
|
||||
|
||||
R3.D3.API.Game.prototype = Object.create(R3.Component.prototype);
|
||||
R3.D3.API.Game.prototype.constructor = R3.D3.API.Game;
|
||||
|
||||
/**
|
||||
* Creates an API camera from an Object camera
|
||||
* @param objectGame
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Game.FromObjectGame = function(objectGame) {
|
||||
|
||||
var apiImageFactory = null;
|
||||
var apiCameras = [];
|
||||
var apiComposers = [];
|
||||
var apiViewports = [];
|
||||
var apiRenderers = [];
|
||||
var apiRenderTargets = [];
|
||||
var apiSystems = [];
|
||||
|
||||
var apiEntityManager = null;
|
||||
|
||||
if (objectGame.imageFactory) {
|
||||
apiImageFactory = R3.D3.API.ImageFactory.FromObjectImageFactory(objectGame.imageFactory);
|
||||
}
|
||||
|
||||
if (objectGame.cameras) {
|
||||
apiCameras = objectGame.cameras.map(
|
||||
function(objectCamera){
|
||||
return R3.D3.API.Camera.FromObjectCamera(objectCamera);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectGame.composers) {
|
||||
apiComposers = objectGame.composers.map(
|
||||
function(objectComposer){
|
||||
return R3.D3.API.Composer.FromObjectComponent(objectComposer);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectGame.viewports) {
|
||||
apiViewports = objectGame.viewports.map(
|
||||
function(objectViewport){
|
||||
return R3.D3.API.Viewport.FromObjectViewport(objectViewport);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectGame.renderers) {
|
||||
apiRenderers = objectGame.renderers.map(
|
||||
function(objectRenderer){
|
||||
return R3.D3.API.Renderer.FromObjectComponent(objectRenderer);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectGame.renderTargets) {
|
||||
apiRenderTargets = objectGame.renderTargets.map(
|
||||
function(objectRenderTarget){
|
||||
return R3.D3.API.RenderTarget.FromObjectComponent(objectRenderTarget);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectGame.systems) {
|
||||
apiSystems = objectGame.systems.map(
|
||||
function(objectSystem){
|
||||
return R3.API.System.FromObjectComponent(objectSystem);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (objectGame.entityManager) {
|
||||
apiEntityManager = R3.API.EntityManager.FromObjectEntityManager(objectGame.entityManager);
|
||||
}
|
||||
|
||||
return new R3.D3.API.Game(
|
||||
objectGame.id,
|
||||
objectGame.name,
|
||||
objectGame.baseUrl,
|
||||
objectGame.path,
|
||||
apiImageFactory,
|
||||
objectGame.gameType,
|
||||
apiCameras,
|
||||
apiComposers,
|
||||
apiViewports,
|
||||
apiRenderers,
|
||||
apiRenderTargets,
|
||||
apiSystems,
|
||||
apiEntityManager,
|
||||
objectGame.parentEntity
|
||||
);
|
||||
|
||||
};
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Graphics API
|
||||
* @param id String
|
||||
* @param name
|
||||
* @param graphicsType
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Graphics = function (
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
R3.Component.call(
|
||||
this,
|
||||
R3.Component.COMPONENT_GRAPHICS,
|
||||
null,
|
||||
null,
|
||||
parentEntity
|
||||
);
|
||||
|
||||
|
||||
};
|
||||
|
||||
R3.D3.API.Graphics.prototype = Object.create(R3.Component.prototype);
|
||||
R3.D3.API.Graphics.prototype.constructor = R3.D3.API.Graphics;
|
||||
|
||||
/**
|
||||
* Object to R3.D3.API.Graphics
|
||||
* @param objectComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Graphics.FromObjectComponent = function(objectComponent) {
|
||||
return new R3.D3.API.Graphics(
|
||||
objectComponent.id,
|
||||
objectComponent.name,
|
||||
objectComponent.graphicsType,
|
||||
objectComponent.parentEntity
|
||||
);
|
||||
};
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* This component renders a scene
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param helperType
|
||||
* @param object
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Helper = function (
|
||||
id,
|
||||
name,
|
||||
helperType,
|
||||
object,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
R3.Component.call(
|
||||
this,
|
||||
R3.Component.COMPONENT_HELPER,
|
||||
null,
|
||||
null,
|
||||
parentEntity
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Helper (' + id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(object)) {
|
||||
console.warn('Cannot create a helper for an Object which does not exist');
|
||||
throw new Error('Cannot create a helper for an Object which does not exist');
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(helperType)) {
|
||||
if (
|
||||
object instanceof R3.D3.Mesh &&
|
||||
object.meshType != R3.D3.Mesh.TYPE_CURVE
|
||||
) {
|
||||
helperType = R3.D3.Helper.HELPER_TYPE_WIREFRAME;
|
||||
}
|
||||
|
||||
if (object instanceof R3.D3.Light) {
|
||||
if (object.lightType == R3.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
||||
helperType = R3.D3.Helper.HELPER_TYPE_DIRECTIONAL_LIGHT;
|
||||
}
|
||||
|
||||
if (object.lightType == R3.D3.Light.LIGHT_TYPE_POINT) {
|
||||
helperType = R3.D3.Helper.HELPER_TYPE_POINT_LIGHT;
|
||||
}
|
||||
|
||||
if (object.lightType == R3.D3.Light.LIGHT_TYPE_SPOT) {
|
||||
helperType = R3.D3.Helper.HELPER_TYPE_SPOT_LIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
if (object instanceof R3.D3.Skeleton) {
|
||||
helperType = R3.D3.Helper.HELPER_TYPE_SKELETON;
|
||||
}
|
||||
}
|
||||
this.helperType = helperType;
|
||||
|
||||
};
|
||||
|
||||
R3.D3.API.Helper.prototype = Object.create(R3.Component.prototype);
|
||||
R3.D3.API.Helper.prototype.constructor = R3.D3.API.Helper;
|
||||
|
||||
/**
|
||||
* Object to R3.D3.API.Helper
|
||||
* @param objectComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Helper.FromObjectComponent = function(objectComponent) {
|
||||
return new R3.D3.API.Helper(
|
||||
objectComponent.id,
|
||||
objectComponent.name,
|
||||
objectComponent.helperType,
|
||||
objectComponent.object,
|
||||
objectComponent.parentEntity
|
||||
);
|
||||
};
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* Raw ImageFactory API object - should always correspond with the ImageFactory Schema
|
||||
* @param id
|
||||
* @param name
|
||||
* @param baseUrl String
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.ImageFactory = function(
|
||||
id,
|
||||
name,
|
||||
baseUrl,
|
||||
parentEntity
|
||||
) {
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = 'ImageFactory (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(baseUrl)) {
|
||||
baseUrl = '';
|
||||
console.warn('No baseURL defined for image factory');
|
||||
}
|
||||
this.baseUrl = baseUrl;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(parentEntity)) {
|
||||
parentEntity = null;
|
||||
}
|
||||
this.parentEntity = parentEntity;
|
||||
};
|
||||
|
||||
R3.D3.API.ImageFactory.prototype = Object.create(R3.Component.prototype);
|
||||
R3.D3.API.ImageFactory.prototype.constructor = R3.D3.API.ImageFactory;
|
||||
|
||||
/**
|
||||
* Returns an API ImageFactory from an Object ImageFactory
|
||||
* @param objectImageFactory
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.ImageFactory.FromObject = function(objectImageFactory) {
|
||||
return new R3.D3.API.ImageFactory(
|
||||
objectImageFactory.id,
|
||||
objectImageFactory.name,
|
||||
objectImageFactory.baseUrl,
|
||||
objectImageFactory.parentEntity
|
||||
);
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* R3.D3.API.Input namespace
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Input = function() {};
|
|
@ -0,0 +1,125 @@
|
|||
/**
|
||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param domElementId
|
||||
* @param pathFollowingComponent R3.D3.Mesh
|
||||
* @param parentEntity
|
||||
* @param wheelFL
|
||||
* @param wheelFR
|
||||
* @param wheelRL
|
||||
* @param wheelRR
|
||||
* @param heightOffset
|
||||
* @param distance
|
||||
* @param distanceGrain
|
||||
* @param rotationFactor
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Input.Drive = function (
|
||||
id,
|
||||
name,
|
||||
domElementId,
|
||||
pathFollowingComponent,
|
||||
parentEntity,
|
||||
wheelFL,
|
||||
wheelFR,
|
||||
wheelRL,
|
||||
wheelRR,
|
||||
heightOffset,
|
||||
distance,
|
||||
distanceGrain,
|
||||
rotationFactor
|
||||
) {
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Input.Drive (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(domElementId)) {
|
||||
domElementId = "divCanvas";
|
||||
}
|
||||
this.domElementId = domElementId;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(pathFollowingComponent)) {
|
||||
pathFollowingComponent = null;
|
||||
}
|
||||
this.pathFollowingComponent = pathFollowingComponent;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(parentEntity)) {
|
||||
parentEntity = null;
|
||||
}
|
||||
this.parentEntity = parentEntity;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(wheelFL)) {
|
||||
wheelFL = null;
|
||||
}
|
||||
this.wheelFL = wheelFL;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(wheelFR)) {
|
||||
wheelFR = null;
|
||||
}
|
||||
this.wheelFR = wheelFR;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(wheelRL)) {
|
||||
wheelRL = null;
|
||||
}
|
||||
this.wheelRL = wheelRL;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(wheelRR)) {
|
||||
wheelRR = null;
|
||||
}
|
||||
this.wheelRR = wheelRR;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(heightOffset)) {
|
||||
heightOffset = 0;
|
||||
}
|
||||
this.heightOffset = heightOffset;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(distance)) {
|
||||
distance = 0;
|
||||
}
|
||||
this.distance = distance;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(distanceGrain)) {
|
||||
distanceGrain = 0.1;
|
||||
}
|
||||
this.distanceGrain = distanceGrain;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(rotationFactor)) {
|
||||
rotationFactor = 0.1;
|
||||
}
|
||||
this.rotationFactor = rotationFactor;
|
||||
|
||||
};
|
||||
|
||||
R3.D3.API.Input.Drive.prototype = Object.create(R3.Component.prototype);
|
||||
R3.D3.API.Input.Drive.prototype.constructor = R3.D3.API.Input.Drive;
|
||||
|
||||
/**
|
||||
* Object to R3.D3.API.Input.Drive
|
||||
* @param objectComponent
|
||||
* @returns {R3.D3.API.Input.Drive}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Input.Drive.FromObject = function(objectComponent) {
|
||||
return new R3.D3.API.Input.Drive(
|
||||
objectComponent.id,
|
||||
objectComponent.name,
|
||||
objectComponent.domElementId,
|
||||
objectComponent.pathFollowingComponent,
|
||||
objectComponent.parentEntity,
|
||||
objectComponent.wheelFL,
|
||||
objectComponent.wheelFR,
|
||||
objectComponent.wheelRL,
|
||||
objectComponent.wheelRR,
|
||||
objectComponent.heightOffset,
|
||||
objectComponent.distance,
|
||||
objectComponent.distanceGrain,
|
||||
objectComponent.rotationFactor
|
||||
);
|
||||
};
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param domElementId
|
||||
* @param camera R3.D3.Camera
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Input.Editor = function (
|
||||
id,
|
||||
name,
|
||||
domElementId,
|
||||
camera,
|
||||
parentEntity
|
||||
) {
|
||||
R3.Component.call(
|
||||
this,
|
||||
R3.Component.COMPONENT_EDITOR_INPUT,
|
||||
{
|
||||
'camera' : R3.D3.Camera
|
||||
},
|
||||
null,
|
||||
parentEntity
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = this.constructor.name;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(domElementId)) {
|
||||
domElementId = "divCanvas";
|
||||
}
|
||||
this.domElementId = domElementId;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(camera)) {
|
||||
camera = null;
|
||||
}
|
||||
this.camera = camera;
|
||||
|
||||
};
|
||||
|
||||
R3.D3.API.Input.Editor.prototype = Object.create(R3.Component.prototype);
|
||||
R3.D3.API.Input.Editor.prototype.constructor = R3.D3.API.Input.Editor;
|
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param domElement
|
||||
* @param camera
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Input.Editor = function (
|
||||
id,
|
||||
name,
|
||||
domElement,
|
||||
camera,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = 'Input Editor (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(domElement)) {
|
||||
domElement = null;
|
||||
}
|
||||
this.domElement = domElement;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(camera)) {
|
||||
camera = null;
|
||||
}
|
||||
this.camera = camera;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(parentEntity)) {
|
||||
parentEntity = null;
|
||||
}
|
||||
this.parentEntity = parentEntity;
|
||||
|
||||
};
|
||||
|
||||
R3.D3.API.Input.Editor.prototype = Object.create(R3.Component.prototype);
|
||||
R3.D3.API.Input.Editor.prototype.constructor = R3.D3.API.Input.Editor;
|
||||
|
||||
/**
|
||||
* Object to R3.D3.API.Input.Editor
|
||||
* @param objectComponent
|
||||
* @returns {R3.D3.API.Input.Editor}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Input.Editor.FromObject = function(objectComponent) {
|
||||
return new R3.D3.API.Input.Editor(
|
||||
objectComponent.id,
|
||||
objectComponent.name,
|
||||
objectComponent.domElement,
|
||||
objectComponent.camera,
|
||||
objectComponent.parentEntity
|
||||
);
|
||||
};
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param domElementId
|
||||
* @param camera R3.D3.Camera
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.Input.Fly = function (
|
||||
id,
|
||||
name,
|
||||
domElementId,
|
||||
camera
|
||||
) {
|
||||
R3.Component.call(
|
||||
this,
|
||||
R3.Component.COMPONENT_FLY_INPUT,
|
||||
{
|
||||
'camera' : R3.D3.Camera
|
||||
}
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = this.constructor.name;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(domElementId)) {
|
||||
domElementId = "divCanvas";
|
||||
}
|
||||
this.domElementId = domElementId;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(camera)) {
|
||||
camera = null;
|
||||
}
|
||||
this.camera = camera;
|
||||
|
||||
};
|
||||
|
||||
R3.D3.API.Input.Fly.prototype = Object.create(R3.Component.prototype);
|
||||
R3.D3.API.Input.Fly.prototype.constructor = R3.D3.API.Input.Fly;
|
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* Looks from currentPosition to targetPosition (default up is 0,1,0)
|
||||
* @param id
|
||||
* @param name
|
||||
* @param currentComponent R3.Component
|
||||
* @param targetComponent R3.Component
|
||||
* @param targetPositionOffset R3.API.Vector3
|
||||
* @param rotationSpeed Number
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.LookAt = function (
|
||||
id,
|
||||
name,
|
||||
currentComponent,
|
||||
targetComponent,
|
||||
targetPositionOffset,
|
||||
rotationSpeed,
|
||||
parentEntity
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = this.constructor.name;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if(R3.Utils.UndefinedOrNull(currentComponent)) {
|
||||
currentComponent = null;
|
||||
}
|
||||
this.currentComponent = currentComponent;
|
||||
|
||||
if(R3.Utils.UndefinedOrNull(targetComponent)) {
|
||||
targetComponent = null;
|
||||
}
|
||||
this.targetComponent = targetComponent;
|
||||
|
||||
if(R3.Utils.UndefinedOrNull(targetPositionOffset)) {
|
||||
targetPositionOffset = new R3.API.Vector3(0, 0, 0);
|
||||
}
|
||||
this.targetPositionOffset = targetPositionOffset;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(rotationSpeed)) {
|
||||
rotationSpeed = 22.0;
|
||||
}
|
||||
this.rotationSpeed = rotationSpeed;
|
||||
|
||||
this.lookAtMatrix = new R3.API.Matrix4();
|
||||
|
||||
this.up = new R3.API.Vector3(0, 1, 0);
|
||||
|
||||
this.currentRotation = new R3.API.Quaternion();
|
||||
|
||||
this.targetPosition = new R3.API.Vector3();
|
||||
|
||||
if(R3.Utils.UndefinedOrNull(parentEntity)) {
|
||||
parentEntity = null;
|
||||
}
|
||||
this.parentEntity = parentEntity;
|
||||
};
|
||||
|
||||
R3.D3.API.LookAt.prototype = Object.create(R3.Component.prototype);
|
||||
R3.D3.API.LookAt.prototype.constructor = R3.D3.API.LookAt;
|
||||
|
||||
/**
|
||||
* Object to R3.D3.API.LookAt
|
||||
* @param objectComponent
|
||||
* @returns {R3.D3.API.LookAt}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.LookAt.FromObject = function(objectComponent) {
|
||||
return new R3.D3.API.LookAt(
|
||||
objectComponent.id,
|
||||
objectComponent.name,
|
||||
objectComponent.currentComponent,
|
||||
objectComponent.targetComponent,
|
||||
R3.API.Vector3.FromObject(objectComponent.targetPositionOffset),
|
||||
objectComponent.rotationSpeed,
|
||||
objectComponent.parentEntity
|
||||
);
|
||||
};
|
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* R3.D3.API.Mesh.Box
|
||||
* @constructor
|
||||
* @param apiMesh
|
||||
* @param width
|
||||
* @param height
|
||||
* @param depth
|
||||
*/
|
||||
R3.D3.API.Mesh.Box = function(
|
||||
apiMesh,
|
||||
width,
|
||||
height,
|
||||
depth
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh)) {
|
||||
apiMesh = {
|
||||
meshType : R3.D3.API.Mesh.MESH_TYPE_BOX
|
||||
};
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh.meshType)) {
|
||||
apiMesh.meshType = R3.D3.API.Mesh.MESH_TYPE_BOX;
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(width)) {
|
||||
width = 1;
|
||||
}
|
||||
this.width = width;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(height)) {
|
||||
height = 1;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(depth)) {
|
||||
depth = 1;
|
||||
}
|
||||
this.depth = depth;
|
||||
|
||||
R3.D3.API.Mesh.call(
|
||||
this,
|
||||
apiMesh.id,
|
||||
apiMesh.name,
|
||||
apiMesh.meshType,
|
||||
apiMesh.excludeFromEnvironment,
|
||||
apiMesh.vertices,
|
||||
apiMesh.faces,
|
||||
apiMesh.materials,
|
||||
apiMesh.parentMesh,
|
||||
apiMesh.parentScene,
|
||||
apiMesh.skeleton,
|
||||
apiMesh.skinIndices,
|
||||
apiMesh.skinWeights,
|
||||
apiMesh.position,
|
||||
apiMesh.quaternion,
|
||||
apiMesh.rotation,
|
||||
apiMesh.scale,
|
||||
apiMesh.up,
|
||||
apiMesh.modelMatrix,
|
||||
apiMesh.renderOrder,
|
||||
apiMesh.isBufferMesh,
|
||||
apiMesh.useQuaternion,
|
||||
apiMesh.visible,
|
||||
apiMesh.castShadow,
|
||||
apiMesh.receiveShadow,
|
||||
apiMesh.parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.API.Mesh.Box.prototype = Object.create(R3.D3.API.Mesh.prototype);
|
||||
R3.D3.API.Mesh.Box.prototype.constructor = R3.D3.API.Mesh.Box;
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* R3.D3.API.Mesh.Curve
|
||||
* @constructor
|
||||
* @param apiMesh
|
||||
* @param pointSize
|
||||
*/
|
||||
R3.D3.API.Mesh.Curve = function(
|
||||
apiMesh,
|
||||
pointSize
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh)) {
|
||||
apiMesh = {
|
||||
meshType : R3.D3.API.Mesh.MESH_TYPE_CURVE
|
||||
};
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh.meshType)) {
|
||||
apiMesh.meshType = R3.D3.API.Mesh.MESH_TYPE_CURVE;
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(pointSize)) {
|
||||
pointSize = 1;
|
||||
}
|
||||
this.pointSize = pointSize;
|
||||
|
||||
R3.D3.API.Mesh.call(
|
||||
this,
|
||||
apiMesh.id,
|
||||
apiMesh.name,
|
||||
apiMesh.meshType,
|
||||
apiMesh.excludeFromEnvironment,
|
||||
apiMesh.vertices,
|
||||
apiMesh.faces,
|
||||
apiMesh.materials,
|
||||
apiMesh.parentMesh,
|
||||
apiMesh.parentScene,
|
||||
apiMesh.skeleton,
|
||||
apiMesh.skinIndices,
|
||||
apiMesh.skinWeights,
|
||||
apiMesh.position,
|
||||
apiMesh.quaternion,
|
||||
apiMesh.rotation,
|
||||
apiMesh.scale,
|
||||
apiMesh.up,
|
||||
apiMesh.modelMatrix,
|
||||
apiMesh.renderOrder,
|
||||
apiMesh.isBufferMesh,
|
||||
apiMesh.useQuaternion,
|
||||
apiMesh.visible,
|
||||
apiMesh.castShadow,
|
||||
apiMesh.receiveShadow,
|
||||
apiMesh.parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.API.Mesh.Curve.prototype = Object.create(R3.D3.API.Mesh.prototype);
|
||||
R3.D3.API.Mesh.Curve.prototype.constructor = R3.D3.API.Mesh.Curve;
|
|
@ -0,0 +1,106 @@
|
|||
/**
|
||||
* R3.D3.API.Mesh.Cylinder
|
||||
* @constructor
|
||||
* @param apiMesh
|
||||
* @param radiusTop
|
||||
* @param radiusBottom
|
||||
* @param height
|
||||
* @param radiusSegments
|
||||
* @param heightSegments
|
||||
* @param openEnded
|
||||
* @param thetaStart
|
||||
* @param thetaLength
|
||||
*/
|
||||
R3.D3.API.Mesh.Cylinder = function(
|
||||
apiMesh,
|
||||
radiusTop,
|
||||
radiusBottom,
|
||||
height,
|
||||
radiusSegments,
|
||||
heightSegments,
|
||||
openEnded,
|
||||
thetaStart,
|
||||
thetaLength
|
||||
) {
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh)) {
|
||||
apiMesh = {
|
||||
meshType : R3.D3.API.Mesh.MESH_TYPE_CYLINDER
|
||||
};
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh.meshType)) {
|
||||
apiMesh.meshType = R3.D3.API.Mesh.MESH_TYPE_CYLINDER;
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(radiusTop)) {
|
||||
radiusTop = 1;
|
||||
}
|
||||
this.radiusTop = radiusTop;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(radiusBottom)) {
|
||||
radiusBottom = 1;
|
||||
}
|
||||
this.radiusBottom = radiusBottom;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(height)) {
|
||||
height = 5;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(radiusSegments)) {
|
||||
radiusSegments = 10;
|
||||
}
|
||||
this.radiusSegments = radiusSegments;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(heightSegments)) {
|
||||
heightSegments = 10;
|
||||
}
|
||||
this.heightSegments = heightSegments;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(openEnded)) {
|
||||
openEnded = false;
|
||||
}
|
||||
this.openEnded = openEnded;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(thetaStart)) {
|
||||
thetaStart = 0;
|
||||
}
|
||||
this.thetaStart = thetaStart;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(thetaLength)) {
|
||||
thetaLength = Math.PI * 2;
|
||||
}
|
||||
this.thetaLength = thetaLength;
|
||||
|
||||
R3.D3.API.Mesh.call(
|
||||
this,
|
||||
apiMesh.id,
|
||||
apiMesh.name,
|
||||
apiMesh.meshType,
|
||||
apiMesh.excludeFromEnvironment,
|
||||
apiMesh.vertices,
|
||||
apiMesh.faces,
|
||||
apiMesh.materials,
|
||||
apiMesh.parentMesh,
|
||||
apiMesh.parentScene,
|
||||
apiMesh.skeleton,
|
||||
apiMesh.skinIndices,
|
||||
apiMesh.skinWeights,
|
||||
apiMesh.position,
|
||||
apiMesh.quaternion,
|
||||
apiMesh.rotation,
|
||||
apiMesh.scale,
|
||||
apiMesh.up,
|
||||
apiMesh.modelMatrix,
|
||||
apiMesh.renderOrder,
|
||||
apiMesh.isBufferMesh,
|
||||
apiMesh.useQuaternion,
|
||||
apiMesh.visible,
|
||||
apiMesh.castShadow,
|
||||
apiMesh.receiveShadow,
|
||||
apiMesh.parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.API.Mesh.Cylinder.prototype = Object.create(R3.D3.API.Mesh.prototype);
|
||||
R3.D3.API.Mesh.Cylinder.prototype.constructor = R3.D3.API.Mesh.Cylinder;
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* R3.D3.API.Mesh.Line
|
||||
* @constructor
|
||||
* @param apiMesh
|
||||
* @param lineWidth
|
||||
*/
|
||||
R3.D3.API.Mesh.Line = function(
|
||||
apiMesh,
|
||||
lineWidth
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh)) {
|
||||
apiMesh = {
|
||||
meshType : R3.D3.API.Mesh.MESH_TYPE_LINE
|
||||
};
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh.meshType)) {
|
||||
apiMesh.meshType = R3.D3.API.Mesh.MESH_TYPE_LINE;
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(lineWidth)) {
|
||||
lineWidth = 1;
|
||||
}
|
||||
this.lineWidth = lineWidth;
|
||||
|
||||
R3.D3.API.Mesh.call(
|
||||
this,
|
||||
apiMesh.id,
|
||||
apiMesh.name,
|
||||
apiMesh.meshType,
|
||||
apiMesh.excludeFromEnvironment,
|
||||
apiMesh.vertices,
|
||||
apiMesh.faces,
|
||||
apiMesh.materials,
|
||||
apiMesh.parentMesh,
|
||||
apiMesh.parentScene,
|
||||
apiMesh.skeleton,
|
||||
apiMesh.skinIndices,
|
||||
apiMesh.skinWeights,
|
||||
apiMesh.position,
|
||||
apiMesh.quaternion,
|
||||
apiMesh.rotation,
|
||||
apiMesh.scale,
|
||||
apiMesh.up,
|
||||
apiMesh.modelMatrix,
|
||||
apiMesh.renderOrder,
|
||||
apiMesh.isBufferMesh,
|
||||
apiMesh.useQuaternion,
|
||||
apiMesh.visible,
|
||||
apiMesh.castShadow,
|
||||
apiMesh.receiveShadow,
|
||||
apiMesh.parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.API.Mesh.Line.prototype = Object.create(R3.D3.API.Mesh.prototype);
|
||||
R3.D3.API.Mesh.Line.prototype.constructor = R3.D3.API.Mesh.Line;
|
|
@ -0,0 +1,128 @@
|
|||
/**
|
||||
* R3.D3.API.Mesh.Plane
|
||||
* @constructor
|
||||
* @param apiMesh
|
||||
* @param width
|
||||
* @param height
|
||||
* @param widthSegments
|
||||
* @param heightSegments
|
||||
* @param heightMapScale
|
||||
* @param isHeightMap
|
||||
* @param isDotMap
|
||||
* @param dotMapScale
|
||||
* @param dotMapOffset
|
||||
* @param dotMapWeight
|
||||
* @param dotObject
|
||||
*/
|
||||
R3.D3.API.Mesh.Plane = function(
|
||||
apiMesh,
|
||||
width,
|
||||
height,
|
||||
widthSegments,
|
||||
heightSegments,
|
||||
heightMapScale,
|
||||
isHeightMap,
|
||||
isDotMap,
|
||||
dotMapScale,
|
||||
dotMapOffset,
|
||||
dotMapWeight,
|
||||
dotObject
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh)) {
|
||||
apiMesh = {
|
||||
meshType : R3.D3.API.Mesh.MESH_TYPE_PLANE
|
||||
};
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh.meshType)) {
|
||||
apiMesh.meshType = R3.D3.API.Mesh.MESH_TYPE_PLANE;
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(width)) {
|
||||
width = 1;
|
||||
}
|
||||
this.width = width;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(height)) {
|
||||
height = 1;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(widthSegments)) {
|
||||
widthSegments = 5;
|
||||
}
|
||||
this.widthSegments = widthSegments;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(heightSegments)) {
|
||||
heightSegments = 5;
|
||||
}
|
||||
this.heightSegments = heightSegments;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(heightMapScale)) {
|
||||
heightMapScale = 1;
|
||||
}
|
||||
this.heightMapScale = heightMapScale;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(isHeightMap)) {
|
||||
isHeightMap = false;
|
||||
}
|
||||
this.isHeightMap = isHeightMap;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(isDotMap)) {
|
||||
isDotMap = false;
|
||||
}
|
||||
this.isDotMap = isDotMap;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(dotMapScale)) {
|
||||
dotMapScale = new R3.API.Vector3(0.01, 0.01, 0.01);
|
||||
}
|
||||
this.dotMapScale = dotMapScale;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(dotMapOffset)) {
|
||||
dotMapOffset = new R3.API.Vector3(1, -1, 5);
|
||||
}
|
||||
this.dotMapOffset = dotMapOffset;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(dotMapWeight)) {
|
||||
dotMapWeight = new R3.API.Vector3(1, 1, 1);
|
||||
}
|
||||
this.dotMapWeight = dotMapWeight;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(dotObject)) {
|
||||
dotObject = null;
|
||||
}
|
||||
this.dotObject = dotObject;
|
||||
|
||||
R3.D3.API.Mesh.call(
|
||||
this,
|
||||
apiMesh.id,
|
||||
apiMesh.name,
|
||||
apiMesh.meshType,
|
||||
apiMesh.excludeFromEnvironment,
|
||||
apiMesh.vertices,
|
||||
apiMesh.faces,
|
||||
apiMesh.materials,
|
||||
apiMesh.parentMesh,
|
||||
apiMesh.parentScene,
|
||||
apiMesh.skeleton,
|
||||
apiMesh.skinIndices,
|
||||
apiMesh.skinWeights,
|
||||
apiMesh.position,
|
||||
apiMesh.quaternion,
|
||||
apiMesh.rotation,
|
||||
apiMesh.scale,
|
||||
apiMesh.up,
|
||||
apiMesh.modelMatrix,
|
||||
apiMesh.renderOrder,
|
||||
apiMesh.isBufferMesh,
|
||||
apiMesh.useQuaternion,
|
||||
apiMesh.visible,
|
||||
apiMesh.castShadow,
|
||||
apiMesh.receiveShadow,
|
||||
apiMesh.parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.API.Mesh.Plane.prototype = Object.create(R3.D3.API.Mesh.prototype);
|
||||
R3.D3.API.Mesh.Plane.prototype.constructor = R3.D3.API.Mesh.Plane;
|
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* R3.D3.API.Mesh.Sphere
|
||||
* @constructor
|
||||
* @param apiMesh
|
||||
* @param radius
|
||||
* @param widthSegments
|
||||
* @param heightSegments
|
||||
*/
|
||||
R3.D3.API.Mesh.Sphere = function(
|
||||
apiMesh,
|
||||
radius,
|
||||
widthSegments,
|
||||
heightSegments
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh)) {
|
||||
apiMesh = {
|
||||
meshType : R3.D3.API.Mesh.MESH_TYPE_SPHERE
|
||||
};
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh.meshType)) {
|
||||
apiMesh.meshType = R3.D3.API.Mesh.MESH_TYPE_SPHERE;
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(radius)) {
|
||||
radius = 1;
|
||||
}
|
||||
this.radius = radius;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(widthSegments)) {
|
||||
widthSegments = 5;
|
||||
}
|
||||
this.widthSegments = widthSegments;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(heightSegments)) {
|
||||
heightSegments = 5;
|
||||
}
|
||||
this.heightSegments = heightSegments;
|
||||
|
||||
R3.D3.API.Mesh.call(
|
||||
this,
|
||||
apiMesh.id,
|
||||
apiMesh.name,
|
||||
apiMesh.meshType,
|
||||
apiMesh.excludeFromEnvironment,
|
||||
apiMesh.vertices,
|
||||
apiMesh.faces,
|
||||
apiMesh.materials,
|
||||
apiMesh.parentMesh,
|
||||
apiMesh.parentScene,
|
||||
apiMesh.skeleton,
|
||||
apiMesh.skinIndices,
|
||||
apiMesh.skinWeights,
|
||||
apiMesh.position,
|
||||
apiMesh.quaternion,
|
||||
apiMesh.rotation,
|
||||
apiMesh.scale,
|
||||
apiMesh.up,
|
||||
apiMesh.modelMatrix,
|
||||
apiMesh.renderOrder,
|
||||
apiMesh.isBufferMesh,
|
||||
apiMesh.useQuaternion,
|
||||
apiMesh.visible,
|
||||
apiMesh.castShadow,
|
||||
apiMesh.receiveShadow,
|
||||
apiMesh.parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.API.Mesh.Sphere.prototype = Object.create(R3.D3.API.Mesh.prototype);
|
||||
R3.D3.API.Mesh.Sphere.prototype.constructor = R3.D3.API.Mesh.Sphere;
|
|
@ -0,0 +1,114 @@
|
|||
/**
|
||||
* R3.D3.API.Mesh.Text
|
||||
* @constructor
|
||||
* @param apiMesh
|
||||
* @param text
|
||||
* @param font
|
||||
* @param size
|
||||
* @param height
|
||||
* @param curveSegments
|
||||
* @param bevelEnabled
|
||||
* @param bevelThickness
|
||||
* @param bevelSize
|
||||
* @param bevelSegments
|
||||
*/
|
||||
R3.D3.API.Mesh.Text = function(
|
||||
apiMesh,
|
||||
text,
|
||||
font,
|
||||
size,
|
||||
height,
|
||||
curveSegments,
|
||||
bevelEnabled,
|
||||
bevelThickness,
|
||||
bevelSize,
|
||||
bevelSegments
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh)) {
|
||||
apiMesh = {
|
||||
meshType : R3.D3.API.Mesh.MESH_TYPE_TEXT
|
||||
};
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMesh.meshType)) {
|
||||
apiMesh.meshType = R3.D3.API.Mesh.MESH_TYPE_TEXT;
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(text)) {
|
||||
text = '-=<yb4f310';
|
||||
}
|
||||
this.text = text;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(font)) {
|
||||
font = new R3.D3.API.Font()
|
||||
}
|
||||
this.font = font;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(size)) {
|
||||
size = 100;
|
||||
}
|
||||
this.size = size;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(height)) {
|
||||
height = 50;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(curveSegments)) {
|
||||
curveSegments = 12;
|
||||
}
|
||||
this.curveSegments = curveSegments;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(bevelEnabled)) {
|
||||
bevelEnabled = false;
|
||||
}
|
||||
this.bevelEnabled = bevelEnabled;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(bevelThickness)) {
|
||||
bevelThickness = 10;
|
||||
}
|
||||
this.bevelThickness = bevelThickness;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(bevelSize)) {
|
||||
bevelSize = 8;
|
||||
}
|
||||
this.bevelSize = bevelSize;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(bevelSegments)) {
|
||||
bevelSegments = 3;
|
||||
}
|
||||
this.bevelSegments = bevelSegments;
|
||||
|
||||
R3.D3.API.Mesh.call(
|
||||
this,
|
||||
apiMesh.id,
|
||||
apiMesh.name,
|
||||
apiMesh.meshType,
|
||||
apiMesh.excludeFromEnvironment,
|
||||
apiMesh.vertices,
|
||||
apiMesh.faces,
|
||||
apiMesh.materials,
|
||||
apiMesh.parentMesh,
|
||||
apiMesh.parentScene,
|
||||
apiMesh.skeleton,
|
||||
apiMesh.skinIndices,
|
||||
apiMesh.skinWeights,
|
||||
apiMesh.position,
|
||||
apiMesh.quaternion,
|
||||
apiMesh.rotation,
|
||||
apiMesh.scale,
|
||||
apiMesh.up,
|
||||
apiMesh.modelMatrix,
|
||||
apiMesh.renderOrder,
|
||||
apiMesh.isBufferMesh,
|
||||
apiMesh.useQuaternion,
|
||||
apiMesh.visible,
|
||||
apiMesh.castShadow,
|
||||
apiMesh.receiveShadow,
|
||||
apiMesh.parentEntity
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.API.Mesh.Text.prototype = Object.create(R3.D3.API.Mesh.prototype);
|
||||
R3.D3.API.Mesh.Text.prototype.constructor = R3.D3.API.Mesh.Text;
|
|
@ -0,0 +1,203 @@
|
|||
/**
|
||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param spline R3.D3.API.Spline
|
||||
* @param mesh R3.D3.API.Mesh
|
||||
* @param raytraceMesh R3.D3.API.Mesh
|
||||
* @param accelleration Number
|
||||
* @param maxSpeed Number
|
||||
* @param baseOffset R3.API.Vector
|
||||
* @param maxOffset R3.API.Vector
|
||||
* @param steeringSpeed Number
|
||||
* @param targetOffset R3.API.Vector3
|
||||
* @param currentOffset R3.API.Vector3
|
||||
* @param currentPathValue Number
|
||||
* @param currentSpeed Number
|
||||
* @param direction Number
|
||||
* @param raycaster R3.D3.Raycaster
|
||||
* @param currentPosition R3.API.Vector3
|
||||
* @param futurePosition R3.API.Vector3
|
||||
* @param up R3.API.Vector3
|
||||
* @param rotationMatrix R3.API.Matrix4
|
||||
* @param rotationVector R3.API.Quaternion
|
||||
* @param parentEntity
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.PathFollowing = function (
|
||||
id,
|
||||
name,
|
||||
spline,
|
||||
mesh,
|
||||
raytraceMesh,
|
||||
accelleration,
|
||||
maxSpeed,
|
||||
baseOffset,
|
||||
maxOffset,
|
||||
steeringSpeed,
|
||||
targetOffset,
|
||||
currentOffset,
|
||||
currentPathValue,
|
||||
currentSpeed,
|
||||
direction,
|
||||
raycaster,
|
||||
currentPosition,
|
||||
futurePosition,
|
||||
up,
|
||||
rotationMatrix,
|
||||
rotationVector,
|
||||
parentEntity
|
||||
) {
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = this.constructor.name;
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(spline)) {
|
||||
spline = null;
|
||||
}
|
||||
this.spline = spline;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(mesh)) {
|
||||
mesh = null;
|
||||
}
|
||||
this.mesh = mesh;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(raytraceMesh)) {
|
||||
raytraceMesh = null;
|
||||
}
|
||||
this.raytraceMesh = raytraceMesh;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(maxSpeed)) {
|
||||
maxSpeed = 0.03;
|
||||
}
|
||||
this.maxSpeed = maxSpeed;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(accelleration)) {
|
||||
accelleration = 0.1;
|
||||
}
|
||||
this.accelleration = accelleration;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(baseOffset)) {
|
||||
baseOffset = new R3.API.Vector3();
|
||||
}
|
||||
this.baseOffset = baseOffset;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(maxOffset)) {
|
||||
maxOffset = new R3.API.Vector3();
|
||||
}
|
||||
this.maxOffset = maxOffset;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(steeringSpeed)) {
|
||||
steeringSpeed = 1.0;
|
||||
}
|
||||
this.steeringSpeed = steeringSpeed;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(targetOffset)) {
|
||||
targetOffset = new R3.API.Vector3();
|
||||
}
|
||||
this.targetOffset = targetOffset;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(currentOffset)) {
|
||||
currentOffset = new R3.API.Vector3();
|
||||
}
|
||||
this.currentOffset = currentOffset;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(currentPathValue)) {
|
||||
currentPathValue = 0;
|
||||
}
|
||||
this.currentPathValue = currentPathValue;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(currentSpeed)) {
|
||||
currentSpeed = 0;
|
||||
}
|
||||
this.currentSpeed = currentSpeed;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(direction)) {
|
||||
direction = 1;
|
||||
}
|
||||
this.direction = direction;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(raycaster)) {
|
||||
raycaster = new R3.D3.API.Raycaster();
|
||||
}
|
||||
this.raycaster = raycaster;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(currentPosition)) {
|
||||
currentPosition = new R3.API.Vector3();
|
||||
}
|
||||
this.currentPosition = currentPosition;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(futurePosition)) {
|
||||
futurePosition = new R3.API.Vector3();
|
||||
}
|
||||
this.futurePosition = futurePosition;
|
||||
|
||||
if(R3.Utils.UndefinedOrNull(up)) {
|
||||
up = new R3.API.Vector3(0, 1, 0);
|
||||
}
|
||||
this.up = up;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(rotationMatrix)) {
|
||||
rotationMatrix = new R3.API.Matrix4();
|
||||
}
|
||||
this.rotationMatrix = rotationMatrix;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(rotationVector)) {
|
||||
rotationVector = new R3.API.Quaternion();
|
||||
}
|
||||
this.rotationVector = rotationVector;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(parentEntity)) {
|
||||
parentEntity = null;
|
||||
}
|
||||
this.parentEntity = parentEntity;
|
||||
|
||||
};
|
||||
|
||||
R3.D3.API.PathFollowing.prototype = Object.create(R3.Component.prototype);
|
||||
R3.D3.API.PathFollowing.prototype.constructor = R3.D3.API.PathFollowing;
|
||||
|
||||
/**
|
||||
* Returns an API path following component from an Object path following component
|
||||
* @param objectComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.PathFollowing.FromObject = function(objectComponent) {
|
||||
|
||||
var apiRaycaster = null;
|
||||
|
||||
if (objectComponent.raycaster) {
|
||||
apiRaycaster = R3.D3.API.Raycaster.FromObject(objectComponent.raycaster);
|
||||
}
|
||||
|
||||
return new R3.D3.API.PathFollowing(
|
||||
objectComponent.id,
|
||||
objectComponent.name,
|
||||
objectComponent.spline,
|
||||
objectComponent.mesh,
|
||||
objectComponent.raytraceMesh,
|
||||
objectComponent.accelleration,
|
||||
objectComponent.maxSpeed,
|
||||
R3.API.Vector3.FromObject(objectComponent.baseOffset),
|
||||
R3.API.Vector3.FromObject(objectComponent.maxOffset),
|
||||
objectComponent.steeringSpeed,
|
||||
R3.API.Vector3.FromObject(objectComponent.targetOffset),
|
||||
R3.API.Vector3.FromObject(objectComponent.currentOffset),
|
||||
objectComponent.currentPathValue,
|
||||
objectComponent.currentSpeed,
|
||||
objectComponent.direction,
|
||||
apiRaycaster,
|
||||
R3.API.Vector3.FromObject(objectComponent.currentPosition),
|
||||
R3.API.Vector3.FromObject(objectComponent.futurePosition),
|
||||
R3.API.Vector3.FromObject(objectComponent.up),
|
||||
R3.API.Matrix4.FromObject(objectComponent.rotationMatrix),
|
||||
R3.API.Quaternion.FromObject(objectComponent.rotationVector),
|
||||
objectComponent.parentEntity
|
||||
);
|
||||
};
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||
* @param id String
|
||||
* @param name String
|
||||
* @param object
|
||||
* @param helper
|
||||
* @param lastUpdate
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.SelectedObject = function (
|
||||
object,
|
||||
helper,
|
||||
lastUpdate
|
||||
) {
|
||||
if (R3.Utils.UndefinedOrNull(object)) {
|
||||
console.warn('Cannot select no object');
|
||||
throw new Error('Cannot select no object');
|
||||
}
|
||||
this.object = object;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(helper)) {
|
||||
helper = null;
|
||||
}
|
||||
this.helper = helper;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(lastUpdate)) {
|
||||
lastUpdate = Date.now();
|
||||
}
|
||||
this.lastUpdate = lastUpdate;
|
||||
};
|
||||
|
||||
/**
|
||||
* Object to R3.D3.API.SelectedObject
|
||||
* @param objectComponent
|
||||
* @returns {R3.D3.API.SelectedObject}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.API.SelectedObject.FromObjectSelectedObject = function(objectComponent) {
|
||||
return new R3.D3.API.SelectedObject(
|
||||
objectComponent.id,
|
||||
objectComponent.name,
|
||||
objectComponent.object,
|
||||
objectComponent.helper,
|
||||
objectComponent.lastUpdate
|
||||
);
|
||||
};
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
* R3.D3.Composer.RenderTarget
|
||||
* @param apiComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Composer.RenderTarget = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
__RUNTIME_COMPONENT__;
|
||||
|
||||
R3.D3.API.Composer.RenderTarget.call(
|
||||
this,
|
||||
apiComponent,
|
||||
apiComponent.renderTarget
|
||||
);
|
||||
|
||||
if (this.renderTarget instanceof R3.D3.API.RenderTarget) {
|
||||
this.renderTarget = R3.Component.ConstructFromObject(this.renderTarget);
|
||||
}
|
||||
|
||||
var linkedComponents = {
|
||||
renderTarget : R3.D3.RenderTarget
|
||||
};
|
||||
|
||||
R3.D3.Composer.call(
|
||||
this,
|
||||
linkedComponents
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.Composer.RenderTarget.prototype = Object.create(R3.D3.Composer.prototype);
|
||||
R3.D3.Composer.RenderTarget.prototype.constructor = R3.D3.Composer.RenderTarget;
|
||||
|
||||
/**
|
||||
* Creates a Composer instance
|
||||
* @returns {*}
|
||||
*/
|
||||
R3.D3.Composer.RenderTarget.prototype.createInstance = function() {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(this.renderTarget)) {
|
||||
throw new Error('Need at least a renderTarget to create this composer object instance')
|
||||
}
|
||||
|
||||
this.width = this.renderTarget.width;
|
||||
this.height = this.renderTarget.height;
|
||||
|
||||
/**
|
||||
* Right - now we should have the right size of the composer - we can continue
|
||||
*/
|
||||
this.instance = this.graphics.Composer(
|
||||
null,
|
||||
this.renderTarget,
|
||||
this.passes,
|
||||
{
|
||||
width : this.width,
|
||||
height : this.height
|
||||
}
|
||||
);
|
||||
|
||||
__CREATE_INSTANCE__;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates Composer instance
|
||||
*/
|
||||
R3.D3.Composer.RenderTarget.prototype.updateInstance = function(property) {
|
||||
|
||||
if (property === 'rendererTarget') {
|
||||
|
||||
console.warn('TODO: renderTarget update');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
R3.D3.Composer.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if this composer is ready
|
||||
* @returns {boolean}
|
||||
*/
|
||||
R3.D3.Composer.RenderTarget.prototype.ready = function() {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(this.instance)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(this.renderTarget)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return R3.D3.Composer.prototype.ready.call(this);
|
||||
|
||||
};
|
|
@ -0,0 +1,126 @@
|
|||
/**
|
||||
* R3.D3.Composer.Renderer
|
||||
* @param apiComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Composer.Renderer = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
__RUNTIME_COMPONENT__;
|
||||
|
||||
R3.D3.API.Composer.Renderer.call(
|
||||
this,
|
||||
apiComponent,
|
||||
apiComponent.renderer
|
||||
);
|
||||
|
||||
if (this.renderer instanceof R3.API.Renderer.D3) {
|
||||
this.renderer = R3.Component.ConstructFromObject(this.renderer);
|
||||
}
|
||||
|
||||
var linkedComponents = {
|
||||
renderer : R3.Renderer.D3
|
||||
};
|
||||
|
||||
R3.D3.Composer.call(
|
||||
this,
|
||||
linkedComponents
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.Composer.Renderer.prototype = Object.create(R3.D3.Composer.prototype);
|
||||
R3.D3.Composer.Renderer.prototype.constructor = R3.D3.Composer.Renderer;
|
||||
|
||||
/**
|
||||
* Creates a Composer instance
|
||||
* @returns {*}
|
||||
*/
|
||||
R3.D3.Composer.Renderer.prototype.createInstance = function() {
|
||||
|
||||
if (
|
||||
R3.Utils.UndefinedOrNull(this.renderer)
|
||||
) {
|
||||
throw new Error('Need at least a renderer to create a composer renderer object')
|
||||
}
|
||||
|
||||
|
||||
if (
|
||||
this.renderer instanceof R3.Renderer.D3.Target ||
|
||||
this.renderer instanceof R3.Renderer.D3.Canvas.Target
|
||||
) {
|
||||
|
||||
this.width = this.renderer.target.width;
|
||||
this.height = this.renderer.target.height;
|
||||
|
||||
} else if (
|
||||
this.renderer instanceof R3.Renderer.D3.Canvas
|
||||
) {
|
||||
|
||||
/**
|
||||
* This composer belongs to a scene which belongs to a viewport
|
||||
*/
|
||||
var viewport = this.getFirstParent(R3.D3.Viewport);
|
||||
|
||||
/**
|
||||
* The canvas is associated to the renderer - it has the actual size of the canvas and we need the size
|
||||
* of the viewport to determine the actual pixel size of this composer
|
||||
*/
|
||||
var canvas = this.renderer.canvas;
|
||||
|
||||
this.width = canvas.width * viewport.width;
|
||||
this.height = canvas.height * viewport.height;
|
||||
|
||||
|
||||
} else {
|
||||
throw new Error('Unhandled renderer type : ' + this.renderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Right - now we should have the right size of the composer - we can continue
|
||||
*/
|
||||
this.instance = this.graphics.Composer(
|
||||
renderer,
|
||||
null,
|
||||
this.passes,
|
||||
{
|
||||
width : this.width,
|
||||
height : this.height
|
||||
}
|
||||
);
|
||||
|
||||
__CREATE_INSTANCE__;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates Composer instance
|
||||
*/
|
||||
R3.D3.Composer.Renderer.prototype.updateInstance = function(property) {
|
||||
|
||||
if (property === 'renderer') {
|
||||
|
||||
console.warn('todo update composer renderer');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
R3.D3.Composer.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if this composer is ready for rendering
|
||||
* @returns {boolean}
|
||||
*/
|
||||
R3.D3.Composer.Renderer.prototype.ready = function() {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(this.instance)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(this.renderer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return R3.D3.Composer.prototype.ready.call(this);
|
||||
|
||||
};
|
|
@ -0,0 +1,538 @@
|
|||
/**
|
||||
* Creates a Editor object
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param apiEditor R3.D3.API.Editor
|
||||
* @param onSelectionChanged
|
||||
* @param onSelectObject
|
||||
* @param onDeSelectObject
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Editor = function(
|
||||
graphics,
|
||||
apiEditor,
|
||||
onSelectionChanged,
|
||||
onSelectObject,
|
||||
onDeSelectObject
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiEditor)) {
|
||||
apiEditor = {};
|
||||
}
|
||||
|
||||
if (apiEditor instanceof R3.D3.Editor) {
|
||||
return apiEditor;
|
||||
}
|
||||
|
||||
R3.D3.API.Editor.call(
|
||||
this,
|
||||
apiEditor.id,
|
||||
apiEditor.name,
|
||||
apiEditor.baseUrl,
|
||||
apiEditor.path,
|
||||
apiEditor.imageFactory,
|
||||
apiEditor.games,
|
||||
apiEditor.scenes,
|
||||
apiEditor.cameras,
|
||||
apiEditor.composers,
|
||||
apiEditor.viewports,
|
||||
apiEditor.renderers,
|
||||
apiEditor.renderTargets,
|
||||
apiEditor.systems,
|
||||
apiEditor.entityManager,
|
||||
apiEditor.allSelected,
|
||||
apiEditor.selectedObjects,
|
||||
apiEditor.parentEntity
|
||||
);
|
||||
|
||||
if (this.imageFactory instanceof R3.D3.API.ImageFactory) {
|
||||
this.imageFactory = new R3.D3.ImageFactory(
|
||||
this.graphics,
|
||||
this.imageFactory
|
||||
);
|
||||
}
|
||||
|
||||
if (this.games) {
|
||||
this.games = this.games.map(
|
||||
function (apiGame) {
|
||||
if (apiGame instanceof R3.D3.API.Game) {
|
||||
return new R3.D3.Game(
|
||||
this.graphics,
|
||||
apiGame,
|
||||
this.imageFactory
|
||||
)
|
||||
}
|
||||
else {
|
||||
console.warn('game not of type API.Game');
|
||||
throw new Error('game not of type API.Game');
|
||||
}
|
||||
}.bind(this)
|
||||
)
|
||||
}
|
||||
|
||||
this.scenes = this.scenes.map(
|
||||
function (apiScene) {
|
||||
if (apiScene instanceof R3.D3.API.Scene) {
|
||||
return new R3.D3.Scene(
|
||||
this.graphics,
|
||||
apiScene,
|
||||
this.imageFactory,
|
||||
true
|
||||
)
|
||||
} else {
|
||||
console.warn('apiScene not of type API.Scene');
|
||||
throw new Error('apiScene not of type API.Scene');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.cameras = this.cameras.map(
|
||||
function (apiCamera) {
|
||||
if (apiCamera instanceof R3.D3.API.Camera) {
|
||||
return new R3.D3.Camera(
|
||||
this.graphics,
|
||||
apiCamera
|
||||
)
|
||||
} else {
|
||||
console.warn('apiCamera not of type API.Camera');
|
||||
throw new Error('apiCamera not of type API.Camera');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.composers = this.composers.map(
|
||||
function (apiComposer) {
|
||||
if (apiComposer instanceof R3.D3.API.Composer) {
|
||||
return new R3.D3.Composer(
|
||||
this.graphics,
|
||||
apiComposer
|
||||
)
|
||||
} else {
|
||||
console.warn('apiComposer not of type API.Composer');
|
||||
throw new Error('apiComposer not of type API.Composer');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.viewports = this.viewports.map(
|
||||
function (apiViewport) {
|
||||
if (apiViewport instanceof R3.D3.API.Viewport) {
|
||||
return new R3.D3.Viewport(
|
||||
this.graphics,
|
||||
apiViewport
|
||||
)
|
||||
} else {
|
||||
console.warn('apiViewport not of type API.Viewport');
|
||||
throw new Error('apiViewport not of type API.Viewport');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.renderers = this.renderers.map(
|
||||
function (apiRenderer) {
|
||||
if (apiRenderer instanceof R3.D3.API.Renderer) {
|
||||
return new R3.D3.Renderer(
|
||||
this.graphics,
|
||||
apiRenderer
|
||||
)
|
||||
} else {
|
||||
console.warn('apiRenderer not of type API.Renderer');
|
||||
throw new Error('apiRenderer not of type API.Renderer');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.renderTargets = this.renderTargets.map(
|
||||
function (apiRenderTarget) {
|
||||
if (apiRenderTarget instanceof R3.D3.API.RenderTarget) {
|
||||
return new R3.D3.RenderTarget(
|
||||
this.graphics,
|
||||
apiRenderTarget
|
||||
)
|
||||
} else {
|
||||
console.warn('apiRenderTarget not of type API.RenderTarget');
|
||||
throw new Error('apiRenderTarget not of type API.RenderTarget');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.systems = this.systems.map(
|
||||
function (apiSystem) {
|
||||
if (apiSystem instanceof R3.API.System) {
|
||||
return new R3.System(
|
||||
this.graphics,
|
||||
apiSystem
|
||||
)
|
||||
} else {
|
||||
console.warn('apiSystem not of type API.System');
|
||||
throw new Error('apiSystem not of type API.System');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
if (this.entityManager) {
|
||||
if (this.entityManager instanceof R3.API.EntityManager) {
|
||||
this.entityManager = new R3.EntityManager(
|
||||
this.graphics,
|
||||
this.entityManager
|
||||
);
|
||||
} else {
|
||||
console.warn('entityManager not of type API.EntityManager');
|
||||
throw new Error('entityManager not of type API.EntityManager');
|
||||
}
|
||||
}
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(onSelectionChanged)) {
|
||||
onSelectionChanged = null;
|
||||
}
|
||||
this.onSelectionChanged = onSelectionChanged;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(onSelectObject)) {
|
||||
onSelectObject = null;
|
||||
}
|
||||
this.onSelectObject = onSelectObject;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(onDeSelectObject)) {
|
||||
onDeSelectObject = null;
|
||||
}
|
||||
this.onDeSelectObject = onDeSelectObject;
|
||||
|
||||
this.meshMoveMode = false;
|
||||
this.meshMoveXMode = false;
|
||||
this.meshMoveYMode = false;
|
||||
this.meshMoveZMode = false;
|
||||
|
||||
this.buildIdToObject();
|
||||
|
||||
this.linkObjects(this.idToObject);
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
R3.D3.Editor.prototype = Object.create(R3.D3.API.Editor.prototype);
|
||||
R3.D3.Editor.prototype.constructor = R3.D3.Editor;
|
||||
|
||||
/**
|
||||
* Creates a camera instance of 'graphics' type (only THREE for now)
|
||||
* @returns {THREE.Editor}
|
||||
*/
|
||||
R3.D3.Editor.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
}
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
R3.D3.Editor.prototype.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a R3.D3.Editor to a new R3.D3.API.Editor
|
||||
* @returns {R3.D3.API.Editor}
|
||||
*/
|
||||
R3.D3.Editor.prototype.toApiObject = function() {
|
||||
|
||||
var apiImageFactory = null;
|
||||
var apiGames = [];
|
||||
var apiScenes = [];
|
||||
var apiCameras = [];
|
||||
var apiComposers = [];
|
||||
var apiViewports = [];
|
||||
var apiRenderers = [];
|
||||
var apiRenderTargets = [];
|
||||
var apiSystems = [];
|
||||
var apiEntityManager = null;
|
||||
|
||||
if (this.imageFactory instanceof R3.D3.ImageFactory) {
|
||||
apiImageFactory = this.imageFactory.toApiObject();
|
||||
}
|
||||
|
||||
if (this.games) {
|
||||
apiGames = this.games.map(
|
||||
function(game) {
|
||||
if (game instanceof R3.D3.Game) {
|
||||
return game.toApiObject();
|
||||
} else {
|
||||
console.warn('game not an instance of Game');
|
||||
throw new Error('game not an instance of Game');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.scenes) {
|
||||
apiScenes = this.scenes.map(
|
||||
function(scene) {
|
||||
if (scene instanceof R3.D3.Scene) {
|
||||
return scene.toApiObject();
|
||||
} else {
|
||||
console.warn('scene not an instance of Scene');
|
||||
throw new Error('scene not an instance of Scene');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.cameras) {
|
||||
apiCameras = this.cameras.map(
|
||||
function(camera) {
|
||||
if (camera instanceof R3.D3.Camera) {
|
||||
return camera.toApiObject();
|
||||
} else {
|
||||
console.warn('camera not an instance of Camera');
|
||||
throw new Error('camera not an instance of Camera');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.composers) {
|
||||
apiComposers = this.composers.map(
|
||||
function(composer) {
|
||||
if (composer instanceof R3.D3.Composer) {
|
||||
return composer.toApiObject();
|
||||
} else {
|
||||
console.warn('composer not an instance of Composer');
|
||||
throw new Error('composer not an instance of Composer');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.viewports) {
|
||||
apiViewports = this.viewports.map(
|
||||
function(viewport) {
|
||||
if (viewport instanceof R3.D3.Viewport) {
|
||||
return viewport.toApiObject();
|
||||
} else {
|
||||
console.warn('viewport not an instance of Viewport');
|
||||
throw new Error('viewport not an instance of Viewport');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.renderers) {
|
||||
apiRenderers = this.renderers.map(
|
||||
function(renderer) {
|
||||
if (renderer instanceof R3.D3.Renderer) {
|
||||
return renderer.toApiObject();
|
||||
} else {
|
||||
console.warn('renderer not an instance of Renderer');
|
||||
throw new Error('renderer not an instance of Renderer');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.renderTargets) {
|
||||
apiRenderTargets = this.renderTargets.map(
|
||||
function(renderTarget) {
|
||||
if (renderTarget instanceof R3.D3.RenderTarget) {
|
||||
return renderTarget.toApiObject();
|
||||
} else {
|
||||
console.warn('renderTarget not an instance of RenderTarget');
|
||||
throw new Error('renderTarget not an instance of RenderTarget');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.systems) {
|
||||
apiSystems = this.systems.map(
|
||||
function(system) {
|
||||
if (system instanceof R3.System) {
|
||||
return system.toApiObject();
|
||||
} else {
|
||||
console.warn('system not an instance of System');
|
||||
throw new Error('system not an instance of System');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.entityManager) {
|
||||
if (this.entityManager instanceof R3.EntityManager) {
|
||||
apiEntityManager = this.entityManager.toApiObject();
|
||||
} else {
|
||||
console.warn('entityManager not an instance of EntityManager');
|
||||
throw new Error('entityManager not an instance of EntityManager');
|
||||
}
|
||||
}
|
||||
|
||||
return new R3.D3.API.Editor(
|
||||
this.id,
|
||||
this.name,
|
||||
this.baseUrl,
|
||||
this.path,
|
||||
apiImageFactory,
|
||||
apiGames,
|
||||
apiScenes,
|
||||
apiCameras,
|
||||
apiComposers,
|
||||
apiViewports,
|
||||
apiRenderers,
|
||||
apiRenderTargets,
|
||||
apiSystems,
|
||||
apiEntityManager,
|
||||
this.allSelected,
|
||||
this.selectedObjects,
|
||||
R3.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts from an Object Editor to a R3.D3.Editor
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param objectEditor Object
|
||||
* @returns {R3.D3.Editor}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Editor.FromObjectEditor = function(graphics, objectEditor) {
|
||||
|
||||
var apiEditor = R3.D3.API.Editor.FromObjectEditor(objectEditor);
|
||||
|
||||
return new R3.D3.Editor(
|
||||
graphics,
|
||||
apiEditor
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Selects a R3 Object
|
||||
* @param object R3.*
|
||||
*/
|
||||
R3.D3.Editor.prototype.selectObject = function(object) {
|
||||
|
||||
this.selectedObjects.push(
|
||||
new R3.D3.SelectedObject(
|
||||
this.graphics,
|
||||
object
|
||||
)
|
||||
);
|
||||
|
||||
if (this.onSelectObject) {
|
||||
this.onSelectObject();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Selects a R3 Object
|
||||
* @param object R3.*
|
||||
*/
|
||||
R3.D3.Editor.prototype.deSelectObject = function(object) {
|
||||
|
||||
var results = this.selectedObjects.reduce(
|
||||
function(results, selectedObject) {
|
||||
|
||||
if (selectedObject.object.id == object.id) {
|
||||
results.removed = selectedObject;
|
||||
} else {
|
||||
results.rest.push(selectedObject);
|
||||
}
|
||||
|
||||
return results;
|
||||
},
|
||||
{
|
||||
removed : null,
|
||||
rest : []
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
if (this.onDeSelectObject) {
|
||||
this.onDeSelectObject(results);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
R3.D3.Editor.prototype.setSize = function(width, height) {
|
||||
|
||||
this.viewports.map(
|
||||
function(viewport){
|
||||
viewport.width = width;
|
||||
viewport.height = height;
|
||||
viewport.updateInstance();
|
||||
}
|
||||
);
|
||||
|
||||
this.renderers.map(
|
||||
function(renderer) {
|
||||
renderer.setSize(width, height);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a scene to the Editor
|
||||
* @param scene R3.D3.API.Scene
|
||||
*/
|
||||
R3.D3.Editor.prototype.addScene = function(scene) {
|
||||
|
||||
if (!scene instanceof R3.D3.Scene &&
|
||||
!scene instanceof R3.D3.API.Scene) {
|
||||
throw new Error('Unhandled scene type : ' + scene);
|
||||
}
|
||||
|
||||
scene = new R3.D3.Scene(this.graphics, scene);
|
||||
|
||||
this.scenes.push(scene);
|
||||
|
||||
this.buildIdToObject();
|
||||
|
||||
/**
|
||||
* We need to add the meshes as components of this scene to the entity 'editor' of the 'entityManager' in this.
|
||||
*
|
||||
* We need a notify mechanism to notify the system of new mesh components
|
||||
*/
|
||||
scene.meshes.map(
|
||||
function(mesh){
|
||||
|
||||
/**
|
||||
* Get all entities with 3D renderers and some systems
|
||||
*/
|
||||
var entities = this.entityManager.query(
|
||||
[
|
||||
R3.D3.Renderer,
|
||||
R3.System
|
||||
]
|
||||
);
|
||||
|
||||
entities.map(
|
||||
function(entity){
|
||||
/**
|
||||
* Add all meshes to this entity
|
||||
*/
|
||||
entity.addComponent(mesh);
|
||||
|
||||
/**
|
||||
* Now we need to notify all systems of this new components
|
||||
*/
|
||||
var systems = entity.getComponents(R3.System);
|
||||
|
||||
systems.map(
|
||||
function(system){
|
||||
system.notify('meshes', R3.D3.Mesh)
|
||||
}.bind(this)
|
||||
)
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
};
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* Engine Superset
|
||||
* @param engineType
|
||||
* @param instance {CANNON | Ammo | Goblin}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Engine = function Engine(
|
||||
engineType,
|
||||
instance
|
||||
) {
|
||||
this.engineType = engineType;
|
||||
this.instance = instance;
|
||||
};
|
||||
|
||||
R3.D3.Engine.prototype.toApiEngine = function() {
|
||||
|
||||
//TODO: create API.Engine sometime
|
||||
return {
|
||||
engineType : this.engineType
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* True if CANNON physics
|
||||
* @returns {boolean}
|
||||
*/
|
||||
R3.D3.Engine.prototype.isCannon = function() {
|
||||
return (this.engineType == R3.D3.Engine.ENGINE_TYPE_CANNON)
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs a warning and throws an error if not cannon
|
||||
*/
|
||||
R3.D3.Engine.prototype.isNotCannonThrow = function() {
|
||||
if (this.engineType != R3.D3.Engine.ENGINE_TYPE_CANNON) {
|
||||
console.warn('Only CANNON supported for this function');
|
||||
throw new Error('Only CANNON supported for this function');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* True if Ammo physics
|
||||
* @returns {boolean}
|
||||
*/
|
||||
R3.D3.Engine.prototype.isAmmo = function() {
|
||||
return (this.engineType == R3.D3.Engine.ENGINE_TYPE_AMMO)
|
||||
};
|
||||
|
||||
/**
|
||||
* True if Goblin physics
|
||||
* @returns {boolean}
|
||||
*/
|
||||
R3.D3.Engine.prototype.isGoblin = function() {
|
||||
return (this.engineType == R3.D3.Engine.ENGINE_TYPE_GOBLIN)
|
||||
};
|
||||
|
||||
/**
|
||||
* Physics R3.D3.Engine Types
|
||||
* @type {number}
|
||||
*/
|
||||
R3.D3.Engine.ENGINE_TYPE_CANNON = 0x1;
|
||||
R3.D3.Engine.ENGINE_TYPE_AMMO = 0x2;
|
||||
R3.D3.Engine.ENGINE_TYPE_GOBLIN = 0x3;
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
* Fly Controls
|
||||
* @param camera
|
||||
* @param THREE
|
||||
* @param canvas
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.FlyControls = function(
|
||||
camera,
|
||||
THREE,
|
||||
canvas
|
||||
) {
|
||||
this.flySpeed = 100;
|
||||
|
||||
this.canvas = canvas;
|
||||
|
||||
this.THREE = THREE;
|
||||
|
||||
this.yaw = 0;
|
||||
this.pitch = 0;
|
||||
this.canRotate = false;
|
||||
|
||||
this.moveForward = false;
|
||||
this.moveBackward = false;
|
||||
this.moveLeft = false;
|
||||
this.moveRight = false;
|
||||
this.moveUp = false;
|
||||
this.moveDown = false;
|
||||
|
||||
|
||||
};
|
|
@ -0,0 +1,155 @@
|
|||
/**
|
||||
* Runtime Follow Component
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param apiFollow
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Follow = function (
|
||||
graphics,
|
||||
apiFollow
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiFollow)) {
|
||||
apiFollow = {};
|
||||
}
|
||||
|
||||
if (apiFollow instanceof R3.D3.Follow) {
|
||||
return apiFollow;
|
||||
}
|
||||
|
||||
R3.D3.API.Follow.call(
|
||||
this,
|
||||
apiFollow.id,
|
||||
apiFollow.name,
|
||||
apiFollow.currentComponent,
|
||||
apiFollow.targetComponent,
|
||||
apiFollow.targetPositionOffset,
|
||||
apiFollow.minDistance,
|
||||
apiFollow.moveSpeed,
|
||||
apiFollow.parentEntity
|
||||
);
|
||||
|
||||
this.targetPositionOffset = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.targetPositionOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.target = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.target,
|
||||
this
|
||||
);
|
||||
|
||||
this.targetToParent = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.targetToParent,
|
||||
this
|
||||
);
|
||||
|
||||
this.rotatedTargetOffset = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.rotatedTargetOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.rotated = new R3.Quaternion(
|
||||
this.graphics,
|
||||
this.rotated,
|
||||
this
|
||||
);
|
||||
|
||||
this.buildIdToObject();
|
||||
|
||||
};
|
||||
|
||||
R3.D3.Follow.prototype = Object.create(R3.D3.API.Follow.prototype);
|
||||
R3.D3.Follow.prototype.constructor = R3.D3.Follow;
|
||||
|
||||
R3.D3.Follow.prototype.toApiObject = function() {
|
||||
|
||||
var apiFollow = new R3.D3.API.Follow(
|
||||
this.id,
|
||||
this.name,
|
||||
R3.Utils.IdOrNull(this.currentComponent),
|
||||
R3.Utils.IdOrNull(this.targetComponent),
|
||||
this.targetPositionOffset.toApiObject(),
|
||||
this.minDistance,
|
||||
this.moveSpeed,
|
||||
R3.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
return apiFollow;
|
||||
};
|
||||
|
||||
R3.D3.Follow.FromObject = function(graphics, objectComponent) {
|
||||
|
||||
var apiFollow = R3.D3.API.Follow.FromObject(objectComponent);
|
||||
|
||||
return new R3.D3.Follow(
|
||||
graphics,
|
||||
apiFollow
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the component
|
||||
* @param deltaTime
|
||||
*/
|
||||
R3.D3.Follow.prototype.update = function(deltaTime) {
|
||||
|
||||
if (this.currentComponent && this.targetComponent) {
|
||||
|
||||
this.rotated.x = this.targetComponent.quaternion.x;
|
||||
this.rotated.y = this.targetComponent.quaternion.y;
|
||||
this.rotated.z = this.targetComponent.quaternion.z;
|
||||
this.rotated.w = this.targetComponent.quaternion.w;
|
||||
|
||||
// this.rotated.updateInstance();
|
||||
|
||||
this.rotatedTargetOffset.x = this.targetPositionOffset.x;
|
||||
this.rotatedTargetOffset.y = this.targetPositionOffset.y;
|
||||
this.rotatedTargetOffset.z = this.targetPositionOffset.z;
|
||||
|
||||
this.rotatedTargetOffset.applyQuaternion(this.rotated);
|
||||
|
||||
// this.rotatedTargetOffset.updateInstance();
|
||||
|
||||
this.target.x = this.targetComponent.position.x + this.rotatedTargetOffset.x;
|
||||
this.target.y = this.targetComponent.position.y + this.rotatedTargetOffset.y;
|
||||
this.target.z = this.targetComponent.position.z + this.rotatedTargetOffset.z;
|
||||
|
||||
// this.target.updateInstance();
|
||||
|
||||
this.targetToParent.x = this.currentComponent.position.x - this.targetComponent.position.x;
|
||||
this.targetToParent.y = this.currentComponent.position.y - this.targetComponent.position.y;
|
||||
this.targetToParent.z = this.currentComponent.position.z - this.targetComponent.position.z;
|
||||
|
||||
this.targetToParent.normalize();
|
||||
|
||||
this.targetToParent.x *= this.minDistance;
|
||||
this.targetToParent.y *= this.minDistance;
|
||||
this.targetToParent.z *= this.minDistance;
|
||||
|
||||
// this.targetToParent.updateInstance();
|
||||
|
||||
this.target.x = this.target.x + this.targetToParent.x;
|
||||
this.target.y = this.target.y + this.targetToParent.y;
|
||||
this.target.z = this.target.z + this.targetToParent.z;
|
||||
|
||||
// this.target.updateInstance();
|
||||
|
||||
var t = deltaTime * this.moveSpeed;
|
||||
|
||||
//t = t * t * t * (t * (6.0 * t - 15.0) + 10.0);
|
||||
|
||||
var lerp = this.currentComponent.position.lerp(this.target, t);
|
||||
|
||||
this.currentComponent.position.x = lerp.x;
|
||||
this.currentComponent.position.y = lerp.y;
|
||||
this.currentComponent.position.z = lerp.z;
|
||||
}
|
||||
|
||||
};
|
|
@ -0,0 +1,431 @@
|
|||
/**
|
||||
* Game Runtime
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param apiGame R3.D3.API.Game
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Game = function (
|
||||
graphics,
|
||||
apiGame
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiGame)) {
|
||||
apiGame = {};
|
||||
}
|
||||
|
||||
if (apiGame instanceof R3.D3.Game) {
|
||||
return apiGame;
|
||||
}
|
||||
|
||||
R3.D3.API.Game.call(
|
||||
this,
|
||||
apiGame.id,
|
||||
apiGame.name,
|
||||
apiGame.baseUrl,
|
||||
apiGame.path,
|
||||
apiGame.imageFactory,
|
||||
apiGame.gameType,
|
||||
apiGame.cameras,
|
||||
apiGame.composers,
|
||||
apiGame.viewports,
|
||||
apiGame.renderers,
|
||||
apiGame.renderTargets,
|
||||
apiGame.systems,
|
||||
apiGame.entityManager,
|
||||
apiGame.parentEntity
|
||||
);
|
||||
|
||||
if (this.imageFactory instanceof R3.D3.API.ImageFactory) {
|
||||
this.imageFactory = new R3.D3.ImageFactory(
|
||||
this.graphics,
|
||||
this.imageFactory
|
||||
);
|
||||
}
|
||||
|
||||
this.cameras = this.cameras.map(
|
||||
function (apiCamera) {
|
||||
if (apiCamera instanceof R3.D3.API.Camera) {
|
||||
return new R3.D3.Camera(
|
||||
this.graphics,
|
||||
apiCamera
|
||||
)
|
||||
} else {
|
||||
console.warn('apiCamera not of type API.Camera');
|
||||
throw new Error('apiCamera not of type API.Camera');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.composers = this.composers.map(
|
||||
function (apiComposer) {
|
||||
if (apiComposer instanceof R3.D3.API.Composer) {
|
||||
return new R3.D3.Composer(
|
||||
this.graphics,
|
||||
apiComposer
|
||||
)
|
||||
} else {
|
||||
console.warn('apiComposer not of type API.Composer');
|
||||
throw new Error('apiComposer not of type API.Composer');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.viewports = this.viewports.map(
|
||||
function (apiViewport) {
|
||||
if (apiViewport instanceof R3.D3.API.Viewport) {
|
||||
return new R3.D3.Viewport(
|
||||
this.graphics,
|
||||
apiViewport
|
||||
)
|
||||
} else {
|
||||
console.warn('apiViewport not of type API.Viewport');
|
||||
throw new Error('apiViewport not of type API.Viewport');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.renderers = this.renderers.map(
|
||||
function (apiRenderer) {
|
||||
if (apiRenderer instanceof R3.D3.API.Renderer) {
|
||||
return new R3.D3.Renderer(
|
||||
this.graphics,
|
||||
apiRenderer
|
||||
)
|
||||
} else {
|
||||
console.warn('apiRenderer not of type API.Renderer');
|
||||
throw new Error('apiRenderer not of type API.Renderer');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.renderTargets = this.renderTargets.map(
|
||||
function (apiRenderTarget) {
|
||||
if (apiRenderTarget instanceof R3.D3.API.RenderTarget) {
|
||||
return new R3.D3.RenderTarget(
|
||||
this.graphics,
|
||||
apiRenderTarget
|
||||
)
|
||||
} else {
|
||||
console.warn('apiRenderTarget not of type API.RenderTarget');
|
||||
throw new Error('apiRenderTarget not of type API.RenderTarget');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
this.systems = this.systems.map(
|
||||
function (apiSystem) {
|
||||
if (apiSystem instanceof R3.API.System) {
|
||||
return new R3.System(
|
||||
this.graphics,
|
||||
apiSystem
|
||||
)
|
||||
} else {
|
||||
console.warn('apiSystem not of type API.System');
|
||||
throw new Error('apiSystem not of type API.System');
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
if (this.entityManager) {
|
||||
if (this.entityManager instanceof R3.API.EntityManager) {
|
||||
this.entityManager = new R3.EntityManager(
|
||||
this.graphics,
|
||||
this.entityManager
|
||||
);
|
||||
} else {
|
||||
console.warn('entityManager not of type API.EntityManager');
|
||||
throw new Error('entityManager not of type API.EntityManager');
|
||||
}
|
||||
}
|
||||
|
||||
this.buildIdToObject();
|
||||
|
||||
this.linkObjects(this.idToObject);
|
||||
};
|
||||
|
||||
R3.D3.Game.prototype = Object.create(R3.D3.API.Game.prototype);
|
||||
R3.D3.Game.prototype.constructor = R3.D3.Game;
|
||||
|
||||
R3.D3.Game.GAME_TYPE_VR_PONG = 0x1;
|
||||
R3.D3.Game.GAME_TYPE_VR_RACER = 0x2;
|
||||
|
||||
/**
|
||||
* Creates a camera instance of 'graphics' type (only THREE for now)
|
||||
* @returns {THREE.Game}
|
||||
*/
|
||||
R3.D3.Game.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
}
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
// R3.D3.Game.prototype.setSize = function(width, height) {
|
||||
//
|
||||
// // var w = 0;
|
||||
// // var h = 0;
|
||||
//
|
||||
// this.viewports.map(
|
||||
// function(viewport) {
|
||||
// // w = viewport.width;
|
||||
// // h = viewport.height;
|
||||
// //
|
||||
// // //TODO : calculate width and height decrease or increase ratio and adjust viewport x and y offset according
|
||||
// // var wx = width / w;
|
||||
// // var hx = height / h;
|
||||
//
|
||||
// viewport.width = width;
|
||||
// viewport.height = height;
|
||||
//
|
||||
// viewport.updateInstance();
|
||||
// }
|
||||
// )
|
||||
//
|
||||
// };
|
||||
|
||||
/**
|
||||
* Updates the instance with the current state
|
||||
*/
|
||||
R3.D3.Game.prototype.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a R3.D3.Game to a new R3.D3.API.Game
|
||||
* @returns {R3.D3.API.Game}
|
||||
*/
|
||||
R3.D3.Game.prototype.toApiObject = function() {
|
||||
|
||||
var apiImageFactory = null;
|
||||
var apiCameras = [];
|
||||
var apiComposers = [];
|
||||
var apiViewports = [];
|
||||
var apiRenderers = [];
|
||||
var apiRenderTargets = [];
|
||||
var apiSystems = [];
|
||||
var apiEntityManager = null;
|
||||
|
||||
if (this.imageFactory instanceof R3.D3.ImageFactory) {
|
||||
apiImageFactory = this.imageFactory.toApiObject();
|
||||
}
|
||||
|
||||
if (this.cameras) {
|
||||
apiCameras = this.cameras.map(
|
||||
function(camera) {
|
||||
if (camera instanceof R3.D3.Camera) {
|
||||
return camera.toApiObject();
|
||||
} else {
|
||||
console.warn('camera not an instance of Camera');
|
||||
throw new Error('camera not an instance of Camera');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.composers) {
|
||||
apiComposers = this.composers.map(
|
||||
function(composer) {
|
||||
if (composer instanceof R3.D3.Composer) {
|
||||
return composer.toApiObject();
|
||||
} else {
|
||||
console.warn('composer not an instance of Composer');
|
||||
throw new Error('composer not an instance of Composer');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.viewports) {
|
||||
apiViewports = this.viewports.map(
|
||||
function(viewport) {
|
||||
if (viewport instanceof R3.D3.Viewport) {
|
||||
return viewport.toApiObject();
|
||||
} else {
|
||||
console.warn('viewport not an instance of Viewport');
|
||||
throw new Error('viewport not an instance of Viewport');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.renderers) {
|
||||
apiRenderers = this.renderers.map(
|
||||
function(renderer) {
|
||||
if (renderer instanceof R3.D3.Renderer) {
|
||||
return renderer.toApiObject();
|
||||
} else {
|
||||
console.warn('renderer not an instance of Renderer');
|
||||
throw new Error('renderer not an instance of Renderer');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.renderTargets) {
|
||||
apiRenderTargets = this.renderTargets.map(
|
||||
function(renderTarget) {
|
||||
if (renderTarget instanceof R3.D3.RenderTarget) {
|
||||
return renderTarget.toApiObject();
|
||||
} else {
|
||||
console.warn('renderTarget not an instance of RenderTarget');
|
||||
throw new Error('renderTarget not an instance of RenderTarget');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.systems) {
|
||||
apiSystems = this.systems.map(
|
||||
function(system) {
|
||||
if (system instanceof R3.System) {
|
||||
return system.toApiObject();
|
||||
} else {
|
||||
console.warn('system not an instance of System');
|
||||
throw new Error('system not an instance of System');
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (this.entityManager) {
|
||||
if (this.entityManager instanceof R3.EntityManager) {
|
||||
apiEntityManager = this.entityManager.toApiObject();
|
||||
} else {
|
||||
console.warn('entityManager not an instance of EntityManager');
|
||||
throw new Error('entityManager not an instance of EntityManager');
|
||||
}
|
||||
}
|
||||
|
||||
return new R3.D3.API.Game(
|
||||
this.id,
|
||||
this.name,
|
||||
this.baseUrl,
|
||||
this.path,
|
||||
apiImageFactory,
|
||||
this.gameType,
|
||||
apiCameras,
|
||||
apiComposers,
|
||||
apiViewports,
|
||||
apiRenderers,
|
||||
apiRenderTargets,
|
||||
apiSystems,
|
||||
apiEntityManager,
|
||||
R3.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts from an Object Game to a R3.D3.Game
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param objectGame Object
|
||||
* @returns {R3.D3.Game}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Game.FromObjectGame = function(graphics, objectGame) {
|
||||
|
||||
var apiGame = R3.D3.API.Game.FromObjectGame(objectGame);
|
||||
|
||||
return new R3.D3.Game(
|
||||
graphics,
|
||||
apiGame
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads a Game
|
||||
* @param graphics
|
||||
* @param objectGame
|
||||
* @param onLoaded
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Game.LoadGame = function(
|
||||
graphics,
|
||||
objectGame,
|
||||
onLoaded
|
||||
) {
|
||||
var game = R3.D3.Game.FromObjectGame(
|
||||
graphics,
|
||||
objectGame
|
||||
);
|
||||
|
||||
onLoaded(game);
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads a Game from the API
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param partialGameObject Object
|
||||
* @param onLoaded callback
|
||||
* @param apiUrl
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Game.LoadGameFromApi = function(
|
||||
graphics,
|
||||
partialGameObject,
|
||||
onLoaded,
|
||||
apiUrl
|
||||
) {
|
||||
|
||||
/**
|
||||
* First check if this is a client or server side request
|
||||
*/
|
||||
if (typeof XMLHttpRequest == 'undefined') {
|
||||
console.warn('Implement server side loading from API here');
|
||||
return onLoaded(
|
||||
null,
|
||||
new Error('Not Implemented')
|
||||
);
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open(
|
||||
'GET',
|
||||
apiUrl + '/game/load' + partialGameObject.path + '/' + partialGameObject.name
|
||||
);
|
||||
|
||||
xhr.onreadystatechange = function(xhr) {
|
||||
|
||||
return function() {
|
||||
|
||||
if (xhr.readyState == 4) {
|
||||
|
||||
try {
|
||||
var response = JSON.parse(xhr.responseText);
|
||||
} catch (e) {
|
||||
return onLoaded(null, new Error('Could not load game : ' + e.message));
|
||||
}
|
||||
|
||||
if (!response.game || response.game.length == 0) {
|
||||
return onLoaded(null, new Error('Could not load game'));
|
||||
}
|
||||
|
||||
var objectGame = response.game[0];
|
||||
|
||||
R3.D3.Game.LoadGame(
|
||||
graphics,
|
||||
objectGame,
|
||||
onLoaded
|
||||
);
|
||||
}
|
||||
}
|
||||
}(xhr);
|
||||
|
||||
xhr.send();
|
||||
};
|
||||
|
||||
R3.D3.Game.prototype.setSize = function(width, height) {
|
||||
this.renderers.map(
|
||||
function(renderer) {
|
||||
renderer.setSize(width, height);
|
||||
}
|
||||
);
|
||||
};
|
|
@ -0,0 +1,166 @@
|
|||
/**
|
||||
* @param sizeX Number
|
||||
* @param sizeY Number
|
||||
* @param matrix matrix 2D Array with height data (Column Major)
|
||||
* @param elementSize Number
|
||||
* @param heightScale Number
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Heightmap = function Heightmap(
|
||||
sizeX,
|
||||
sizeY,
|
||||
matrix,
|
||||
elementSize,
|
||||
heightScale
|
||||
) {
|
||||
if (typeof sizeX == 'undefined') {
|
||||
sizeX = 0;
|
||||
}
|
||||
this.sizeX = sizeX;
|
||||
|
||||
if (typeof sizeY == 'undefined') {
|
||||
sizeY = 0;
|
||||
}
|
||||
this.sizeY = sizeY;
|
||||
|
||||
if (typeof matrix == 'undefined') {
|
||||
matrix = [];
|
||||
}
|
||||
this.matrix = matrix;
|
||||
|
||||
if (typeof elementSize == 'undefined') {
|
||||
elementSize = 10;
|
||||
}
|
||||
this.elementSize = elementSize;
|
||||
|
||||
if (typeof heightScale == 'undefined') {
|
||||
heightScale = 15;
|
||||
}
|
||||
this.elementSize = heightScale;
|
||||
};
|
||||
|
||||
|
||||
R3.D3.Heightmap.prototype.toApiHeightMap = function() {
|
||||
//TODO - create API heightmap someday
|
||||
return {
|
||||
sizeX: this.sizeX,
|
||||
sizeY: this.sizeY,
|
||||
matrix: this.matrix,
|
||||
elementSize: this.elementSize,
|
||||
heightScale: this.heightScale
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a graphics instance mesh from the graphics, physics and physics shape
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param shape R3.D3.Shape
|
||||
* @param engine R3.D3.Engine
|
||||
* @returns {THREE.Mesh|this.meshes}
|
||||
*/
|
||||
R3.D3.Heightmap.GenerateInstanceMesh = function(
|
||||
graphics,
|
||||
shape,
|
||||
engine
|
||||
) {
|
||||
graphics.isNotThreeThrow();
|
||||
engine.isNotCannonThrow();
|
||||
|
||||
var geometry = new graphics.instance.Geometry();
|
||||
|
||||
var v0 = new engine.instance.Vec3();
|
||||
var v1 = new engine.instance.Vec3();
|
||||
var v2 = new engine.instance.Vec3();
|
||||
|
||||
for (var xi = 0; xi < shape.instance.data.length - 1; xi++) {
|
||||
for (var yi = 0; yi < shape.instance.data[xi].length - 1; yi++) {
|
||||
for (var k = 0; k < 2; k++) {
|
||||
shape.instance.getConvexTrianglePillar(xi, yi, k===0);
|
||||
v0.copy(shape.instance.pillarConvex.vertices[0]);
|
||||
v1.copy(shape.instance.pillarConvex.vertices[1]);
|
||||
v2.copy(shape.instance.pillarConvex.vertices[2]);
|
||||
v0.vadd(shape.instance.pillarOffset, v0);
|
||||
v1.vadd(shape.instance.pillarOffset, v1);
|
||||
v2.vadd(shape.instance.pillarOffset, v2);
|
||||
geometry.vertices.push(
|
||||
new graphics.instance.Vector3(v0.x, v0.y, v0.z),
|
||||
new graphics.instance.Vector3(v1.x, v1.y, v1.z),
|
||||
new graphics.instance.Vector3(v2.x, v2.y, v2.z)
|
||||
);
|
||||
var i = geometry.vertices.length - 3;
|
||||
geometry.faces.push(new graphics.instance.Face3(i, i+1, i+2));
|
||||
}
|
||||
}
|
||||
}
|
||||
geometry.computeBoundingSphere();
|
||||
geometry.computeFaceNormals();
|
||||
|
||||
return new graphics.instance.Mesh(
|
||||
geometry,
|
||||
new graphics.instance.MeshNormalMaterial(
|
||||
{
|
||||
wireframe: false,
|
||||
shading : graphics.instance.SmoothShading
|
||||
}
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Needs an RGBA
|
||||
* @param imagePath string
|
||||
* @param heightScale
|
||||
* @param callback
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Heightmap.GenerateHeightmapDataFromImage = function (
|
||||
imagePath,
|
||||
heightScale,
|
||||
callback
|
||||
) {
|
||||
var img = new Image();
|
||||
|
||||
img.onload = function () {
|
||||
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
|
||||
var context = canvas.getContext('2d');
|
||||
context.drawImage(img, 0, 0);
|
||||
|
||||
var imgd = context.getImageData(0, 0, img.width, img.height);
|
||||
var pixels = imgd.data;
|
||||
|
||||
var heightList = [];
|
||||
for (var i = 0, n = pixels.length; i < n; i += (4)) {
|
||||
heightList.push(pixels[i]);
|
||||
}
|
||||
|
||||
var matrix = [];
|
||||
var sizeX = img.width,
|
||||
sizeY = img.height;
|
||||
|
||||
for (var x = 0; x < sizeX; x++) {
|
||||
matrix.push([]);
|
||||
for (var j = 0; j < sizeY; j++) {
|
||||
var height = (heightList[(sizeX - x) + j * sizeY] / 255) * heightScale;
|
||||
matrix[x].push(height);
|
||||
}
|
||||
}
|
||||
|
||||
// todo: delete canvas here
|
||||
|
||||
callback(
|
||||
new R3.D3.Heightmap(
|
||||
sizeX,
|
||||
sizeY,
|
||||
matrix,
|
||||
10,
|
||||
heightScale
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
img.src = imagePath;
|
||||
};
|
|
@ -0,0 +1,156 @@
|
|||
/**
|
||||
* The image factory takes care that we only make requests for Image URLs which we have not already started downloading
|
||||
* @param graphics
|
||||
* @param apiImageFactory
|
||||
* @param progressCallback
|
||||
* @returns {R3.D3.ImageFactory}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.ImageFactory = function (
|
||||
graphics,
|
||||
apiImageFactory,
|
||||
progressCallback
|
||||
) {
|
||||
graphics.isNotThreeThrow();
|
||||
this.graphics = graphics;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiImageFactory)) {
|
||||
apiImageFactory = {};
|
||||
}
|
||||
|
||||
if (apiImageFactory instanceof R3.D3.ImageFactory) {
|
||||
return apiImageFactory;
|
||||
}
|
||||
|
||||
R3.D3.API.ImageFactory.call(
|
||||
this,
|
||||
apiImageFactory.id,
|
||||
apiImageFactory.name,
|
||||
apiImageFactory.baseUrl,
|
||||
apiImageFactory.parentEntity
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(progressCallback)) {
|
||||
progressCallback = null;
|
||||
}
|
||||
this.progressCallback = progressCallback;
|
||||
|
||||
R3.Component.call(
|
||||
this,
|
||||
R3.Component.COMPONENT_IMAGE_FACTORY
|
||||
);
|
||||
|
||||
this.promiseList = {};
|
||||
};
|
||||
|
||||
R3.D3.ImageFactory.prototype = Object.create(R3.D3.API.ImageFactory.prototype);
|
||||
R3.D3.ImageFactory.prototype.constructor = R3.D3.ImageFactory;
|
||||
|
||||
R3.D3.ImageFactory.prototype.createInstance = function(update) {
|
||||
|
||||
if (!this.loaded) {
|
||||
console.log('Attempted to create an instance but the runtime object is not fully loaded : ' + this.name);
|
||||
return null;
|
||||
}
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (update) {
|
||||
instance = this.instance;
|
||||
} else {
|
||||
instance = new THREE.ImageLoader();
|
||||
}
|
||||
|
||||
instance.crossOrigin = '';
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update instance
|
||||
*/
|
||||
R3.D3.ImageFactory.prototype.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Loads an image, either returns the image immediately if already loaded, or a promise to load the image
|
||||
* @param imagePath
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.ImageFactory.prototype.loadImage = function(
|
||||
imagePath,
|
||||
force
|
||||
) {
|
||||
|
||||
imagePath = imagePath.replace(new RegExp('\/*'), '/');
|
||||
|
||||
if (!imagePath) {
|
||||
console.log('Attempted to download bad URL : ' + imagePath);
|
||||
throw new Error('Bad URL : ' + imagePath);
|
||||
}
|
||||
|
||||
if (!force && this.promiseList[imagePath]) {
|
||||
return this.promiseList[imagePath];
|
||||
}
|
||||
|
||||
var defer = Q.defer();
|
||||
|
||||
this.promiseList[imagePath] = defer.promise;
|
||||
|
||||
this.instance.load(
|
||||
this.baseUrl + imagePath + '?ts=' + Date.now(),
|
||||
function (image) {
|
||||
|
||||
R3.Event.Emit(
|
||||
R3.Event.IMAGE_LOADED,
|
||||
{
|
||||
imagePath : imagePath,
|
||||
imageInstance : image
|
||||
}
|
||||
);
|
||||
|
||||
defer.resolve(image);
|
||||
}.bind(this),
|
||||
function onProgress(xhr) {
|
||||
if (this.progressCallback) {
|
||||
this.progressCallback((xhr.loaded / xhr.total * 100));
|
||||
}
|
||||
}.bind(this),
|
||||
function onError() {
|
||||
defer.reject('Failed to download image : ' + this.baseUrl + imagePath);
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
return this.promiseList[imagePath];
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a R3.D3.ImageFactory to a R3.D3.API.ImageFactory
|
||||
* @returns {R3.D3.API.ImageFactory}
|
||||
*/
|
||||
R3.D3.ImageFactory.prototype.toApiObject = function() {
|
||||
return new R3.D3.API.ImageFactory(
|
||||
this.id,
|
||||
this.name,
|
||||
this.baseUrl,
|
||||
R3.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a new R3.D3.ImageFactory from a R3.D3.API.ImageFactory
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param objectImageFactory R3.D3.API.ImageFactory
|
||||
* @returns {R3.D3.ImageFactory}
|
||||
*/
|
||||
R3.D3.ImageFactory.FromObject = function(graphics, objectImageFactory) {
|
||||
|
||||
return new R3.D3.ImageFactory(
|
||||
graphics,
|
||||
R3.D3.API.ImageFactory.FromObject(objectImageFactory)
|
||||
);
|
||||
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* R3.D3.Input namespace
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Input = function () {};
|
|
@ -0,0 +1,174 @@
|
|||
/**
|
||||
* Input parent class
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param apiInputDrive R3.D3.API.Input.Drive
|
||||
* @param dom R3.Dom
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Input.Drive = function (
|
||||
graphics,
|
||||
apiInputDrive,
|
||||
dom
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiInputDrive)) {
|
||||
apiInputDrive = {};
|
||||
}
|
||||
|
||||
if (apiInputDrive instanceof R3.D3.Drive) {
|
||||
return apiInputDrive;
|
||||
}
|
||||
|
||||
R3.D3.API.Input.Drive.call(
|
||||
this,
|
||||
apiInputDrive.id,
|
||||
apiInputDrive.name,
|
||||
apiInputDrive.domElementId,
|
||||
apiInputDrive.pathFollowingComponent,
|
||||
apiInputDrive.parentEntity,
|
||||
apiInputDrive.wheelFL,
|
||||
apiInputDrive.wheelFR,
|
||||
apiInputDrive.wheelRL,
|
||||
apiInputDrive.wheelRR,
|
||||
apiInputDrive.heightOffset,
|
||||
apiInputDrive.distance,
|
||||
apiInputDrive.distanceGrain,
|
||||
apiInputDrive.rotationFactor
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(dom)) {
|
||||
console.warn('Cannot create Input without an handle to the DOM');
|
||||
throw new Error('Cannot create Input without an handle to the DOM');
|
||||
}
|
||||
this.dom = dom;
|
||||
|
||||
this.keyLeft = false;
|
||||
|
||||
this.keyRight = false;
|
||||
|
||||
R3.Component.call(
|
||||
this,
|
||||
R3.Component.COMPONENT_INPUT_DRIVE,
|
||||
{
|
||||
'pathFollowingComponent' : R3.D3.PathFollowing,
|
||||
'wheelFL' : R3.D3.Mesh,
|
||||
'wheelFR' : R3.D3.Mesh,
|
||||
'wheelRL' : R3.D3.Mesh,
|
||||
'wheelRR' : R3.D3.Mesh
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.Input.Drive.prototype = Object.create(R3.D3.API.Input.Drive.prototype);
|
||||
R3.D3.Input.Drive.prototype.constructor = R3.D3.Input.Drive;
|
||||
|
||||
R3.D3.Input.Drive.prototype.createInstance = function(update) {
|
||||
|
||||
if (update) {
|
||||
return this.instance;
|
||||
}
|
||||
|
||||
var instance = this.dom.document.getElementById(this.domElementId);
|
||||
|
||||
instance.addEventListener(
|
||||
'keydown',
|
||||
function(keyboardEvent) {
|
||||
if (keyboardEvent.key == 'j') {
|
||||
this.keyLeft = true;
|
||||
}
|
||||
|
||||
if (keyboardEvent.key == 'l') {
|
||||
this.keyRight = true;
|
||||
}
|
||||
}.bind(this),
|
||||
false
|
||||
);
|
||||
|
||||
instance.addEventListener(
|
||||
'keyup',
|
||||
function(keyboardEvent) {
|
||||
if (keyboardEvent.key == 'j') {
|
||||
this.keyLeft = false;
|
||||
}
|
||||
|
||||
if (keyboardEvent.key == 'l') {
|
||||
this.keyRight = false;
|
||||
}
|
||||
}.bind(this),
|
||||
false
|
||||
);
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
R3.D3.Input.Drive.prototype.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
};
|
||||
|
||||
/**
|
||||
* R3.D3.Input.Drive to R3.D3.API.Input.Drive
|
||||
* @returns {R3.D3.API.Input.Drive}
|
||||
*/
|
||||
R3.D3.Input.Drive.prototype.toApiObject = function() {
|
||||
|
||||
var apiInputDrive = new R3.D3.API.Input.Drive(
|
||||
this.id,
|
||||
this.name,
|
||||
this.domElementId,
|
||||
R3.Utils.IdOrNull(this.pathFollowingComponent),
|
||||
R3.Utils.IdOrNull(this.parentEntity),
|
||||
R3.Utils.IdOrNull(this.wheelFL),
|
||||
R3.Utils.IdOrNull(this.wheelFR),
|
||||
R3.Utils.IdOrNull(this.wheelRL),
|
||||
R3.Utils.IdOrNull(this.wheelRR),
|
||||
this.heightOffset,
|
||||
this.distance,
|
||||
this.distanceGrain,
|
||||
this.rotationFactor
|
||||
);
|
||||
|
||||
return apiInputDrive;
|
||||
};
|
||||
|
||||
R3.D3.Input.Drive.FromObject = function(graphics, objectComponent) {
|
||||
|
||||
var apiInputDrive = R3.D3.API.Input.Drive.FromObject(objectComponent);
|
||||
|
||||
return new R3.D3.Input.Drive(
|
||||
graphics,
|
||||
apiInputDrive
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.Input.Drive.prototype.update = function(deltaTime) {
|
||||
if (this.pathFollowingComponent) {
|
||||
|
||||
this.pathFollowingComponent.mesh.localPosition.x = (this.heightOffset * this.pathFollowingComponent.rotationMatrix.up.x);
|
||||
this.pathFollowingComponent.mesh.localPosition.y = (this.heightOffset * this.pathFollowingComponent.rotationMatrix.up.y);
|
||||
this.pathFollowingComponent.mesh.localPosition.z = (this.heightOffset * this.pathFollowingComponent.rotationMatrix.up.z);
|
||||
|
||||
if (this.keyLeft) {
|
||||
this.distance -= this.distanceGrain;
|
||||
}
|
||||
|
||||
if (this.keyRight) {
|
||||
this.distance += this.distanceGrain;
|
||||
}
|
||||
|
||||
this.pathFollowingComponent.mesh.localPosition.x += (this.distance * this.pathFollowingComponent.rotationMatrix.left.x);
|
||||
this.pathFollowingComponent.mesh.localPosition.y += (this.distance * this.pathFollowingComponent.rotationMatrix.left.y);
|
||||
this.pathFollowingComponent.mesh.localPosition.z += (this.distance * this.pathFollowingComponent.rotationMatrix.left.z);
|
||||
|
||||
this.wheelFL.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed;
|
||||
this.wheelFR.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed;
|
||||
|
||||
this.wheelFL.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed;
|
||||
this.wheelFR.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed;
|
||||
|
||||
this.wheelRL.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed;
|
||||
this.wheelRR.localRotation.x += this.rotationFactor * this.pathFollowingComponent.currentSpeed;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* Input parent class
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param parentObject
|
||||
* @param apiInputEditor R3.D3.API.Input.Editor
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Input.Editor = function RuntimeEditorInput(
|
||||
graphics,
|
||||
parentObject,
|
||||
apiInputEditor
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
R3.D3.API.Input.Editor.call(
|
||||
this,
|
||||
apiInputEditor.id,
|
||||
apiInputEditor.name,
|
||||
apiInputEditor.domElementId,
|
||||
apiInputEditor.camera,
|
||||
apiInputEditor.parentEntity
|
||||
);
|
||||
|
||||
/**
|
||||
* Don't create an instance here - since we don't have our camera loaded yet...
|
||||
*/
|
||||
};
|
||||
|
||||
R3.D3.Input.Editor.prototype = Object.create(R3.D3.API.Input.Editor.prototype);
|
||||
R3.D3.Input.Editor.prototype.constructor = R3.D3.Input.Editor;
|
||||
|
||||
R3.D3.Input.Editor.prototype.createInstance = function(update) {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (this.camera && this.domElementId) {
|
||||
instance = new THREE.EditorControls(
|
||||
this.camera.instance,
|
||||
document.getElementById(this.domElementId)
|
||||
);
|
||||
}
|
||||
|
||||
this.instance = instance;
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
R3.D3.Input.Editor.prototype.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
};
|
||||
|
||||
R3.D3.Input.Editor.prototype.toApiComponent = function() {
|
||||
|
||||
var apiInputEditor = new R3.D3.API.Input.Editor(
|
||||
this.id,
|
||||
this.name,
|
||||
this.domElementId,
|
||||
R3.Utils.IdOrNull(this.camera),
|
||||
R3.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
return apiInputEditor;
|
||||
};
|
||||
|
||||
R3.D3.Input.Editor.FromObjectComponent = function(graphics, objectComponent) {
|
||||
|
||||
var apiInputEditor = new R3.D3.API.Input.Editor(
|
||||
objectComponent.id,
|
||||
objectComponent.name,
|
||||
objectComponent.domElementId,
|
||||
objectComponent.camera,
|
||||
objectComponent.parentEntity
|
||||
);
|
||||
|
||||
return new R3.D3.Input.Editor(
|
||||
graphics,
|
||||
this,
|
||||
apiInputEditor
|
||||
);
|
||||
};
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
* Input parent class
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param apiInputEditor R3.D3.API.Input.Editor
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Input.Editor = function (
|
||||
graphics,
|
||||
apiInputEditor
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiInputEditor)) {
|
||||
apiInputEditor = {};
|
||||
}
|
||||
|
||||
if (apiInputEditor instanceof R3.D3.Input.Editor) {
|
||||
return apiInputEditor;
|
||||
}
|
||||
|
||||
R3.D3.API.Input.Editor.call(
|
||||
this,
|
||||
apiInputEditor.id,
|
||||
apiInputEditor.name,
|
||||
apiInputEditor.domElement,
|
||||
apiInputEditor.camera,
|
||||
apiInputEditor.parentEntity
|
||||
);
|
||||
|
||||
if (this.domElement instanceof R3.API.DomElement) {
|
||||
this.domElement = new R3.DomElement(
|
||||
this.domElement
|
||||
)
|
||||
}
|
||||
|
||||
if (this.camera instanceof R3.D3.API.Camera) {
|
||||
this.camera = new R3.D3.Camera(
|
||||
this.graphics,
|
||||
this.camera
|
||||
)
|
||||
}
|
||||
|
||||
R3.Component.call(
|
||||
this,
|
||||
R3.Component.COMPONENT_INPUT_EDITOR,
|
||||
{
|
||||
'camera' : R3.D3.Camera
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.Input.Editor.prototype = Object.create(R3.D3.API.Input.Editor.prototype);
|
||||
R3.D3.Input.Editor.prototype.constructor = R3.D3.Input.Editor;
|
||||
|
||||
R3.D3.Input.Editor.prototype.createInstance = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
R3.D3.Input.Editor.prototype.updateInstance = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* R3.D3.Input.Editor to R3.D3.API.Input.Editor
|
||||
* @returns {R3.D3.API.Input.Editor}
|
||||
*/
|
||||
R3.D3.Input.Editor.prototype.toApiObject = function() {
|
||||
|
||||
var apiInputEditor = new R3.D3.API.Input.Editor(
|
||||
this.id,
|
||||
this.name,
|
||||
this.domElementId,
|
||||
R3.Utils.IdOrNull(this.camera),
|
||||
R3.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
return apiInputEditor;
|
||||
};
|
||||
|
||||
R3.D3.Input.Editor.FromObject = function(graphics, objectComponent) {
|
||||
|
||||
var apiInputEditor = R3.D3.API.Input.Editor.FromObject(objectComponent);
|
||||
|
||||
return new R3.D3.Input.Editor(
|
||||
graphics,
|
||||
apiInputEditor
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,285 @@
|
|||
/**
|
||||
* Input parent class
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param parentObject
|
||||
* @param apiInputFly R3.D3.API.Input.Fly
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Input.Fly = function RuntimeEditorInput(
|
||||
graphics,
|
||||
parentObject,
|
||||
apiInputFly
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
R3.D3.API.Input.Fly.call(
|
||||
this,
|
||||
apiInputFly.id,
|
||||
apiInputFly.name,
|
||||
apiInputFly.domElementId,
|
||||
apiInputFly.camera
|
||||
);
|
||||
|
||||
this.mouseUpCallback = this.onMouseUp.bind(this);
|
||||
this.mouseDownCallback = this.onMouseDown.bind(this);
|
||||
this.mouseMoveCallback = this.onMouseMove.bind(this);
|
||||
this.mouseWheelCallback = this.onMouseWheel.bind(this);
|
||||
this.keyDownCallback = this.onKeyDown.bind(this);
|
||||
this.keyUpCallback = this.onKeyUp.bind(this);
|
||||
|
||||
this.camera = camera;
|
||||
|
||||
this.canvas.addEventListener('keydown', this.keyDownCallback, false);
|
||||
this.canvas.addEventListener('keyup', this.keyUpCallback, false);
|
||||
this.canvas.addEventListener('mousedown', this.mouseDownCallback, false);
|
||||
this.canvas.addEventListener('mouseup', this.mouseUpCallback, false);
|
||||
this.canvas.addEventListener('mousewheel', this.mouseWheelCallback, false);
|
||||
|
||||
this.havePointerLock = 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document;
|
||||
this.element = document.body;
|
||||
|
||||
if (this.havePointerLock) {
|
||||
this.element.requestPointerLock = this.element.requestPointerLock || this.element.mozRequestPointerLock || this.element.webkitRequestPointerLock;
|
||||
document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't create an instance here - since we don't have our camera loaded yet...
|
||||
*/
|
||||
};
|
||||
|
||||
R3.D3.Input.Fly.prototype = Object.create(R3.D3.API.Input.Fly.prototype);
|
||||
R3.D3.Input.Fly.prototype.constructor = R3.D3.Input.Fly;
|
||||
|
||||
R3.D3.Input.Fly.prototype.createInstance = function(update) {
|
||||
|
||||
//todo
|
||||
};
|
||||
|
||||
R3.D3.Input.Fly.prototype.updateInstance = function() {
|
||||
this.instance = this.createInstance(true);
|
||||
};
|
||||
|
||||
R3.D3.Input.Fly.prototype.toApiComponent = function() {
|
||||
|
||||
var apiInputFly = new R3.D3.API.Input.Fly(
|
||||
this.id,
|
||||
this.name,
|
||||
this.domElementId,
|
||||
R3.Utils.IdOrNull(this.camera)
|
||||
);
|
||||
|
||||
return apiInputFly;
|
||||
};
|
||||
|
||||
R3.D3.Input.Fly.FromObjectComponent = function(graphics, objectComponent) {
|
||||
|
||||
var apiInputFly = new R3.D3.API.Input.Fly(
|
||||
objectComponent.id,
|
||||
objectComponent.name,
|
||||
objectComponent.domElementId,
|
||||
objectComponent.camera
|
||||
);
|
||||
|
||||
return new R3.D3.Input.Fly(
|
||||
graphics,
|
||||
this,
|
||||
apiInputFly
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Go forward / backward on mouse wheel
|
||||
* @param event
|
||||
*/
|
||||
R3.D3.Input.Fly.prototype.onMouseWheel = function(event) {
|
||||
this.moveForward = true;
|
||||
this.applyTranslation(event.wheelDelta * 0.001);
|
||||
event.preventDefault();
|
||||
this.moveForward = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Start rotating the camera on mouse middle button down
|
||||
* @param event
|
||||
*/
|
||||
R3.D3.Input.Fly.prototype.onMouseDown = function(event) {
|
||||
if (event.button == 1) {
|
||||
this.canRotate = true;
|
||||
this.canvas.addEventListener('mousemove', this.mouseMoveCallback, false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop rotating on middle mouse button down
|
||||
* @param event
|
||||
*/
|
||||
R3.D3.Input.Fly.prototype.onMouseUp = function(event) {
|
||||
if (event.button == 1) {
|
||||
this.canRotate = false;
|
||||
this.canvas.removeEventListener('mousemove', this.mouseMoveCallback);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply current yaw and pitch to camera
|
||||
*/
|
||||
R3.D3.Input.Fly.prototype.applyRotation = function() {
|
||||
this.camera.rotation.set(this.pitch, this.yaw, 0, "YXZ");
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply current position to camera
|
||||
* @param deltaTime
|
||||
*/
|
||||
R3.D3.Input.Fly.prototype.applyTranslation = function(deltaTime) {
|
||||
var direction = new this.THREE.Vector3(0, 0, -1);
|
||||
var rotation = new this.THREE.Euler(0, 0, 0, "YXZ");
|
||||
rotation.set(this.pitch, this.yaw, 0, "YXZ");
|
||||
|
||||
direction = direction.applyEuler(rotation);
|
||||
|
||||
var forward = direction.normalize();
|
||||
var right = forward.cross(new this.THREE.Vector3(0, 1, 0));
|
||||
|
||||
if(this.moveForward) {
|
||||
|
||||
this.camera.position.x += forward.x * (deltaTime * this.flySpeed);
|
||||
this.camera.position.y += forward.y * (deltaTime * this.flySpeed);
|
||||
this.camera.position.z += forward.z * (deltaTime * this.flySpeed);
|
||||
|
||||
} else if(this.moveBackward) {
|
||||
|
||||
this.camera.position.x -= forward.x * (deltaTime * this.flySpeed);
|
||||
this.camera.position.y -= forward.y * (deltaTime * this.flySpeed);
|
||||
this.camera.position.z -= forward.z * (deltaTime * this.flySpeed);
|
||||
}
|
||||
|
||||
if(this.moveLeft) {
|
||||
|
||||
this.camera.position.x -= right.x * (deltaTime * this.flySpeed);
|
||||
this.camera.position.y -= right.y * (deltaTime * this.flySpeed);
|
||||
this.camera.position.z -= right.z * (deltaTime * this.flySpeed);
|
||||
|
||||
} else if(this.moveRight) {
|
||||
|
||||
this.camera.position.x += right.x * (deltaTime * this.flySpeed);
|
||||
this.camera.position.y += right.y * (deltaTime * this.flySpeed);
|
||||
this.camera.position.z += right.z * (deltaTime * this.flySpeed);
|
||||
}
|
||||
|
||||
if(this.moveUp) {
|
||||
|
||||
this.camera.position.y += (deltaTime * this.flySpeed);
|
||||
|
||||
} else if(this.moveDown) {
|
||||
|
||||
this.camera.position.y -= (deltaTime * this.flySpeed);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This update function should be called from the animation function in order to apply the 'frame rate independent'
|
||||
* movement to the camera
|
||||
* @param deltaTime
|
||||
*/
|
||||
R3.D3.Input.Fly.prototype.update = function(deltaTime) {
|
||||
this.applyRotation();
|
||||
this.applyTranslation(deltaTime);
|
||||
};
|
||||
|
||||
/**
|
||||
* Rotate on mouse move
|
||||
* @param event
|
||||
*/
|
||||
R3.D3.Input.Fly.prototype.onMouseMove = function ( event ) {
|
||||
if (this.canRotate) {
|
||||
var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
||||
var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
|
||||
|
||||
this.yaw -= movementX * 0.002;
|
||||
this.pitch -= movementY * 0.002;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Keyboard controls
|
||||
* @param event
|
||||
*/
|
||||
R3.D3.Input.Fly.prototype.onKeyDown = function ( event ) {
|
||||
switch ( event.keyCode ) {
|
||||
|
||||
case 87: // w
|
||||
this.moveForward = true;
|
||||
break;
|
||||
|
||||
case 65: // a
|
||||
this.moveLeft = true;
|
||||
break;
|
||||
|
||||
case 83: // s
|
||||
this.moveBackward = true;
|
||||
break;
|
||||
|
||||
case 68: // d
|
||||
this.moveRight = true;
|
||||
break;
|
||||
|
||||
case 104: // keypad up arrow
|
||||
this.moveUp = true;
|
||||
break;
|
||||
|
||||
case 98: // keypad down arrow
|
||||
this.moveDown = true;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Keyboard controls
|
||||
* @param event
|
||||
*/
|
||||
R3.D3.Input.Fly.prototype.onKeyUp = function ( event ) {
|
||||
switch ( event.keyCode ) {
|
||||
|
||||
case 38: // up
|
||||
case 87: // w
|
||||
this.moveForward = false;
|
||||
break;
|
||||
|
||||
case 37: // left
|
||||
case 65: // a
|
||||
this.moveLeft = false;
|
||||
break;
|
||||
|
||||
case 40: // down
|
||||
case 83: // s
|
||||
this.moveBackward = false;
|
||||
break;
|
||||
|
||||
case 39: // right
|
||||
case 68: // d
|
||||
this.moveRight = false;
|
||||
break;
|
||||
|
||||
case 104: // keypad up arrow
|
||||
this.moveUp = false;
|
||||
break;
|
||||
|
||||
case 98: // keypad down arrow
|
||||
this.moveDown = false;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
/**
|
||||
* Entities with LookAt component looks to targetPosition (default up is 0,1,0)
|
||||
* @param graphics R3.GraphicsRuntime
|
||||
* @param apiLookAt R3.D3.API.LookAt
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.LookAt = function (
|
||||
graphics,
|
||||
apiLookAt
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiLookAt)) {
|
||||
apiLookAt = {};
|
||||
}
|
||||
|
||||
if (apiLookAt instanceof R3.D3.LookAt) {
|
||||
return apiLookAt;
|
||||
}
|
||||
|
||||
R3.D3.API.LookAt.call(
|
||||
this,
|
||||
apiLookAt.id,
|
||||
apiLookAt.name,
|
||||
apiLookAt.currentComponent,
|
||||
apiLookAt.targetComponent,
|
||||
apiLookAt.targetPositionOffset,
|
||||
apiLookAt.rotationSpeed,
|
||||
apiLookAt.parentEntity
|
||||
);
|
||||
|
||||
this.targetPositionOffset = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.targetPositionOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.lookAtMatrix = new R3.Matrix4(
|
||||
this.graphics,
|
||||
this.lookAtMatrix,
|
||||
this
|
||||
);
|
||||
|
||||
this.up = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.up,
|
||||
this
|
||||
);
|
||||
|
||||
this.currentRotation = new R3.Quaternion(
|
||||
this.graphics,
|
||||
this.currentRotation,
|
||||
this
|
||||
);
|
||||
|
||||
this.targetPosition = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.targetPosition,
|
||||
this
|
||||
);
|
||||
|
||||
R3.Component.call(
|
||||
this,
|
||||
R3.Component.COMPONENT_LOOK_AT,
|
||||
{
|
||||
'currentComponent' : R3.Component,
|
||||
'targetComponent' : R3.Component
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.LookAt.prototype = Object.create(R3.D3.API.LookAt.prototype);
|
||||
R3.D3.LookAt.prototype.constructor = R3.D3.LookAt;
|
||||
|
||||
R3.D3.LookAt.prototype.createInstance = function() {
|
||||
this.instance = true;
|
||||
R3.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
R3.D3.LookAt.prototype.updateInstance = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* to API object
|
||||
* @returns {R3.D3.API.LookAt}
|
||||
*/
|
||||
R3.D3.LookAt.prototype.toApiObject = function() {
|
||||
|
||||
var apiLookAt = new R3.D3.API.LookAt(
|
||||
this.id,
|
||||
this.name,
|
||||
R3.Utils.IdOrNull(this.currentComponent),
|
||||
R3.Utils.IdOrNull(this.targetComponent),
|
||||
this.targetPositionOffset.toApiObject(),
|
||||
this.rotationSpeed,
|
||||
R3.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
return apiLookAt;
|
||||
};
|
||||
|
||||
R3.D3.LookAt.FromObject = function(graphics, objectComponent) {
|
||||
|
||||
var apiLookAt = R3.D3.API.LookAt.FromObject(objectComponent);
|
||||
|
||||
return new R3.D3.LookAt(
|
||||
graphics,
|
||||
apiLookAt
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Looks at using time
|
||||
* @param deltaTime
|
||||
*/
|
||||
R3.D3.LookAt.prototype.update = function(deltaTime) {
|
||||
|
||||
if (this.currentComponent && this.targetComponent) {
|
||||
|
||||
this.targetPosition.x = this.targetComponent.position.x + this.targetPositionOffset.x;
|
||||
this.targetPosition.y = this.targetComponent.position.y + this.targetPositionOffset.y;
|
||||
this.targetPosition.z = this.targetComponent.position.z + this.targetPositionOffset.z;
|
||||
|
||||
this.targetPosition.updateInstance();
|
||||
|
||||
// this.lookAtMatrix.lookAt(
|
||||
// this.currentComponent.position,
|
||||
// this.targetPosition,
|
||||
// this.up
|
||||
// );
|
||||
//
|
||||
// this.currentRotation = new R3.Quaternion(this.graphics, this, new R3.API.Quaternion());
|
||||
//
|
||||
// this.currentRotation.setFromRotationMatrix(this.lookAtMatrix);
|
||||
|
||||
// var t = deltaTime * this.rotationSpeed;
|
||||
// t = t * t * t * (t * (6.0 * t - 15.0) + 10.0);
|
||||
|
||||
// this.currentRotation.slerp(this.currentRotation, t);
|
||||
|
||||
// this.currentRotation.normalize();
|
||||
//
|
||||
// this.currentComponent.quaternion.x = this.currentRotation.x;
|
||||
// this.currentComponent.quaternion.y = this.currentRotation.y;
|
||||
// this.currentComponent.quaternion.z = this.currentRotation.z;
|
||||
// this.currentComponent.quaternion.w = this.currentRotation.w;
|
||||
//
|
||||
this.currentComponent.lookAt.x = this.targetPosition.x;
|
||||
this.currentComponent.lookAt.y = this.targetPosition.y;
|
||||
this.currentComponent.lookAt.z = this.targetPosition.z;
|
||||
|
||||
this.currentComponent.lookAt.updateInstance();
|
||||
}
|
||||
|
||||
};
|
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
* R3.D3.Mesh.Box
|
||||
* @param graphics R3.GraphicsRuntime
|
||||
* @param apiMeshBox
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Mesh.Box = function (
|
||||
graphics,
|
||||
apiMeshBox
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMeshBox)) {
|
||||
apiMeshBox = {
|
||||
meshType: R3.D3.API.Mesh.MESH_TYPE_BOX
|
||||
};
|
||||
}
|
||||
|
||||
R3.D3.API.Mesh.Box.call(
|
||||
this,
|
||||
apiMeshBox,
|
||||
apiMeshBox.width,
|
||||
apiMeshBox.height,
|
||||
apiMeshBox.depth
|
||||
);
|
||||
|
||||
R3.D3.Mesh.call(
|
||||
this,
|
||||
this.graphics,
|
||||
this
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Box.prototype = Object.create(R3.D3.Mesh.prototype);
|
||||
R3.D3.Mesh.Box.prototype.constructor = R3.D3.Mesh.Box;
|
||||
|
||||
R3.D3.Mesh.Box.prototype.createInstance = function() {
|
||||
|
||||
var geometry = null;
|
||||
|
||||
if (this.vertices.length === 0) {
|
||||
|
||||
geometry = new THREE.BoxGeometry(
|
||||
this.width,
|
||||
this.height,
|
||||
this.depth
|
||||
);
|
||||
|
||||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
}
|
||||
|
||||
R3.D3.Mesh.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Box.prototype.updateInstance = function(property) {
|
||||
|
||||
if (
|
||||
property === 'width' ||
|
||||
property === 'height' ||
|
||||
property === 'depth'
|
||||
) {
|
||||
var geometry = new THREE.BoxGeometry(
|
||||
this.width,
|
||||
this.height,
|
||||
this.depth
|
||||
);
|
||||
|
||||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
|
||||
geometry = this.createInstanceGeometry();
|
||||
|
||||
this.instance.geometry = geometry;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
R3.D3.Mesh.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a R3.D3.Mesh.Box to a R3.D3.API.Mesh.Box
|
||||
* @returns {R3.D3.API.Mesh.Box}
|
||||
*/
|
||||
R3.D3.Mesh.Box.prototype.toApiObject = function() {
|
||||
|
||||
var apiMesh = R3.D3.Mesh.prototype.toApiObject.call(this);
|
||||
|
||||
var apiMeshBox = new R3.D3.API.Mesh.Box(
|
||||
apiMesh,
|
||||
this.width,
|
||||
this.height,
|
||||
this.depth
|
||||
);
|
||||
|
||||
return apiMeshBox;
|
||||
};
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* R3.D3.Mesh.Curve
|
||||
* @param graphics R3.GraphicsRuntime
|
||||
* @param apiMeshCurve
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Mesh.Curve = function (
|
||||
graphics,
|
||||
apiMeshCurve
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMeshCurve)) {
|
||||
apiMeshCurve = {
|
||||
meshType: R3.D3.API.Mesh.MESH_TYPE_CURVE
|
||||
};
|
||||
}
|
||||
|
||||
R3.D3.API.Mesh.Curve.call(
|
||||
this,
|
||||
apiMeshCurve,
|
||||
apiMeshCurve.pointSize
|
||||
);
|
||||
|
||||
R3.D3.Mesh.call(
|
||||
this,
|
||||
this.graphics,
|
||||
this
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Curve.prototype = Object.create(R3.D3.Mesh.prototype);
|
||||
R3.D3.Mesh.Curve.prototype.constructor = R3.D3.Mesh.Curve;
|
||||
|
||||
|
||||
R3.D3.Mesh.Curve.prototype.createInstance = function() {
|
||||
|
||||
console.warn('todo: not fully implemented');
|
||||
|
||||
this.instance = true;
|
||||
|
||||
return;
|
||||
|
||||
// var geometry = new THREE.Geometry();
|
||||
//
|
||||
// /**
|
||||
// * Setup vertices
|
||||
// */
|
||||
// this.applyVertexDataToInstance(geometry);
|
||||
//
|
||||
// var instance = new THREE.Points(geometry);
|
||||
//
|
||||
// this.createInstanceDefaults(instance);
|
||||
//
|
||||
// return instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a R3.D3.Mesh.Curve to a R3.D3.API.Mesh.Curve
|
||||
* @returns {R3.D3.API.Mesh.Curve}
|
||||
*/
|
||||
R3.D3.Mesh.Curve.prototype.toApiObject = function() {
|
||||
|
||||
var apiMesh = R3.D3.Mesh.prototype.toApiObject.call(this);
|
||||
|
||||
var apiMeshCurve = new R3.D3.API.Mesh.Curve(
|
||||
apiMesh,
|
||||
this.pointSize
|
||||
);
|
||||
|
||||
return apiMeshCurve;
|
||||
};
|
|
@ -0,0 +1,146 @@
|
|||
/**
|
||||
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
|
||||
* @param graphics R3.GraphicsRuntime
|
||||
* @param apiMeshCylinder
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Mesh.Cylinder = function (
|
||||
graphics,
|
||||
apiMeshCylinder
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMeshCylinder)) {
|
||||
apiMeshCylinder = {
|
||||
meshType : R3.D3.API.Mesh.MESH_TYPE_CYLINDER
|
||||
};
|
||||
}
|
||||
|
||||
R3.D3.API.Mesh.Cylinder.call(
|
||||
this,
|
||||
apiMeshCylinder,
|
||||
apiMeshCylinder.radiusTop,
|
||||
apiMeshCylinder.radiusBottom,
|
||||
apiMeshCylinder.height,
|
||||
apiMeshCylinder.radiusSegments,
|
||||
apiMeshCylinder.heightSegments,
|
||||
apiMeshCylinder.openEnded,
|
||||
apiMeshCylinder.thetaStart,
|
||||
apiMeshCylinder.thetaLength
|
||||
);
|
||||
|
||||
R3.D3.Mesh.call(
|
||||
this,
|
||||
graphics,
|
||||
this
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Cylinder.prototype = Object.create(R3.D3.Mesh.prototype);
|
||||
R3.D3.Mesh.Cylinder.prototype.constructor = R3.D3.Mesh.Cylinder;
|
||||
|
||||
R3.D3.Mesh.Cylinder.prototype.createInstance = function() {
|
||||
|
||||
var geometry = null;
|
||||
|
||||
if (this.vertices.length === 0) {
|
||||
geometry = new THREE.CylinderGeometry(
|
||||
this.radiusTop,
|
||||
this.radiusBottom,
|
||||
this.height,
|
||||
this.radiusSegments,
|
||||
this.heightSegments,
|
||||
this.openEnded,
|
||||
this.thetaStart,
|
||||
this.thetaLength
|
||||
);
|
||||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
}
|
||||
|
||||
R3.D3.Mesh.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Cylinder.prototype.updateInstance = function(property) {
|
||||
|
||||
if (
|
||||
property === 'radiusTop' ||
|
||||
property === 'radiusBottom' ||
|
||||
property === 'height' ||
|
||||
property === 'radiusSegments' ||
|
||||
property === 'heightSegments' ||
|
||||
property === 'openEnded' ||
|
||||
property === 'thetaStart' ||
|
||||
property === 'thetaLength'
|
||||
) {
|
||||
var geometry = new THREE.CylinderGeometry(
|
||||
this.radiusTop,
|
||||
this.radiusBottom,
|
||||
this.height,
|
||||
this.radiusSegments,
|
||||
this.heightSegments,
|
||||
this.openEnded,
|
||||
this.thetaStart,
|
||||
this.thetaLength
|
||||
);
|
||||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
|
||||
geometry = this.createInstanceGeometry();
|
||||
|
||||
this.instance.geometry = geometry;
|
||||
}
|
||||
|
||||
R3.D3.Mesh.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a R3.D3.Mesh.Cylinder to a R3.D3.API.Mesh.Cylinder
|
||||
* @returns {R3.D3.API.Mesh.Cylinder}
|
||||
*/
|
||||
R3.D3.Mesh.Cylinder.prototype.toApiObject = function() {
|
||||
|
||||
var apiMesh = R3.D3.Mesh.prototype.toApiObject.call(this);
|
||||
|
||||
var apiMeshCylinder = new R3.D3.API.Mesh.Cylinder(
|
||||
apiMesh,
|
||||
this.radiusTop,
|
||||
this.radiusBottom,
|
||||
this.height,
|
||||
this.radiusSegments,
|
||||
this.heightSegments,
|
||||
this.openEnded,
|
||||
this.thetaStart,
|
||||
this.thetaLength
|
||||
);
|
||||
|
||||
return apiMeshCylinder;
|
||||
};
|
||||
|
||||
/**
|
||||
* This function turns the cylinder into a 'display' where each plane on the cylinder is mapped onto a flat texture
|
||||
*/
|
||||
R3.D3.Mesh.Cylinder.prototype.turnIntoDisplay = function() {
|
||||
|
||||
this.heightSegments = 1;
|
||||
this.updateInstance('heightSegments');
|
||||
|
||||
this.openEnded = true;
|
||||
this.updateInstance('openEnded');
|
||||
|
||||
this.materials.map(
|
||||
function(material){
|
||||
material.remove();
|
||||
}
|
||||
);
|
||||
|
||||
this.materials = [];
|
||||
|
||||
for (var i = 0; i < this.radiusSegments; i++) {
|
||||
this.materials.push(
|
||||
new R3.D3.Material(this.graphics)
|
||||
)
|
||||
}
|
||||
|
||||
this.updateInstance('materials');
|
||||
|
||||
};
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
|
||||
* @param graphics R3.GraphicsRuntime
|
||||
* @param apiMeshLine
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Mesh.Line = function (
|
||||
graphics,
|
||||
apiMeshLine
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMeshLine)) {
|
||||
apiMeshLine = {
|
||||
meshType: R3.D3.API.Mesh.MESH_TYPE_LINE
|
||||
};
|
||||
}
|
||||
|
||||
R3.D3.API.Mesh.Line.call(
|
||||
this,
|
||||
apiMeshLine,
|
||||
apiMeshLine.lineWidth
|
||||
);
|
||||
|
||||
R3.D3.Mesh.call(
|
||||
this,
|
||||
this.graphics,
|
||||
this
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Line.prototype = Object.create(R3.D3.Mesh.prototype);
|
||||
R3.D3.Mesh.Line.prototype.constructor = R3.D3.Mesh.Line;
|
||||
|
||||
R3.D3.Mesh.Line.prototype.createInstance = function() {
|
||||
|
||||
var geometry = new THREE.Geometry();
|
||||
|
||||
geometry.vertices.push(
|
||||
this.vertices.map(
|
||||
function(vertex){
|
||||
return vertex.instance;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
this.instance = new THREE.Line(geometry);
|
||||
|
||||
R3.D3.Mesh.prototype.createInstance.call(this);
|
||||
|
||||
this.instance.userData.lineWidth = this.lineWidth;
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Line.prototype.updateInstance = function(property) {
|
||||
|
||||
this.instance.linewidth = this.lineWidth;
|
||||
|
||||
R3.D3.Mesh.prototype.updateInstance.call(this, property);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a R3.D3.Mesh.Line to a R3.D3.API.Mesh.Line
|
||||
* @returns {R3.D3.API.Mesh.Line}
|
||||
*/
|
||||
R3.D3.Mesh.Line.prototype.toApiObject = function() {
|
||||
|
||||
var apiMesh = R3.D3.Mesh.prototype.toApiObject.call(this);
|
||||
|
||||
var apiMeshLine = new R3.D3.API.Mesh.Line(
|
||||
apiMesh,
|
||||
this.lineWidth
|
||||
);
|
||||
|
||||
return apiMeshLine;
|
||||
};
|
|
@ -0,0 +1,344 @@
|
|||
/**
|
||||
* Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created
|
||||
* @param graphics R3.GraphicsRuntime
|
||||
* @param apiMeshPlane
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Mesh.Plane = function (
|
||||
graphics,
|
||||
apiMeshPlane
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMeshPlane)) {
|
||||
apiMeshPlane = {
|
||||
meshType : R3.D3.API.Mesh.MESH_TYPE_PLANE
|
||||
};
|
||||
}
|
||||
|
||||
R3.D3.API.Mesh.Plane.call(
|
||||
this,
|
||||
apiMeshPlane,
|
||||
apiMeshPlane.width,
|
||||
apiMeshPlane.height,
|
||||
apiMeshPlane.widthSegments,
|
||||
apiMeshPlane.heightSegments,
|
||||
apiMeshPlane.heightMapScale,
|
||||
apiMeshPlane.isHeightMap,
|
||||
apiMeshPlane.isDotMap,
|
||||
apiMeshPlane.dotMapScale,
|
||||
apiMeshPlane.dotMapOffset,
|
||||
apiMeshPlane.dotMapWeight,
|
||||
apiMeshPlane.dotObject
|
||||
);
|
||||
|
||||
this.dotMapScale = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.dotMapScale,
|
||||
this
|
||||
);
|
||||
|
||||
this.dotMapOffset = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.dotMapOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.dotMapWeight = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.dotMapWeight,
|
||||
this
|
||||
);
|
||||
|
||||
this.dots = [];
|
||||
|
||||
R3.D3.Mesh.call(
|
||||
this,
|
||||
graphics,
|
||||
apiMeshPlane
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Plane.prototype = Object.create(R3.D3.Mesh.prototype);
|
||||
R3.D3.Mesh.Plane.prototype.constructor = R3.D3.Mesh.Plane;
|
||||
|
||||
R3.D3.Mesh.Plane.prototype.createInstance = function() {
|
||||
|
||||
var geometry = null;
|
||||
|
||||
/**
|
||||
* If this geometry is not coming from the database, apply the vertex data from the instance to our runtime object
|
||||
*/
|
||||
if (this.vertices.length === 0) {
|
||||
|
||||
geometry = new THREE.PlaneGeometry(
|
||||
this.width,
|
||||
this.height,
|
||||
this.widthSegments,
|
||||
this.heightSegments
|
||||
);
|
||||
|
||||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
|
||||
/**
|
||||
* If this is a heightmap - first generate the z-coordinates
|
||||
*/
|
||||
if (this.isHeightMap) {
|
||||
this.generateHeightMapFromBumpMap();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Now construct the mesh instance
|
||||
*/
|
||||
R3.D3.Mesh.prototype.createInstance.call(this);
|
||||
|
||||
if (this.isDotMap && this.dotObject) {
|
||||
this.generateDotMap();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
R3.D3.Mesh.Plane.prototype.updateInstance = function(property) {
|
||||
|
||||
var geometry = null;
|
||||
|
||||
if (
|
||||
property === 'width' ||
|
||||
property === 'height' ||
|
||||
property === 'widthSegments' ||
|
||||
property === 'heightSegments' ||
|
||||
property === 'isHeightMap' ||
|
||||
property === 'heightMapScale'
|
||||
) {
|
||||
|
||||
geometry = new THREE.PlaneGeometry(
|
||||
this.width,
|
||||
this.height,
|
||||
this.widthSegments,
|
||||
this.heightSegments
|
||||
);
|
||||
|
||||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
|
||||
if (this.isHeightMap) {
|
||||
this.generateHeightMapFromBumpMap();
|
||||
}
|
||||
|
||||
geometry = this.createInstanceGeometry();
|
||||
|
||||
this.instance.geometry = geometry;
|
||||
}
|
||||
|
||||
if (
|
||||
property === 'isDotMap' ||
|
||||
property === 'dotMapScale' ||
|
||||
property === 'dotMapOffset' ||
|
||||
property === 'dotMapWeight' ||
|
||||
property === 'dotObject'
|
||||
) {
|
||||
this.dots.map(
|
||||
function(dot){
|
||||
this.parentScene.instance.remove(dot);
|
||||
dot.geometry.dispose();
|
||||
dot.material.dispose();
|
||||
}.bind(this)
|
||||
);
|
||||
|
||||
if (this.isDotMap) {
|
||||
this.generateDotMap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
R3.D3.Mesh.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a R3.D3.Mesh.Plane to a R3.D3.API.Mesh.Plane
|
||||
* @returns {R3.D3.API.Mesh.Plane}
|
||||
*/
|
||||
R3.D3.Mesh.Plane.prototype.toApiObject = function() {
|
||||
|
||||
var apiMesh = R3.D3.Mesh.prototype.toApiObject.call(this);
|
||||
|
||||
var apiMeshPlane = new R3.D3.API.Mesh.Plane(
|
||||
apiMesh,
|
||||
this.width,
|
||||
this.height,
|
||||
this.widthSegments,
|
||||
this.heightSegments,
|
||||
this.heightMapScale,
|
||||
this.isHeightMap,
|
||||
this.isDotMap,
|
||||
this.dotMapScale.toApiObject(),
|
||||
this.dotMapOffset.toApiObject(),
|
||||
this.dotMapWeight.toApiObject(),
|
||||
R3.Utils.IdOrNull(this.dotObject)
|
||||
);
|
||||
|
||||
return apiMeshPlane;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
R3.D3.Mesh.Plane.prototype.generateDotMap = function() {
|
||||
|
||||
this.dots = [];
|
||||
|
||||
var data = this.getHeightData();
|
||||
|
||||
var width = Math.sqrt(data.length);
|
||||
var height = width;
|
||||
|
||||
for (var x = 0; x < width; x++) {
|
||||
for (var y = 0; y < height; y++ ) {
|
||||
|
||||
var z = data[(y * width) + x];
|
||||
|
||||
if (z < 0.1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var geometry;
|
||||
var material;
|
||||
|
||||
if (this.dotObject) {
|
||||
geometry = this.dotObject.instance.geometry.clone();
|
||||
material = this.dotObject.materials[0].instance;
|
||||
} else {
|
||||
geometry = new THREE.BoxBufferGeometry(0.5, 0.5, 0.5);
|
||||
material = this.materials[0].instance;
|
||||
}
|
||||
|
||||
var dot = new THREE.Mesh(geometry, material);
|
||||
dot.name = 'dot ' + this.dots.length;
|
||||
dot.position.x = x * this.dotMapWeight.x + this.dotMapOffset.x;
|
||||
dot.position.y = height - (y * this.dotMapWeight.y + this.dotMapOffset.y);
|
||||
dot.position.z = z * this.dotMapWeight.z + this.dotMapOffset.z;
|
||||
|
||||
dot.scale.x = z * this.dotMapScale.x + 0.00001;
|
||||
dot.scale.y = z * this.dotMapScale.y + 0.00001;
|
||||
dot.scale.z = z * this.dotMapScale.z + 0.00001;
|
||||
|
||||
this.parentScene.instance.add(dot);
|
||||
|
||||
this.dots.push(dot);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {THREE.PlaneGeometry}
|
||||
*/
|
||||
R3.D3.Mesh.Plane.prototype.generateHeightMapFromBumpMap = function() {
|
||||
|
||||
var data = this.getHeightData();
|
||||
|
||||
this.vertices.map(
|
||||
function(vertex, index) {
|
||||
vertex.position.z = data[index];
|
||||
}
|
||||
);
|
||||
|
||||
// var geometry = this.createInstanceGeometry();
|
||||
//
|
||||
// this.instance.geometry = geometry;
|
||||
|
||||
//
|
||||
// var vertices = this.instance.geometry.attributes.position.array;
|
||||
//
|
||||
// for ( var i = 0; i < vertices.length; i += 3 ) {
|
||||
// vertices[i+2] = data[i];
|
||||
// }
|
||||
//
|
||||
// this.instance.geometry.attributes.position.needsUpdate = true;
|
||||
|
||||
//this.updateVerticesFromGeometryInstance(this.instance.geometry);
|
||||
|
||||
// this.updateInstance();
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Plane.prototype.createPhysicsObjects = function() {
|
||||
|
||||
R3.Event.Emit(
|
||||
R3.Event.GET_PHYSICS_RUNTIME,
|
||||
null,
|
||||
function(physics){
|
||||
|
||||
/**
|
||||
* Create the plane shape
|
||||
* @type {R3.D3.API.Shape}
|
||||
*/
|
||||
var apiShapePlane = new R3.D3.API.Shape(
|
||||
null,
|
||||
'Shape Plane (' + this.name + ')'
|
||||
);
|
||||
|
||||
apiShapePlane.parentMesh = this;
|
||||
|
||||
var shapePlane = new R3.D3.Shape.Plane(
|
||||
physics,
|
||||
apiShapePlane
|
||||
);
|
||||
|
||||
var apiRigidBody = new R3.D3.API.RigidBody(
|
||||
null,
|
||||
'Rigid Body (' + this.name + ')',
|
||||
0,
|
||||
null,
|
||||
new R3.API.Vector3(
|
||||
this.position.x,
|
||||
this.position.y,
|
||||
this.position.z
|
||||
),
|
||||
new R3.API.Quaternion(
|
||||
this.quaternion.x,
|
||||
this.quaternion.y,
|
||||
this.quaternion.z,
|
||||
this.quaternion.w,
|
||||
new R3.API.Vector3(
|
||||
this.quaternion.axis.x,
|
||||
this.quaternion.axis.y,
|
||||
this.quaternion.axis.z
|
||||
),
|
||||
this.quaternion.angle
|
||||
)
|
||||
);
|
||||
|
||||
apiRigidBody.shapes.push(shapePlane);
|
||||
|
||||
apiRigidBody.parentMesh = this;
|
||||
|
||||
/**
|
||||
* Construct the rigid body
|
||||
* @type {R3.D3.RigidBody}
|
||||
*/
|
||||
var rigidBody = new R3.D3.RigidBody(
|
||||
physics,
|
||||
apiRigidBody
|
||||
);
|
||||
|
||||
if (this.parentEntity instanceof R3.Entity) {
|
||||
this.parentEntity.addComponent(shapePlane);
|
||||
this.parentEntity.addComponent(rigidBody);
|
||||
}
|
||||
|
||||
}.bind(this),
|
||||
function(error){
|
||||
console.log(error.message);
|
||||
throw new Error(error.message);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
};
|
|
@ -0,0 +1,184 @@
|
|||
/**
|
||||
* R3.D3.Mesh.Sphere
|
||||
* @param graphics R3.GraphicsRuntime
|
||||
* @param apiMeshSphere
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Mesh.Sphere = function (
|
||||
graphics,
|
||||
apiMeshSphere
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMeshSphere)) {
|
||||
apiMeshSphere = {
|
||||
meshType: R3.D3.API.Mesh.MESH_TYPE_SPHERE
|
||||
};
|
||||
}
|
||||
|
||||
R3.D3.API.Mesh.Sphere.call(
|
||||
this,
|
||||
apiMeshSphere,
|
||||
apiMeshSphere.radius,
|
||||
apiMeshSphere.widthSegments,
|
||||
apiMeshSphere.heightSegments
|
||||
);
|
||||
|
||||
R3.D3.Mesh.call(
|
||||
this,
|
||||
this.graphics,
|
||||
this
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Sphere.prototype = Object.create(R3.D3.Mesh.prototype);
|
||||
R3.D3.Mesh.Sphere.prototype.constructor = R3.D3.Mesh.Sphere;
|
||||
|
||||
R3.D3.Mesh.Sphere.prototype.createInstance = function() {
|
||||
|
||||
var geometry = null;
|
||||
|
||||
if (this.vertices.length === 0) {
|
||||
geometry = new THREE.SphereGeometry(
|
||||
this.radius,
|
||||
this.widthSegments,
|
||||
this.heightSegments
|
||||
);
|
||||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
}
|
||||
|
||||
R3.D3.Mesh.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Sphere.prototype.updateInstance = function(property) {
|
||||
|
||||
if (
|
||||
property === 'radius' ||
|
||||
property === 'widthSegments' ||
|
||||
property === 'heightSegments'
|
||||
) {
|
||||
|
||||
var geometry = new THREE.SphereGeometry(
|
||||
this.radius,
|
||||
this.widthSegments,
|
||||
this.heightSegments
|
||||
);
|
||||
|
||||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
|
||||
geometry = this.createInstanceGeometry();
|
||||
|
||||
this.instance.geometry = geometry;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
R3.D3.Mesh.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a R3.D3.Mesh.Sphere to a R3.D3.API.Mesh.Sphere
|
||||
* @returns {R3.D3.API.Mesh.Sphere}
|
||||
*/
|
||||
R3.D3.Mesh.Sphere.prototype.toApiObject = function() {
|
||||
|
||||
var apiMesh = R3.D3.Mesh.prototype.toApiObject.call(this);
|
||||
|
||||
var apiMeshSphere = new R3.D3.API.Mesh.Sphere(
|
||||
apiMesh,
|
||||
this.radius,
|
||||
this.widthSegments,
|
||||
this.heightSegments
|
||||
);
|
||||
|
||||
return apiMeshSphere;
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Sphere.prototype.createPhysicsObjects = function() {
|
||||
|
||||
R3.Event.Emit(
|
||||
R3.Event.GET_PHYSICS_RUNTIME,
|
||||
null,
|
||||
function(physics){
|
||||
var apiShapeSphere = new R3.D3.API.Shape(
|
||||
null,
|
||||
'Sphere Shape (' + this.name + ')'
|
||||
);
|
||||
|
||||
apiShapeSphere.parentMesh = this;
|
||||
|
||||
var shapeSphere = new R3.D3.Shape.Sphere(
|
||||
physics,
|
||||
apiShapeSphere,
|
||||
this.radius
|
||||
);
|
||||
|
||||
var apiRigidBody = new R3.D3.API.RigidBody(
|
||||
null,
|
||||
'Rigid Body (' + this.name + ')',
|
||||
1,
|
||||
null,
|
||||
new R3.API.Vector3(
|
||||
this.position.x,
|
||||
this.position.y,
|
||||
this.position.z
|
||||
),
|
||||
new R3.API.Quaternion(
|
||||
this.quaternion.x,
|
||||
this.quaternion.y,
|
||||
this.quaternion.z,
|
||||
this.quaternion.w,
|
||||
new R3.API.Vector3(
|
||||
this.quaternion.axis.x,
|
||||
this.quaternion.axis.y,
|
||||
this.quaternion.axis.z
|
||||
),
|
||||
this.quaternion.angle
|
||||
)
|
||||
);
|
||||
|
||||
apiRigidBody.parentMesh = this;
|
||||
|
||||
apiRigidBody.shapes.push(shapeSphere);
|
||||
|
||||
var rigidBody = new R3.D3.RigidBody(
|
||||
physics,
|
||||
apiRigidBody
|
||||
);
|
||||
|
||||
if (this.parentEntity instanceof R3.Entity) {
|
||||
this.parentEntity.addComponent(shapeSphere);
|
||||
this.parentEntity.addComponent(rigidBody);
|
||||
}
|
||||
|
||||
}.bind(this),
|
||||
function(error){
|
||||
console.log(error.message);
|
||||
throw new Error(error.message);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a standard object mesh to a R3.D3.Mesh
|
||||
* @param graphics R3.GraphicsRuntime
|
||||
* @param objectMesh {Object}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Mesh.Sphere.FromObject = function(graphics, objectMesh) {
|
||||
|
||||
var apiMesh = R3.D3.API.Mesh.FromObject(objectMesh);
|
||||
|
||||
return new R3.D3.Mesh.Sphere(
|
||||
graphics,
|
||||
apiMesh,
|
||||
objectMesh.radius,
|
||||
objectMesh.widthSegments,
|
||||
objectMesh.heightSegments
|
||||
);
|
||||
|
||||
};
|
|
@ -0,0 +1,140 @@
|
|||
/**
|
||||
* R3.D3.Mesh.Text
|
||||
* @param graphics R3.GraphicsRuntime
|
||||
* @param apiMeshText
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Mesh.Text = function (
|
||||
graphics,
|
||||
apiMeshText
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiMeshText)) {
|
||||
apiMeshText = {
|
||||
meshType : R3.D3.API.Mesh.MESH_TYPE_TEXT
|
||||
};
|
||||
}
|
||||
|
||||
R3.D3.API.Mesh.Text.call(
|
||||
this,
|
||||
apiMeshText,
|
||||
apiMeshText.text,
|
||||
apiMeshText.font,
|
||||
apiMeshText.size,
|
||||
apiMeshText.height,
|
||||
apiMeshText.curveSegments,
|
||||
apiMeshText.bevelEnabled,
|
||||
apiMeshText.bevelThickness,
|
||||
apiMeshText.bevelSize,
|
||||
apiMeshText.bevelSegments
|
||||
);
|
||||
|
||||
if (this.font instanceof R3.D3.API.Font) {
|
||||
this.font = new R3.D3.Font(
|
||||
this.graphics,
|
||||
this.font
|
||||
)
|
||||
}
|
||||
|
||||
R3.D3.Mesh.call(
|
||||
this,
|
||||
this.graphics,
|
||||
this
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Text.prototype = Object.create(R3.D3.Mesh.prototype);
|
||||
R3.D3.Mesh.Text.prototype.constructor = R3.D3.Mesh.Text;
|
||||
|
||||
R3.D3.Mesh.Text.prototype.createInstance = function() {
|
||||
|
||||
var geometry = null;
|
||||
|
||||
if (this.vertices.length === 0) {
|
||||
|
||||
geometry = new THREE.TextGeometry(
|
||||
this.text,
|
||||
{
|
||||
font: this.font.instance,
|
||||
size: this.size,
|
||||
height: this.height,
|
||||
curveSegments: this.curveSegments,
|
||||
bevelEnabled: this.bevelEnabled,
|
||||
bevelThickness: this.bevelThickness,
|
||||
bevelSize: this.bevelSize,
|
||||
bevelSegments: this.bevelSegments
|
||||
}
|
||||
);
|
||||
|
||||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
}
|
||||
|
||||
R3.D3.Mesh.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
R3.D3.Mesh.Text.prototype.updateInstance = function(property) {
|
||||
|
||||
if (
|
||||
property === 'text' ||
|
||||
property === 'font' ||
|
||||
property === 'size' ||
|
||||
property === 'height' ||
|
||||
property === 'curveSegments' ||
|
||||
property === 'bevelEnabled' ||
|
||||
property === 'bevelThickness' ||
|
||||
property === 'bevelSize' ||
|
||||
property === 'bevelSegments'
|
||||
) {
|
||||
|
||||
var geometry = new THREE.TextGeometry(
|
||||
this.text,
|
||||
{
|
||||
font: this.font.instance,
|
||||
size: this.size,
|
||||
height: this.height,
|
||||
curveSegments: this.curveSegments,
|
||||
bevelEnabled: this.bevelEnabled,
|
||||
bevelThickness: this.bevelThickness,
|
||||
bevelSize: this.bevelSize,
|
||||
bevelSegments: this.bevelSegments
|
||||
}
|
||||
);
|
||||
|
||||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
|
||||
geometry = this.createInstanceGeometry();
|
||||
|
||||
this.instance.geometry = geometry;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
R3.D3.Mesh.prototype.updateInstance.call(this, property);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a R3.D3.Mesh.Text to a R3.D3.API.Mesh.Text
|
||||
* @returns {R3.D3.API.Mesh.Text}
|
||||
*/
|
||||
R3.D3.Mesh.Text.prototype.toApiObject = function() {
|
||||
|
||||
var apiMesh = R3.D3.Mesh.prototype.toApiObject.call(this);
|
||||
|
||||
var apiMeshText = new R3.D3.API.Mesh.Text(
|
||||
apiMesh,
|
||||
this.text,
|
||||
this.font,
|
||||
this.size,
|
||||
this.height,
|
||||
this.curveSegments,
|
||||
this.bevelEnabled,
|
||||
this.bevelThickness,
|
||||
this.bevelSize,
|
||||
this.bevelSegments
|
||||
);
|
||||
|
||||
return apiMeshText;
|
||||
};
|
|
@ -0,0 +1,257 @@
|
|||
/**
|
||||
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||
* @param graphics R3.GraphicsRuntime
|
||||
* @param apiPathFollowing R3.D3.API.PathFollowing
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.PathFollowing = function (
|
||||
graphics,
|
||||
apiPathFollowing
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiPathFollowing)) {
|
||||
apiPathFollowing = {};
|
||||
}
|
||||
|
||||
if (apiPathFollowing instanceof R3.D3.PathFollowing) {
|
||||
return apiPathFollowing;
|
||||
}
|
||||
|
||||
R3.D3.API.PathFollowing.call(
|
||||
this,
|
||||
apiPathFollowing.id,
|
||||
apiPathFollowing.name,
|
||||
apiPathFollowing.spline,
|
||||
apiPathFollowing.mesh,
|
||||
apiPathFollowing.raytraceMesh,
|
||||
apiPathFollowing.accelleration,
|
||||
apiPathFollowing.maxSpeed,
|
||||
apiPathFollowing.baseOffset,
|
||||
apiPathFollowing.maxOffset,
|
||||
apiPathFollowing.steeringSpeed,
|
||||
apiPathFollowing.targetOffset,
|
||||
apiPathFollowing.currentOffset,
|
||||
apiPathFollowing.currentPathValue,
|
||||
apiPathFollowing.currentSpeed,
|
||||
apiPathFollowing.direction,
|
||||
apiPathFollowing.raycaster,
|
||||
apiPathFollowing.currentPosition,
|
||||
apiPathFollowing.futurePosition,
|
||||
apiPathFollowing.up,
|
||||
apiPathFollowing.rotationMatrix,
|
||||
apiPathFollowing.rotationVector,
|
||||
apiPathFollowing.parentEntity
|
||||
);
|
||||
|
||||
this.baseOffset = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.baseOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.maxOffset = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.maxOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.targetOffset = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.targetOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.currentOffset = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.currentOffset,
|
||||
this
|
||||
);
|
||||
|
||||
this.raycaster = new R3.D3.Raycaster(
|
||||
this.graphics,
|
||||
this.raycaster
|
||||
);
|
||||
|
||||
this.currentPosition = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.currentPosition,
|
||||
this
|
||||
);
|
||||
|
||||
this.futurePosition = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.futurePosition,
|
||||
this
|
||||
);
|
||||
|
||||
this.up = new R3.Vector3(
|
||||
this.graphics,
|
||||
this.up,
|
||||
this
|
||||
);
|
||||
|
||||
this.rotationMatrix = new R3.Matrix4(
|
||||
this.graphics,
|
||||
this.rotationMatrix,
|
||||
this
|
||||
);
|
||||
|
||||
this.rotationVector = new R3.Quaternion(
|
||||
this.graphics,
|
||||
this.rotationVector,
|
||||
this
|
||||
);
|
||||
|
||||
this.mx = new R3.Utils.MovingAverage(10);
|
||||
this.my = new R3.Utils.MovingAverage(10);
|
||||
this.mz = new R3.Utils.MovingAverage(10);
|
||||
|
||||
R3.Component.call(
|
||||
this,
|
||||
R3.Component.COMPONENT_PATH_FOLLOWING,
|
||||
{
|
||||
'spline': R3.D3.Spline,
|
||||
'mesh' : R3.D3.Mesh,
|
||||
'raytraceMesh' : R3.D3.Mesh
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
R3.D3.PathFollowing.prototype = Object.create(R3.D3.API.PathFollowing.prototype);
|
||||
R3.D3.PathFollowing.prototype.constructor = R3.D3.PathFollowing;
|
||||
|
||||
R3.D3.PathFollowing.prototype.createInstance = function() {
|
||||
|
||||
console.log('R3.D3.PathFollowing.prototype.createInstance()');
|
||||
|
||||
R3.Component.prototype.createInstance.call(this);
|
||||
|
||||
};
|
||||
|
||||
R3.D3.PathFollowing.prototype.toApiObject = function() {
|
||||
|
||||
var apiPathFollowing = new R3.D3.API.PathFollowing(
|
||||
this.id,
|
||||
this.name,
|
||||
R3.Utils.IdOrNull(this.spline),
|
||||
R3.Utils.IdOrNull(this.mesh),
|
||||
R3.Utils.IdOrNull(this.raytraceMesh),
|
||||
this.accelleration,
|
||||
this.maxSpeed,
|
||||
this.baseOffset.toApiObject(),
|
||||
this.maxOffset.toApiObject(),
|
||||
this.steeringSpeed,
|
||||
this.targetOffset.toApiObject(),
|
||||
this.currentOffset.toApiObject(),
|
||||
this.currentPathValue,
|
||||
this.currentSpeed,
|
||||
this.direction,
|
||||
this.raycaster.toApiObject(),
|
||||
this.currentPosition.toApiObject(),
|
||||
this.futurePosition.toApiObject(),
|
||||
this.up.toApiObject(),
|
||||
this.rotationMatrix.toApiObject(),
|
||||
this.rotationVector.toApiObject(),
|
||||
R3.Utils.IdOrNull(this.parentEntity)
|
||||
);
|
||||
|
||||
return apiPathFollowing;
|
||||
};
|
||||
|
||||
/**
|
||||
* Object path following to R3.D3.PathFollowing
|
||||
* @param graphics
|
||||
* @param objectComponent
|
||||
* @returns {R3.D3.PathFollowing}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.PathFollowing.FromObject = function(graphics, objectComponent) {
|
||||
|
||||
var apiPathFollowing = R3.D3.API.PathFollowing.FromObject(objectComponent);
|
||||
|
||||
return new R3.D3.PathFollowing(
|
||||
graphics,
|
||||
apiPathFollowing
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the component
|
||||
* @param deltaTime
|
||||
*/
|
||||
R3.D3.PathFollowing.prototype.update = function(deltaTime) {
|
||||
|
||||
if (this.spline && this.mesh && this.raytraceMesh) {
|
||||
|
||||
this.currentSpeed += this.accelleration * deltaTime * this.direction;
|
||||
if(this.currentSpeed > this.maxSpeed) {
|
||||
this.currentSpeed = this.maxSpeed;
|
||||
}
|
||||
this.grain = (this.currentSpeed / 100.0);
|
||||
|
||||
var currentPosition = this.spline.getPointAt(this.currentPathValue);
|
||||
|
||||
this.currentPosition.x = currentPosition.x;
|
||||
this.currentPosition.y = currentPosition.y;
|
||||
this.currentPosition.z = currentPosition.z;
|
||||
|
||||
this.currentPathValue += this.grain;
|
||||
|
||||
if (this.currentPathValue >= 1) {
|
||||
this.currentPathValue = this.currentPathValue - 1;
|
||||
}
|
||||
|
||||
if (this.currentPathValue < 0) {
|
||||
this.currentPathValue = 0.0;
|
||||
}
|
||||
|
||||
var futurePosition = this.spline.getPointAt(this.currentPathValue);
|
||||
|
||||
this.futurePosition.x = futurePosition.x;
|
||||
this.futurePosition.y = futurePosition.y;
|
||||
this.futurePosition.z = futurePosition.z;
|
||||
|
||||
this.raycaster.setPosition(
|
||||
this.currentPosition
|
||||
);
|
||||
|
||||
this.raycaster.setDirection(
|
||||
{
|
||||
x : -this.up.x,
|
||||
y : -this.up.y,
|
||||
z : -this.up.z
|
||||
}
|
||||
);
|
||||
|
||||
var normal = this.raycaster.getFaceNormal(this.raytraceMesh);
|
||||
|
||||
if (normal) {
|
||||
this.up.x = this.mx(normal.x);
|
||||
this.up.y = this.my(normal.y);
|
||||
this.up.z = this.mz(normal.z);
|
||||
}
|
||||
|
||||
this.rotationMatrix.lookAt(
|
||||
this.currentPosition,
|
||||
this.futurePosition,
|
||||
this.up
|
||||
);
|
||||
|
||||
this.rotationVector.setFromRotationMatrix(this.rotationMatrix);
|
||||
|
||||
this.mesh.position.x = this.futurePosition.x;
|
||||
this.mesh.position.y = this.futurePosition.y;
|
||||
this.mesh.position.z = this.futurePosition.z;
|
||||
|
||||
/**
|
||||
* Update Rotation
|
||||
*/
|
||||
this.mesh.quaternion.x = this.rotationVector.x;
|
||||
this.mesh.quaternion.y = this.rotationVector.y;
|
||||
this.mesh.quaternion.z = this.rotationVector.z;
|
||||
this.mesh.quaternion.w = this.rotationVector.w;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Physics SuperSet Namespace Object
|
||||
* @param id
|
||||
* @param name
|
||||
* @param engine R3.D3.Engine
|
||||
* @param worlds
|
||||
* @returns {{World: World}}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Physics = function(
|
||||
id,
|
||||
name,
|
||||
engine,
|
||||
worlds
|
||||
) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.engine = engine;
|
||||
|
||||
if (typeof worlds == 'undefined') {
|
||||
worlds = [];
|
||||
}
|
||||
this.worlds = worlds;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Solver Types
|
||||
* @type {number}
|
||||
*/
|
||||
R3.D3.Physics.SPLIT_SOLVER = 0x1;
|
||||
R3.D3.Physics.GS_SOLVER = 0x2;
|
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* Raycast Vehicles :)
|
||||
* @param engine R3.D3.Engine
|
||||
* @param chassisBody R3.D3.RigidBody
|
||||
* @param wheels R3.D3.RaycastWheel[]
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.RaycastVehicle = function(
|
||||
engine,
|
||||
chassisBody,
|
||||
wheels,
|
||||
wheelBodies
|
||||
) {
|
||||
this.engine = engine;
|
||||
this.engine.isNotCannonThrow();
|
||||
|
||||
this.id = R3.Utils.RandomId();
|
||||
|
||||
this.chassisBody = chassisBody;
|
||||
|
||||
if (typeof wheels == 'undefined') {
|
||||
wheels = [];
|
||||
}
|
||||
this.wheels = wheels;
|
||||
|
||||
if(R3.Utils.UndefinedOrNull(wheelBodies)) {
|
||||
wheelBodies = [];
|
||||
}
|
||||
this.wheelBodies = wheelBodies;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
|
||||
R3.Utils.Extend(R3.D3.RaycastVehicle, R3.Component);
|
||||
};
|
||||
|
||||
/**
|
||||
* private
|
||||
* @returns {R3.D3.RaycastVehicle|R3.D3.Physics.RaycastVehicle|*}
|
||||
*/
|
||||
R3.D3.RaycastVehicle.prototype.createInstance = function() {
|
||||
return new this.engine.instance.RaycastVehicle({
|
||||
chassisBody: this.chassisBody.instance
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a raycast wheel to this vehicle
|
||||
* @param wheel R3.D3.RaycastWheel
|
||||
* @param wheelRigidBody R3.D3.RigidBody
|
||||
*/
|
||||
R3.D3.RaycastVehicle.prototype.addWheel = function (
|
||||
wheel,
|
||||
wheelRigidBody
|
||||
) {
|
||||
this.wheels.push(wheel);
|
||||
this.wheelBodies.push(wheelRigidBody);
|
||||
wheel.wheelIndex = this.instance.addWheel(wheel.instance);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns updated wheel info
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.RaycastVehicle.prototype.getWheelInfo = function() {
|
||||
return this.instance.wheelInfos;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Override component methods //
|
||||
R3.D3.RaycastVehicle.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
for (var i = 0; i < this.getWheelInfo().length; i++) {
|
||||
this.instance.updateWheelTransform(i);
|
||||
var t = this.getWheelInfo()[i].worldTransform;
|
||||
var wheelBody = this.wheelBodies[i].instance;
|
||||
wheelBody.position.copy(t.position);
|
||||
wheelBody.quaternion.copy(t.quaternion);
|
||||
}
|
||||
};
|
||||
|
||||
R3.D3.RaycastVehicle.prototype.onRegistered = function(
|
||||
parentScene
|
||||
) {
|
||||
|
||||
};
|
|
@ -0,0 +1,201 @@
|
|||
R3.D3.RaycastWheel = function(
|
||||
engine,
|
||||
chassisConnectionPointLocal,
|
||||
chassisConnectionPointWorld,
|
||||
directionLocal,
|
||||
directionWorld,
|
||||
axleLocal,
|
||||
axleWorld,
|
||||
suspensionRestLength,
|
||||
suspensionMaxLength,
|
||||
radius,
|
||||
suspensionStiffness,
|
||||
dampingCompression,
|
||||
dampingRelaxation,
|
||||
frictionSlip,
|
||||
steering,
|
||||
rotation,
|
||||
deltaRotation,
|
||||
rollInfluence,
|
||||
maxSuspensionForce,
|
||||
clippedInvContactDotSuspension,
|
||||
suspensionRelativeVelocity,
|
||||
suspensionForce,
|
||||
skidInfo,
|
||||
suspensionLength,
|
||||
maxSuspensionTravel,
|
||||
useCustomSlidingRotationalSpeed,
|
||||
customSlidingRotationalSpeed
|
||||
) {
|
||||
this.engine = engine;
|
||||
this.engine.isNotCannonThrow();
|
||||
|
||||
this.id = R3.Utils.RandomId();
|
||||
|
||||
if(typeof chassisConnectionPointLocal == 'undefined' || chassisConnectionPointLocal == null) {
|
||||
chassisConnectionPointLocal = new this.engine.instance.Vec3();
|
||||
}
|
||||
this.chassisConnectionPointLocal = chassisConnectionPointLocal;
|
||||
|
||||
if(typeof chassisConnectionPointWorld == 'undefined' || chassisConnectionPointWorld == null) {
|
||||
chassisConnectionPointWorld = new this.engine.instance.Vec3();
|
||||
}
|
||||
this.chassisConnectionPointWorld = chassisConnectionPointWorld;
|
||||
|
||||
if(typeof directionLocal == 'undefined' || directionLocal == null) {
|
||||
directionLocal = new this.engine.instance.Vec3();
|
||||
}
|
||||
this.directionLocal = directionLocal;
|
||||
|
||||
if(typeof directionWorld == 'undefined' || directionWorld == null) {
|
||||
directionWorld = new this.engine.instance.Vec3();
|
||||
}
|
||||
this.directionWorld = directionWorld;
|
||||
|
||||
if(typeof axleLocal == 'undefined' || axleLocal == null) {
|
||||
axleLocal = new this.engine.instance.Vec3();
|
||||
}
|
||||
this.axleLocal = axleLocal;
|
||||
|
||||
if(typeof axleWorld == 'undefined' || axleWorld == null) {
|
||||
axleWorld = new this.engine.instance.Vec3();
|
||||
}
|
||||
this.axleWorld = axleWorld;
|
||||
|
||||
if(typeof suspensionRestLength == 'undefined' || suspensionRestLength == null) {
|
||||
suspensionRestLength = 1;
|
||||
}
|
||||
this.suspensionRestLength = suspensionRestLength;
|
||||
|
||||
if(typeof suspensionMaxLength == 'undefined' || suspensionMaxLength == null) {
|
||||
suspensionMaxLength = 2;
|
||||
}
|
||||
this.suspensionMaxLength = suspensionMaxLength;
|
||||
|
||||
if(typeof radius == 'undefined' || radius == null) {
|
||||
radius = 1;
|
||||
}
|
||||
this.radius = radius;
|
||||
|
||||
if(typeof suspensionStiffness == 'undefined' || suspensionStiffness == null) {
|
||||
suspensionStiffness = 100;
|
||||
}
|
||||
this.suspensionStiffness = suspensionStiffness;
|
||||
|
||||
if(typeof dampingCompression == 'undefined' || dampingCompression == null) {
|
||||
dampingCompression = 10;
|
||||
}
|
||||
this.dampingCompression = dampingCompression;
|
||||
|
||||
if(typeof dampingRelaxation == 'undefined' || dampingRelaxation == null) {
|
||||
dampingRelaxation = 10;
|
||||
}
|
||||
this.dampingRelaxation = dampingRelaxation;
|
||||
|
||||
if(typeof frictionSlip == 'undefined' || frictionSlip == null) {
|
||||
frictionSlip = 10000;
|
||||
}
|
||||
this.frictionSlip = frictionSlip;
|
||||
|
||||
if(typeof steering == 'undefined' || steering == null) {
|
||||
steering = 0;
|
||||
}
|
||||
this.steering = steering;
|
||||
|
||||
if(typeof rotation == 'undefined' || rotation == null) {
|
||||
rotation = 0;
|
||||
}
|
||||
this.rotation = rotation;
|
||||
|
||||
if(typeof deltaRotation == 'undefined' || deltaRotation == null) {
|
||||
deltaRotation = 0;
|
||||
}
|
||||
this.deltaRotation = deltaRotation;
|
||||
|
||||
if(typeof rollInfluence == 'undefined' || rollInfluence == null) {
|
||||
rollInfluence = 0.01;
|
||||
}
|
||||
this.rollInfluence = rollInfluence;
|
||||
|
||||
if(typeof maxSuspensionForce == 'undefined' || maxSuspensionForce == null) {
|
||||
maxSuspensionForce = Number.MAX_VALUE;
|
||||
}
|
||||
this.maxSuspensionForce = maxSuspensionForce;
|
||||
|
||||
if(typeof clippedInvContactDotSuspension == 'undefined' || clippedInvContactDotSuspension == null) {
|
||||
clippedInvContactDotSuspension = 1;
|
||||
}
|
||||
this.clippedInvContactDotSuspension = clippedInvContactDotSuspension;
|
||||
|
||||
if(typeof suspensionRelativeVelocity == 'undefined' || suspensionRelativeVelocity == null) {
|
||||
suspensionRelativeVelocity = 0;
|
||||
}
|
||||
this.suspensionRelativeVelocity = suspensionRelativeVelocity;
|
||||
|
||||
if(typeof suspensionForce == 'undefined' || suspensionForce == null) {
|
||||
suspensionForce = 0;
|
||||
}
|
||||
this.suspensionForce = suspensionForce;
|
||||
|
||||
if(typeof skidInfo == 'undefined' || skidInfo == null) {
|
||||
skidInfo = 0;
|
||||
}
|
||||
this.skidInfo = skidInfo;
|
||||
|
||||
if(typeof suspensionLength == 'undefined' || suspensionLength == null) {
|
||||
suspensionLength = 0;
|
||||
}
|
||||
this.suspensionLength = suspensionLength;
|
||||
|
||||
if(typeof maxSuspensionTravel == 'undefined' || maxSuspensionTravel == null) {
|
||||
maxSuspensionTravel = 1;
|
||||
}
|
||||
this.maxSuspensionTravel = maxSuspensionTravel;
|
||||
|
||||
if(typeof useCustomSlidingRotationalSpeed == 'undefined' || useCustomSlidingRotationalSpeed == null) {
|
||||
useCustomSlidingRotationalSpeed = false;
|
||||
}
|
||||
this.useCustomSlidingRotationalSpeed = useCustomSlidingRotationalSpeed;
|
||||
|
||||
if(typeof customSlidingRotationalSpeed == 'undefined' || customSlidingRotationalSpeed == null) {
|
||||
customSlidingRotationalSpeed = -0.1;
|
||||
}
|
||||
this.customSlidingRotationalSpeed = customSlidingRotationalSpeed;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
|
||||
// this gets assigned at runtime, when the wheel gets added to a vehicle
|
||||
this.wheelIndex = -1;
|
||||
};
|
||||
|
||||
R3.D3.RaycastWheel.prototype.createInstance = function() {
|
||||
return {
|
||||
chassisConnectionPointLocal : this.chassisConnectionPointLocal,
|
||||
chassisConnectionPointWorld : this.chassisConnectionPointWorld,
|
||||
directionLocal : this.directionLocal,
|
||||
directionWorld : this.directionWorld,
|
||||
axleLocal : this.axleLocal,
|
||||
axleWorld : this.axleWorld,
|
||||
suspensionRestLength : this.suspensionRestLength,
|
||||
suspensionMaxLength : this.suspensionMaxLength,
|
||||
radius : this.radius,
|
||||
suspensionStiffness : this.suspensionStiffness,
|
||||
dampingCompression : this.dampingCompression,
|
||||
dampingRelaxation : this.dampingRelaxation,
|
||||
frictionSlip : this.frictionSlip,
|
||||
steering : this.steering,
|
||||
rotation : this.rotation,
|
||||
deltaRotation : this.deltaRotation,
|
||||
rollInfluence : this.rollInfluence,
|
||||
maxSuspensionForce : this.maxSuspensionForce,
|
||||
clippedInvContactDotSuspension : this.clippedInvContactDotSuspension,
|
||||
suspensionRelativeVelocity : this.suspensionRelativeVelocity,
|
||||
suspensionForce : this.suspensionForce,
|
||||
skidInfo : this.skidInfo,
|
||||
suspensionLength : this.suspensionLength,
|
||||
maxSuspensionTravel : this.maxSuspensionTravel,
|
||||
useCustomSlidingRotationalSpeed : this.useCustomSlidingRotationalSpeed,
|
||||
customSlidingRotationalSpeed : this.customSlidingRotationalSpeed
|
||||
};
|
||||
|
||||
};
|
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* Physics Rigid Body Vehicle Superset
|
||||
* @param engine R3.D3.Engine
|
||||
* @param chassisBody R3.D3.RigidBody
|
||||
* @param wheels R3.D3.RigidWheel[]
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.RigidBodyVehicle = function(
|
||||
engine,
|
||||
chassisBody,
|
||||
wheels
|
||||
) {
|
||||
this.id = R3.Utils.RandomId();
|
||||
this.engine = engine;
|
||||
this.engine.isNotCannonThrow();
|
||||
|
||||
this.chassisBody = chassisBody;
|
||||
|
||||
if (typeof wheels == 'undefined') {
|
||||
wheels = [];
|
||||
}
|
||||
this.wheels = wheels;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns physics wheelbody info (for updates)
|
||||
* @returns {Array}
|
||||
*/
|
||||
R3.D3.RigidBodyVehicle.prototype.getWheelInfo = function() {
|
||||
return this.instance.wheelBodies;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {R3.D3.RigidVehicle}
|
||||
*/
|
||||
R3.D3.RigidBodyVehicle.prototype.createInstance = function() {
|
||||
return new this.engine.instance.RigidVehicle({
|
||||
chassisBody: this.chassisBody.instance
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a wheel to this rigid body vehicle
|
||||
* @param wheel R3.D3.RigidWheel
|
||||
*/
|
||||
R3.D3.RigidBodyVehicle.prototype.addWheel = function(wheel) {
|
||||
|
||||
this.wheels.push(wheel);
|
||||
|
||||
this.instance.addWheel({
|
||||
body: wheel.body.instance,
|
||||
position: new this.engine.instance.Vec3(
|
||||
wheel.position.x,
|
||||
wheel.position.y,
|
||||
wheel.position.z
|
||||
),
|
||||
axis: new this.engine.instance.Vec3(
|
||||
wheel.axis.x,
|
||||
wheel.axis.y,
|
||||
wheel.axis.z
|
||||
),
|
||||
direction: new this.engine.instance.Vec3(
|
||||
wheel.direction.x,
|
||||
wheel.direction.y,
|
||||
wheel.direction.z
|
||||
)
|
||||
});
|
||||
|
||||
};
|
|
@ -0,0 +1,195 @@
|
|||
/**
|
||||
* RigidBody Superset
|
||||
* @param engine R3.D3.Engine
|
||||
* @param mass
|
||||
* @param friction
|
||||
* @param position
|
||||
* @param quaternion
|
||||
* @param velocity
|
||||
* @param angularVelocity
|
||||
* @param linearDamping
|
||||
* @param angularDamping
|
||||
* @param allowSleep
|
||||
* @param sleepSpeedLimit
|
||||
* @param sleepTimeLimit
|
||||
* @param collisionFilterGroup
|
||||
* @param collisionFilterMask
|
||||
* @param fixedRotation
|
||||
* @param shape R3.D3.Shape
|
||||
* @param kinematic Boolean
|
||||
* @returns {R3.D3.Physics.RigidBody}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.RigidBody = function(
|
||||
engine,
|
||||
mass,
|
||||
friction,
|
||||
position,
|
||||
quaternion,
|
||||
velocity,
|
||||
angularVelocity,
|
||||
linearDamping,
|
||||
angularDamping,
|
||||
allowSleep,
|
||||
sleepSpeedLimit,
|
||||
sleepTimeLimit,
|
||||
collisionFilterGroup,
|
||||
collisionFilterMask,
|
||||
fixedRotation,
|
||||
shape,
|
||||
kinematic
|
||||
) {
|
||||
this.id = R3.Utils.RandomId();
|
||||
this.position = position || new R3.API.Vector3();
|
||||
this.velocity = velocity || new R3.API.Vector3();
|
||||
this.angularVelocity = angularVelocity || new R3.API.Vector3();
|
||||
this.quaternion = quaternion || new R3.API.Quaternion(0, 0, 0, 1);
|
||||
this.mass = typeof mass == "undefined" ? 0 : mass;
|
||||
this.friction = typeof friction == "undefined" ? 5 : friction;
|
||||
this.linearDamping = typeof linearDamping == "undefined" ? 0.01 : linearDamping;
|
||||
this.angularDamping = typeof angularDamping == "undefined" ? 0.01 : angularDamping;
|
||||
this.allowSleep = typeof allowSleep == "undefined" ? true : allowSleep;
|
||||
this.sleepSpeedLimit = typeof sleepSpeedLimit == "undefined" ? 0.1 : sleepSpeedLimit;
|
||||
this.sleepTimeLimit = typeof sleepTimeLimit == "undefined" ? 1.0 : sleepTimeLimit;
|
||||
this.collisionFilterGroup = typeof collisionFilterGroup == "undefined" ? 1 : collisionFilterGroup;
|
||||
this.collisionFilterMask = typeof collisionFilterMask == "undefined" ? 1 : collisionFilterMask;
|
||||
this.fixedRotation = typeof fixedRotation == "undefined" ? false : fixedRotation;
|
||||
this.shape = typeof shape == "undefined" ? null : shape;
|
||||
this.kinematic = kinematic || false;
|
||||
|
||||
this.engine = engine;
|
||||
this.engine.isNotCannonThrow();
|
||||
this.instance = this.createInstance();
|
||||
|
||||
// Todo: this should be executed somewhere in r3-z, so that we don't execute it on every construction of an object.
|
||||
R3.Utils.Extend(R3.D3.RigidBody, R3.Component);
|
||||
};
|
||||
|
||||
/**
|
||||
* private function
|
||||
* @returns {*}
|
||||
*/
|
||||
R3.D3.RigidBody.prototype.createInstance = function() {
|
||||
|
||||
var instance = new this.engine.instance.Body({
|
||||
mass: this.mass,
|
||||
friction: this.friction,
|
||||
position: new this.engine.instance.Vec3(
|
||||
this.position.x,
|
||||
this.position.y,
|
||||
this.position.z
|
||||
),
|
||||
velocity: new this.engine.instance.Vec3(
|
||||
this.velocity.x,
|
||||
this.velocity.y,
|
||||
this.velocity.z
|
||||
),
|
||||
quaternion: new this.engine.instance.Quaternion(
|
||||
this.quaternion.x,
|
||||
this.quaternion.y,
|
||||
this.quaternion.z,
|
||||
this.quaternion.w
|
||||
),
|
||||
angularVelocity: new this.engine.instance.Vec3(
|
||||
this.angularVelocity.x,
|
||||
this.angularVelocity.y,
|
||||
this.angularVelocity.z
|
||||
),
|
||||
linearDamping: this.linearDamping,
|
||||
angularDamping: this.angularDamping,
|
||||
allowSleep: this.allowSleep,
|
||||
sleepSpeedLimit: this.sleepSpeedLimit,
|
||||
sleepTimeLimit: this.sleepTimeLimit,
|
||||
collisionFilterGroup: this.collisionFilterGroup,
|
||||
collisionFilterMask: this.collisionFilterMask,
|
||||
fixedRotation: this.fixedRotation,
|
||||
shape: this.shape && this.shape.instance ? this.shape.instance : null
|
||||
});
|
||||
|
||||
this.instance = instance;
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
R3.D3.RigidBody.prototype.toApiRigidBody = function() {
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a shape to this rigid body
|
||||
* @param shape R3.D3.Shape
|
||||
* @param offset R3.API.Vector3
|
||||
* @param orientation R3.API.Quaternion
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.RigidBody.prototype.addShape = function(
|
||||
shape,
|
||||
offset,
|
||||
orientation
|
||||
) {
|
||||
if (!offset || typeof offset == 'undefined') {
|
||||
offset = new R3.API.Vector3(0,0,0);
|
||||
}
|
||||
|
||||
if (!orientation || typeof orientation == 'undefined') {
|
||||
orientation = new R3.API.Quaternion(0,0,0,1);
|
||||
}
|
||||
|
||||
this.instance.addShape(
|
||||
shape.instance,
|
||||
new this.engine.instance.Vec3(
|
||||
offset.x,
|
||||
offset.y,
|
||||
offset.z
|
||||
),
|
||||
new this.engine.instance.Quaternion(
|
||||
orientation.x,
|
||||
orientation.y,
|
||||
orientation.z,
|
||||
orientation.w
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
///////////////////////// Methods to override //////////////////////////
|
||||
R3.D3.RigidBody.prototype.onUpdate = function(
|
||||
deltaTime,
|
||||
parentEntity
|
||||
) {
|
||||
if(parentEntity) {
|
||||
if (this.kinematic) {
|
||||
// reapply the entity's transform back to the rigid body, since it is kinematic
|
||||
this.instance.position.x = parentEntity.position.x;
|
||||
this.instance.position.y = parentEntity.position.y;
|
||||
this.instance.position.z = parentEntity.position.z;
|
||||
|
||||
this.instance.quaternion.x = parentEntity.quaternion.x;
|
||||
this.instance.quaternion.y = parentEntity.quaternion.y;
|
||||
this.instance.quaternion.z = parentEntity.quaternion.z;
|
||||
this.instance.quaternion.w = parentEntity.quaternion.w;
|
||||
|
||||
this.instance.inertia.x = 0;
|
||||
this.instance.inertia.y = 0;
|
||||
this.instance.inertia.z = 0;
|
||||
|
||||
this.instance.velocity.x = 0;
|
||||
this.instance.velocity.y = 0;
|
||||
this.instance.velocity.z = 0;
|
||||
} else {
|
||||
var quaternion = new THREE.Quaternion();
|
||||
quaternion.copy(this.instance.quaternion);
|
||||
|
||||
var position = new THREE.Vector3();
|
||||
position.copy(this.instance.position);
|
||||
|
||||
parentEntity.position.x = position.x;
|
||||
parentEntity.position.y = position.y;
|
||||
parentEntity.position.z = position.z;
|
||||
|
||||
parentEntity.quaternion.x = quaternion.x;
|
||||
parentEntity.quaternion.y = quaternion.y;
|
||||
parentEntity.quaternion.z = quaternion.z;
|
||||
parentEntity.quaternion.w = quaternion.w;
|
||||
}
|
||||
}
|
||||
};
|
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* Rigid Wheel superset
|
||||
* @param body R3.D3.RigidBody
|
||||
* @param position R3.API.Vector3
|
||||
* @param axis R3.API.Vector3
|
||||
* @param direction R3.API.Vector3
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.RigidWheel = function(
|
||||
body,
|
||||
position,
|
||||
axis,
|
||||
direction
|
||||
) {
|
||||
this.id = R3.Utils.RandomId();
|
||||
this.body = body;
|
||||
this.position = position;
|
||||
this.axis = axis;
|
||||
this.direction = direction;
|
||||
};
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* Selected Objects
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param object
|
||||
* @param helper
|
||||
* @param lastUpdate
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.SelectedObject = function SelectedObject(
|
||||
graphics,
|
||||
object,
|
||||
helper,
|
||||
lastUpdate
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(object)) {
|
||||
console.warn('Cannot select no object');
|
||||
throw new Error('Cannot select no object');
|
||||
}
|
||||
this.object = object;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(helper)) {
|
||||
helper = new R3.D3.Helper(
|
||||
this.graphics,
|
||||
null,
|
||||
null,
|
||||
object
|
||||
)
|
||||
}
|
||||
this.helper = helper;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(lastUpdate)) {
|
||||
lastUpdate = Date.now();
|
||||
}
|
||||
this.lastUpdate = lastUpdate;
|
||||
};
|
|
@ -0,0 +1,195 @@
|
|||
/**
|
||||
* Physics Shape Superset
|
||||
* @param engine R3.D3.Engine
|
||||
* @param shapeType
|
||||
* @param scale R3.API.Vector3
|
||||
* @param vertices Number[]
|
||||
* @param indices Number[]
|
||||
* @param radius Number
|
||||
* @param halfExtensions R3.API.Vector3
|
||||
* @param radiusTop Number
|
||||
* @param radiusBottom Number
|
||||
* @param height Number
|
||||
* @param numSegments Number
|
||||
* @param heightmap R3.D3.Heightmap
|
||||
* @param elementSize
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Shape = function(
|
||||
engine,
|
||||
shapeType,
|
||||
scale,
|
||||
vertices,
|
||||
indices,
|
||||
radius,
|
||||
halfExtensions,
|
||||
radiusTop,
|
||||
radiusBottom,
|
||||
height,
|
||||
numSegments,
|
||||
heightmap
|
||||
) {
|
||||
|
||||
this.engine = engine;
|
||||
|
||||
this.engine.isNotCannonThrow();
|
||||
|
||||
this.shapeType = shapeType;
|
||||
|
||||
if (typeof scale == 'undefined') {
|
||||
scale = new R3.API.Vector3(1, 1, 1)
|
||||
}
|
||||
this.scale = scale;
|
||||
|
||||
if (typeof vertices == 'undefined') {
|
||||
vertices = [];
|
||||
}
|
||||
this.vertices = vertices;
|
||||
|
||||
if (typeof indices == 'undefined') {
|
||||
indices = [];
|
||||
}
|
||||
this.indices = indices;
|
||||
|
||||
if (typeof radius == 'undefined') {
|
||||
radius = 1;
|
||||
}
|
||||
this.radius = radius;
|
||||
|
||||
if (typeof halfExtensions == 'undefined') {
|
||||
halfExtensions = new R3.API.Vector3(1,1,1);
|
||||
}
|
||||
this.halfExtensions = halfExtensions;
|
||||
|
||||
if (typeof radiusTop == 'undefined') {
|
||||
radiusTop = 1;
|
||||
}
|
||||
this.radiusTop = radiusTop;
|
||||
|
||||
if (typeof radiusBottom == 'undefined') {
|
||||
radiusBottom = 1;
|
||||
}
|
||||
this.radiusBottom = radiusBottom;
|
||||
|
||||
if (typeof height == 'undefined') {
|
||||
height = 1;
|
||||
}
|
||||
this.height = height;
|
||||
|
||||
if (typeof numSegments == 'undefined') {
|
||||
numSegments = 1;
|
||||
}
|
||||
this.numSegments = numSegments;
|
||||
|
||||
if (typeof heightmap == 'undefined') {
|
||||
heightmap = new R3.D3.Heightmap();
|
||||
}
|
||||
this.heightmap = heightmap;
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
* Shape constants
|
||||
* @type {number}
|
||||
*/
|
||||
R3.D3.Shape.SHAPE_TYPE_SPHERE = 1;
|
||||
R3.D3.Shape.SHAPE_TYPE_BOX = 2;
|
||||
R3.D3.Shape.SHAPE_TYPE_TRIMESH = 3;
|
||||
R3.D3.Shape.SHAPE_TYPE_CYLINDER = 4;
|
||||
R3.D3.Shape.SHAPE_TYPE_HEIGHT_MAP = 5;
|
||||
R3.D3.Shape.SHAPE_TYPE_CONVEX_HULL = 6;
|
||||
R3.D3.Shape.SHAPE_TYPE_PLANE = 7;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
R3.D3.Shape.prototype.createInstance = function() {
|
||||
|
||||
var instance = null;
|
||||
|
||||
if (this.shapeType == R3.D3.Shape.SHAPE_TYPE_TRIMESH) {
|
||||
|
||||
} else if (this.shapeType == R3.D3.Shape.SHAPE_TYPE_SPHERE) {;
|
||||
} else if (this.shapeType == R3.D3.Shape.SHAPE_TYPE_BOX) {
|
||||
|
||||
} else if (this.shapeType == R3.D3.Shape.SHAPE_TYPE_CYLINDER) {
|
||||
|
||||
} else if (this.shapeType == R3.D3.Shape.SHAPE_TYPE_HEIGHT_MAP) {
|
||||
|
||||
} else if (this.shapeType == R3.D3.Shape.SHAPE_TYPE_CONVEX_HULL) {
|
||||
|
||||
instance = new this.engine.instance.ConvexPolyhedron(
|
||||
this.vertices, this.indices
|
||||
);
|
||||
|
||||
} else if(this.shapeType == R3.D3.Shape.SHAPE_TYPE_PLANE) {
|
||||
instance = new this.engine.instance.Plane();
|
||||
} else {
|
||||
console.warn('Shape type not implemented: ' + this.shapeType);
|
||||
throw new Error('Shape type not implemented: ' + this.shapeType);
|
||||
}
|
||||
|
||||
this.instance = instance;
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* update
|
||||
*/
|
||||
R3.D3.Shape.prototype.update = function(
|
||||
engine
|
||||
) {
|
||||
engine.isNotCannonThrow();
|
||||
|
||||
if(this.shapeType === R3.D3.Shape.SHAPE_TYPE_TRIMESH) {
|
||||
this.instance.setScale(
|
||||
new engine.instance.Vec3(
|
||||
this.scale.x,
|
||||
this.scale.y,
|
||||
this.scale.z
|
||||
)
|
||||
);
|
||||
this.instance.updateAABB();
|
||||
this.instance.updateNormals();
|
||||
this.instance.updateEdges();
|
||||
this.instance.updateBoundingSphereRadius();
|
||||
this.instance.updateTree();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts a R3.D3.Shape to a R3.D3.API.Shape
|
||||
* @returns {R3.D3.API.Shape}
|
||||
*/
|
||||
R3.D3.Shape.prototype.toApiShape = function() {
|
||||
|
||||
return new R3.D3.API.Shape(
|
||||
this.engine.toApiEngine(),
|
||||
this.shapeType,
|
||||
this.scale.toApiVector(),
|
||||
this.vertices,
|
||||
this.indices,
|
||||
this.radius,
|
||||
this.halfExtensions,
|
||||
this.radiusTop,
|
||||
this.radiusBottom,
|
||||
this.height,
|
||||
this.numSegments,
|
||||
this.heightmap.toApiHeightMap()
|
||||
)
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts from an Object to a Shape
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param objectShape Object
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.Shape.FromObjectShape = function(graphics, objectShape) {
|
||||
//todo: implement this still
|
||||
return null;
|
||||
};
|
|
@ -0,0 +1,69 @@
|
|||
R3.D3.SkyBox = function (
|
||||
graphics
|
||||
) {
|
||||
this.id = null;
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
this.texturesFolder = null;
|
||||
};
|
||||
|
||||
R3.D3.SkyBox.prototype.load = function (
|
||||
texturesFolder
|
||||
) {
|
||||
this.texturesFolder = texturesFolder;
|
||||
this.textures = [];
|
||||
this.materials = [];
|
||||
this.mesh = {};
|
||||
this.scene = new this.graphics.instance.Scene();
|
||||
this.textureCube = null;
|
||||
|
||||
var textureLoader = new this.graphics.instance.TextureLoader();
|
||||
|
||||
// this textures are used to display the skybox
|
||||
this.textures.push(textureLoader.load(this.texturesFolder + "px.png"));
|
||||
this.textures.push(textureLoader.load(this.texturesFolder + "nx.png"));
|
||||
this.textures.push(textureLoader.load(this.texturesFolder + "py.png"));
|
||||
this.textures.push(textureLoader.load(this.texturesFolder + "ny.png"));
|
||||
this.textures.push(textureLoader.load(this.texturesFolder + "pz.png"));
|
||||
this.textures.push(textureLoader.load(this.texturesFolder + "nz.png"));
|
||||
|
||||
// assign textures to each cube face
|
||||
for (var i = 0; i < 6; i ++) {
|
||||
this.materials.push(new this.graphics.instance.MeshBasicMaterial({ map: this.textures[i] }));
|
||||
}
|
||||
|
||||
// create cube geometry
|
||||
this.mesh = new this.graphics.instance.Mesh(new this.graphics.instance.CubeGeometry(1, 1, 1), new this.graphics.instance.MeshFaceMaterial(this.materials));
|
||||
this.mesh.applyMatrix(new this.graphics.instance.Matrix4().makeScale(1, 1, -1));
|
||||
this.scene.add(this.mesh);
|
||||
|
||||
// Load env textureCube
|
||||
// this is used for reflections on meshes
|
||||
// mesh.material.envMap = this.textureCube;
|
||||
this.textureCube = new this.graphics.instance.CubeTextureLoader().load([
|
||||
this.texturesFolder + "px.png", this.texturesFolder + "nx.png",
|
||||
this.texturesFolder + "py.png", this.texturesFolder + "ny.png",
|
||||
this.texturesFolder + "pz.png", this.texturesFolder + "nz.png"
|
||||
]);
|
||||
};
|
||||
|
||||
R3.D3.SkyBox.prototype.render = function (
|
||||
threeRenderer,
|
||||
threeCamera
|
||||
) {
|
||||
var cameraPosition = new this.graphics.instance.Vector3(threeCamera.position.x, threeCamera.position.y, threeCamera.position.z);
|
||||
|
||||
threeCamera.position.set(0, 0, 0);
|
||||
|
||||
var gl = threeRenderer.context;
|
||||
|
||||
gl.disable(gl.DEPTH_TEST);
|
||||
|
||||
threeRenderer.render(this.scene, threeCamera);
|
||||
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
|
||||
threeCamera.position.copy(cameraPosition);
|
||||
};
|
|
@ -0,0 +1,914 @@
|
|||
/**
|
||||
* World SuperSet - contains the custom world instance
|
||||
* @param id
|
||||
* @param name
|
||||
* @param engine
|
||||
* @param gravity
|
||||
* @param broadphase
|
||||
* @param solver
|
||||
* @param rigidBodies
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.World = function(
|
||||
id,
|
||||
name,
|
||||
engine,
|
||||
gravity,
|
||||
broadphase,
|
||||
solver,
|
||||
rigidBodies
|
||||
) {
|
||||
|
||||
this.id = id;
|
||||
|
||||
this.name = name;
|
||||
|
||||
if (typeof gravity == 'undefined') {
|
||||
gravity = new R3.API.Vector3(0, -9.81, 0);
|
||||
}
|
||||
this.gravity = gravity;
|
||||
|
||||
if (typeof broadphase == 'undefined') {
|
||||
broadphase = new R3.D3.Broadphase(
|
||||
null,
|
||||
'broadPhaseNaive',
|
||||
R3.D3.Broadphase.BROADPHASE_TYPE_NAIVE,
|
||||
engine
|
||||
);
|
||||
}
|
||||
this.broadphase = broadphase;
|
||||
|
||||
if (typeof solver == 'undefined') {
|
||||
solver = new R3.D3.Solver(
|
||||
null,
|
||||
engine,
|
||||
R3.D3.Solver.GS_SOLVER
|
||||
);
|
||||
}
|
||||
this.solver = solver;
|
||||
|
||||
if (typeof rigidBodies == 'undefined') {
|
||||
rigidBodies = [];
|
||||
}
|
||||
this.rigidBodies = rigidBodies;
|
||||
|
||||
this.engine = engine;
|
||||
|
||||
this.engine.isNotCannonThrow();
|
||||
|
||||
this.instance = this.createInstance();
|
||||
};
|
||||
|
||||
/**
|
||||
* private
|
||||
* @returns {R3.D3.World|R3.D3.Physics.World|*}
|
||||
*/
|
||||
R3.D3.World.prototype.createInstance = function() {
|
||||
|
||||
var instance = new this.engine.instance.World();
|
||||
|
||||
instance.broadphase = this.broadphase.instance;
|
||||
|
||||
instance.solver = this.solver.instance;
|
||||
|
||||
instance.gravity.x = this.gravity.x;
|
||||
instance.gravity.y = this.gravity.y;
|
||||
instance.gravity.z = this.gravity.z;
|
||||
|
||||
instance.name = this.name;
|
||||
|
||||
return instance;
|
||||
};
|
||||
|
||||
R3.D3.World.prototype.toApiWorld = function() {
|
||||
//TODO: create API.World someday
|
||||
return {
|
||||
id: this.id,
|
||||
name: this.name,
|
||||
engine: this.engine.toApiEngine(),
|
||||
gravity: this.gravity,
|
||||
broadphase: this.broadphase.toApiBroadphase(),
|
||||
solver: this.solver.toApiSolver(),
|
||||
rigidBodies: this.rigidBodies.map(function(rigidBody){return rigidBody.toApiRigidBody()})
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
R3.D3.World.FromObjectWorld = function(engine, objectWorld) {
|
||||
|
||||
//todo implement this fully
|
||||
return new R3.D3.World(
|
||||
objectWorld.id,
|
||||
objectWorld.name,
|
||||
engine,
|
||||
objectWorld.gravity,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param rigidBody R3.D3.RigidBody
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.World.prototype.addRigidBody = function(
|
||||
rigidBody
|
||||
) {
|
||||
this.instance.addBody(rigidBody.instance);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param vehicle (R3.D3.RigidBodyVehicle | R3.D3.RaycastVehicle)
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.World.prototype.addVehicle = function(
|
||||
vehicle
|
||||
) {
|
||||
vehicle.instance.addToWorld(this.instance);
|
||||
};
|
||||
|
||||
R3.D3.World.prototype.step = function(
|
||||
fixedStep,
|
||||
dtStep
|
||||
) {
|
||||
this.instance.step(fixedStep, dtStep, 3);
|
||||
return;
|
||||
|
||||
var now = Date.now() / 1000.0;
|
||||
//var now = null;
|
||||
if(!this.lastCallTime){
|
||||
// last call time not saved, cant guess elapsed time. Take a simple step.
|
||||
this.instance.step(fixedStep);
|
||||
this.lastCallTime = now;
|
||||
return;
|
||||
}
|
||||
|
||||
var timeSinceLastCall = (now - this.lastCallTime);
|
||||
|
||||
this.instance.step(fixedStep, timeSinceLastCall, 4);
|
||||
|
||||
this.lastCallTime = now;
|
||||
};
|
||||
|
||||
R3.D3.World.prototype.GetIndexedVertices = function(
|
||||
triangleMeshShape
|
||||
) {
|
||||
|
||||
if(this.engine.engineType == R3.D3.Physics.TYPE_CANNON) {
|
||||
|
||||
return {
|
||||
vertices : triangleMeshShape.vertices,
|
||||
indices : triangleMeshShape.indices
|
||||
};
|
||||
|
||||
} else {
|
||||
// todo: implement this for other physics engines.
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @param triangleMeshShape R3.D3.Shape
|
||||
* @param normalLength Number
|
||||
* @param scale R3.API.Vector3
|
||||
* @param opacity Number
|
||||
* @param wireframeColor HexCode
|
||||
* @param graphics THREE
|
||||
* @returns {THREE.Mesh|this.meshes}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.World.prototype.generateWireframeViewTriangleMesh = function(
|
||||
graphics,
|
||||
triangleMeshShape,
|
||||
normalLength,
|
||||
scale,
|
||||
opacity,
|
||||
wireframeColor
|
||||
) {
|
||||
graphics.isNotThreeThrow();
|
||||
this.engine.isNotCannonThrow();
|
||||
|
||||
if(typeof normalLength == 'undefined') {
|
||||
normalLength = 10;
|
||||
}
|
||||
|
||||
if(typeof scale == 'undefined') {
|
||||
scale = new graphics.instance.Vector3(1, 1, 1);
|
||||
}
|
||||
|
||||
if(typeof opacity == 'undefined') {
|
||||
opacity = 0.5;
|
||||
}
|
||||
|
||||
if(typeof wireframeColor == 'undefined') {
|
||||
wireframeColor = 0xfefefe;
|
||||
}
|
||||
|
||||
var graphicsGeometry = new graphics.instance.Geometry();
|
||||
|
||||
var wireframeMesh = new graphics.instance.Mesh(
|
||||
graphicsGeometry,
|
||||
new graphics.instance.MeshBasicMaterial({
|
||||
color: wireframeColor,
|
||||
wireframe: true,
|
||||
opacity: opacity
|
||||
})
|
||||
);
|
||||
|
||||
for(var v = 0, l = triangleMeshShape.instance.vertices.length / 3; v < l; ++v) {
|
||||
graphicsGeometry.vertices.push(
|
||||
new graphics.instance.Vector3(
|
||||
triangleMeshShape.instance.vertices[v * 3],
|
||||
triangleMeshShape.instance.vertices[v * 3 + 1],
|
||||
triangleMeshShape.instance.vertices[v * 3 + 2]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
for(var i = 0, l = triangleMeshShape.instance.indices.length / 3; i < l; ++i) {
|
||||
var i0 = triangleMeshShape.instance.indices[i * 3];
|
||||
var i1 = triangleMeshShape.instance.indices[i * 3 + 1];
|
||||
var i2 = triangleMeshShape.instance.indices[i * 3 + 2];
|
||||
|
||||
graphicsGeometry.faces.push(
|
||||
new graphics.instance.Face3(
|
||||
i0,
|
||||
i1,
|
||||
i2
|
||||
)
|
||||
);
|
||||
|
||||
// Center point on the current triangle
|
||||
|
||||
var centroid = new graphics.instance.Vector3()
|
||||
.add(graphicsGeometry.vertices[i0])
|
||||
.add(graphicsGeometry.vertices[i1])
|
||||
.add(graphicsGeometry.vertices[i2])
|
||||
.divideScalar(3);
|
||||
|
||||
// Get the normal from the mesh shape itself
|
||||
var normal = new this.engine.instance.Vec3();
|
||||
triangleMeshShape.instance.getNormal(i , normal);
|
||||
|
||||
var arrow = new graphics.instance.ArrowHelper(
|
||||
new graphics.instance.Vector3(
|
||||
normal.x,
|
||||
normal.y,
|
||||
normal.z
|
||||
),
|
||||
centroid,
|
||||
normalLength,
|
||||
new graphics.instance.Color(
|
||||
normal.x,
|
||||
normal.y,
|
||||
normal.z
|
||||
)
|
||||
);
|
||||
wireframeMesh.add( arrow );
|
||||
}
|
||||
|
||||
wireframeMesh.scale.x = scale.x;
|
||||
wireframeMesh.scale.y = scale.y;
|
||||
wireframeMesh.scale.z = scale.z;
|
||||
|
||||
return wireframeMesh;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param convexPolyMeshShape R3.D3.Shape
|
||||
* @param normalLength Number
|
||||
* @param scale R3.API.Vector3
|
||||
* @param opacity Number
|
||||
* @param wireframeColor HexCode
|
||||
* @param graphics THREE
|
||||
* @returns {THREE.Mesh|this.meshes}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.World.prototype.generateWireframeViewConvexPolyMesh = function(
|
||||
graphics,
|
||||
convexPolyMeshShape,
|
||||
normalLength,
|
||||
scale,
|
||||
opacity,
|
||||
wireframeColor
|
||||
) {
|
||||
graphics.isNotThreeThrow();
|
||||
this.engine.isNotCannonThrow();
|
||||
|
||||
if(typeof normalLength == 'undefined') {
|
||||
normalLength = 10;
|
||||
}
|
||||
|
||||
if(typeof scale == 'undefined') {
|
||||
scale = new graphics.instance.Vector3(1, 1, 1);
|
||||
}
|
||||
|
||||
if(typeof opacity == 'undefined') {
|
||||
opacity = 0.5;
|
||||
}
|
||||
|
||||
if(typeof wireframeColor == 'undefined') {
|
||||
wireframeColor = 0xfefefe;
|
||||
}
|
||||
|
||||
|
||||
var graphicsGeometry = new graphics.instance.Geometry();
|
||||
var wireframeMesh = new graphics.instance.Mesh(
|
||||
graphicsGeometry,
|
||||
new graphics.instance.MeshBasicMaterial({
|
||||
color: wireframeColor,
|
||||
wireframe: true,
|
||||
opacity: opacity
|
||||
})
|
||||
);
|
||||
|
||||
for(var i = 0, l = convexPolyMeshShape.instance.vertices.length; i < l; i++) {
|
||||
var vertex = convexPolyMeshShape.instance.vertices[i];
|
||||
graphicsGeometry.vertices.push(new graphics.instance.Vector3(vertex.x, vertex.y, vertex.z));
|
||||
}
|
||||
|
||||
for(var i = 0, l = convexPolyMeshShape.instance.faces.length; i < l; i++) {
|
||||
var face = convexPolyMeshShape.instance.faces[i];
|
||||
|
||||
var i0 = face[0];
|
||||
var i1 = face[1];
|
||||
var i2 = face[2];
|
||||
|
||||
graphicsGeometry.faces.push(new graphics.instance.Face3(i0, i1, i2));
|
||||
|
||||
// Center point on the current triangle
|
||||
var centroid = new graphics.instance.Vector3()
|
||||
.add(graphicsGeometry.vertices[i0])
|
||||
.add(graphicsGeometry.vertices[i1])
|
||||
.add(graphicsGeometry.vertices[i2])
|
||||
.divideScalar(3);
|
||||
|
||||
var normalVec3 = convexPolyMeshShape.instance.faceNormals[i];
|
||||
var normal = new graphics.instance.Vector3(
|
||||
normalVec3.x,
|
||||
normalVec3.y,
|
||||
normalVec3.z
|
||||
);
|
||||
|
||||
var arrow = new graphics.instance.ArrowHelper(
|
||||
normal,
|
||||
centroid,
|
||||
normalLength,
|
||||
new graphics.instance.Color(
|
||||
normal.x,
|
||||
normal.y,
|
||||
normal.z
|
||||
)
|
||||
);
|
||||
|
||||
wireframeMesh.add( arrow );
|
||||
}
|
||||
|
||||
wireframeMesh.scale.x = scale.x;
|
||||
wireframeMesh.scale.y = scale.y;
|
||||
wireframeMesh.scale.z = scale.z;
|
||||
|
||||
return wireframeMesh;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param graphicsMesh THREE.Mesh
|
||||
* @param mass Number
|
||||
* @param friction Number
|
||||
* @param createCollisionSubMeshes Boolean
|
||||
* @param facesPerSubsection Number
|
||||
* @param subsectionsToMerge Number
|
||||
* @returns {Object}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.World.prototype.generateTriangleMeshShapeDivided = function(
|
||||
graphics,
|
||||
graphicsMesh,
|
||||
mass,
|
||||
friction,
|
||||
createCollisionSubMeshes,
|
||||
facesPerSubsection,
|
||||
subsectionsToMerge
|
||||
) {
|
||||
graphics.isNotThreeThrow();
|
||||
this.engine.isNotCannonThrow();
|
||||
|
||||
if(mass == null || typeof mass == 'undefined') {
|
||||
mass = 0;
|
||||
}
|
||||
|
||||
if(friction == null || typeof friction == 'undefined') {
|
||||
friction = 10;
|
||||
}
|
||||
|
||||
if(createCollisionSubMeshes == null || typeof createCollisionSubMeshes == 'undefined') {
|
||||
createCollisionSubMeshes = false;
|
||||
}
|
||||
|
||||
var processedFaces = 0;
|
||||
var facesPerSubSection = facesPerSubsection || 0;
|
||||
var subMeshesToMerge = subsectionsToMerge || 0;
|
||||
var totalAmtFaces = graphicsMesh.geometry.faces.length;
|
||||
var facesToProcess = createCollisionSubMeshes ? (subMeshesToMerge * facesPerSubSection) : totalAmtFaces;
|
||||
|
||||
var pairs = []; // output
|
||||
|
||||
var vertices = [];
|
||||
var indicies = [];
|
||||
|
||||
for(var i = 0; i <= totalAmtFaces; i++) {
|
||||
if(processedFaces == facesToProcess || i == totalAmtFaces) {
|
||||
|
||||
var body = null;
|
||||
|
||||
var meshShape = new this.engine.instance.Trimesh(vertices, indicies);
|
||||
|
||||
meshShape.setScale(new this.engine.instance.Vec3(
|
||||
graphicsMesh.scale.x,
|
||||
graphicsMesh.scale.y,
|
||||
graphicsMesh.scale.z
|
||||
));
|
||||
|
||||
meshShape.updateAABB();
|
||||
meshShape.updateNormals();
|
||||
meshShape.updateEdges();
|
||||
meshShape.updateBoundingSphereRadius();
|
||||
meshShape.updateTree();
|
||||
|
||||
body = new this.engine.instance.Body({
|
||||
mass: mass,
|
||||
friction: friction
|
||||
});
|
||||
body.addShape(meshShape);
|
||||
|
||||
pairs.push({
|
||||
threeObject : createCollisionSubMeshes ? null : graphicsMesh,
|
||||
physicsObject : body
|
||||
});
|
||||
|
||||
vertices = [];
|
||||
indicies = [];
|
||||
processedFaces = 0;
|
||||
|
||||
if(i == totalAmtFaces) {
|
||||
return pairs;
|
||||
}
|
||||
}
|
||||
|
||||
var face = graphicsMesh.geometry.faces[i];
|
||||
indicies.push(indicies.length);
|
||||
indicies.push(indicies.length);
|
||||
indicies.push(indicies.length);
|
||||
|
||||
var v0 = graphicsMesh.geometry.vertices[face.a];
|
||||
var v1 = graphicsMesh.geometry.vertices[face.b];
|
||||
var v2 = graphicsMesh.geometry.vertices[face.c];
|
||||
|
||||
vertices.push(v0.x, v0.y, v0.z);
|
||||
vertices.push(v1.x, v1.y, v1.z);
|
||||
vertices.push(v2.x, v2.y, v2.z);
|
||||
|
||||
processedFaces++;
|
||||
}
|
||||
};
|
||||
|
||||
R3.D3.World.prototype.generateConvexPolyShape = function(
|
||||
graphics,
|
||||
mesh
|
||||
) {
|
||||
var processedFaces = 0;
|
||||
var facesPerSubSection = 2; // *2 -> SUBDIVISION MESH
|
||||
var subMeshesToMerge = 4; // *2 -> SUBDIVISION MESH
|
||||
var facesToProcess = subMeshesToMerge * facesPerSubSection;
|
||||
|
||||
var vertices = [];
|
||||
var indicies = [];
|
||||
|
||||
for(var i = 0; i <= mesh.geometry.faces.length; i++) {
|
||||
if(processedFaces == facesToProcess || i == mesh.geometry.faces.length) {
|
||||
|
||||
// try and create convex poly...........
|
||||
var convexIndices = [];
|
||||
for(var index = 0; index < indicies.length / 3; index++) {
|
||||
convexIndices.push([ indicies[index * 3], indicies[index * 3 + 1], indicies[index * 3 + 2] ]);
|
||||
}
|
||||
|
||||
var convexVertices = [];
|
||||
for(var vert = 0; vert < vertices.length / 3; vert++) {
|
||||
convexVertices[vert] = new CANNON.Vec3(vertices[vert * 3] * mesh.scale.x, vertices[vert * 3 + 1] * mesh.scale.y, vertices[vert * 3 + 2] * mesh.scale.z);
|
||||
}
|
||||
|
||||
var meshShape = new R3.D3.Shape(this.engine, R3.D3.Shape.SHAPE_TYPE_CONVEX_HULL, {x:1,y:1,z:1},convexVertices, convexIndices);
|
||||
|
||||
var body = new R3.D3.RigidBody(this.engine, 0, 1);
|
||||
body.addShape(meshShape);
|
||||
|
||||
this.addRigidBody(body);
|
||||
|
||||
vertices = [];
|
||||
indicies = [];
|
||||
processedFaces = 0;
|
||||
|
||||
console.log("SPLIT MESH TO CONVEX POLY");
|
||||
|
||||
if(i == mesh.geometry.faces.length) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var face = mesh.geometry.faces[i];
|
||||
indicies.push(indicies.length);
|
||||
indicies.push(indicies.length);
|
||||
indicies.push(indicies.length);
|
||||
|
||||
var v0 = mesh.geometry.vertices[face.a];
|
||||
var v1 = mesh.geometry.vertices[face.b];
|
||||
var v2 = mesh.geometry.vertices[face.c];
|
||||
|
||||
vertices.push(v0.x, v0.y, v0.z);
|
||||
vertices.push(v1.x, v1.y, v1.z);
|
||||
vertices.push(v2.x, v2.y, v2.z);
|
||||
|
||||
processedFaces++;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param graphicsMesh THREE.Mesh
|
||||
* @returns {R3.D3.Shape}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.World.prototype.generateTriangleMeshShape = function(
|
||||
graphics,
|
||||
graphicsMesh
|
||||
) {
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Note: I did not test this yet with the API data.
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
var scaledVertices = [];
|
||||
for(var i = 0, l = graphicsMesh.geometry.vertices.length; i < l; i++) {
|
||||
|
||||
var vertex = graphicsMesh.geometry.vertices[i];
|
||||
|
||||
scaledVertices.push(new this.engine.instance.Vec3(
|
||||
vertex.x * graphicsMesh.scale.x,
|
||||
vertex.y * graphicsMesh.scale.y,
|
||||
vertex.z * graphicsMesh.scale.z
|
||||
));
|
||||
}
|
||||
|
||||
var triangleFaces = [];
|
||||
for(var f = 0, fl = graphicsMesh.geometry.faces.length; f < fl; f++) {
|
||||
var i0 = graphicsMesh.geometry.faces[f].a;
|
||||
var i1 = graphicsMesh.geometry.faces[f].b;
|
||||
var i2 = graphicsMesh.geometry.faces[f].c;
|
||||
|
||||
triangleFaces.push([
|
||||
i0, i1, i2
|
||||
]);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - -
|
||||
// Create collision mesh
|
||||
// - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
var reindexedFaces = {};
|
||||
var vertices = [];
|
||||
var faces = [];
|
||||
|
||||
var processedFaces = 0;
|
||||
var totalFacesToProcess = triangleFaces.length;
|
||||
var flLastIndex = 0;
|
||||
|
||||
for(var f = 0; f < totalFacesToProcess; f++) {
|
||||
|
||||
var i0 = triangleFaces[f][0];
|
||||
var i1 = triangleFaces[f][1];
|
||||
var i2 = triangleFaces[f][2];
|
||||
|
||||
if(typeof reindexedFaces[i0] === 'undefined') {
|
||||
vertices.push(scaledVertices[i0].x, scaledVertices[i0].y, scaledVertices[i0].z);
|
||||
reindexedFaces[i0] = flLastIndex;
|
||||
flLastIndex++;
|
||||
}
|
||||
|
||||
if(typeof reindexedFaces[i1] === 'undefined') {
|
||||
vertices.push(scaledVertices[i1].x, scaledVertices[i1].y, scaledVertices[i1].z);
|
||||
reindexedFaces[i1] = flLastIndex;
|
||||
flLastIndex++;
|
||||
}
|
||||
|
||||
if(typeof reindexedFaces[i2] === 'undefined') {
|
||||
vertices.push(scaledVertices[i2].x, scaledVertices[i2].y, scaledVertices[i2].z);
|
||||
reindexedFaces[i2] = flLastIndex;
|
||||
flLastIndex++;
|
||||
}
|
||||
|
||||
faces.push(reindexedFaces[i0], reindexedFaces[i1], reindexedFaces[i2]);
|
||||
|
||||
processedFaces++;
|
||||
}
|
||||
|
||||
return new R3.D3.Shape(this.engine, R3.D3.Shape.SHAPE_TYPE_TRIMESH, {x : 1, y : 1, z : 1}, vertices, faces);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param triangleMeshBody R3.D3.RigidBody
|
||||
* @param rayscale Number
|
||||
* @param maxTriangleDistance Number
|
||||
* @param createCompoundShape Boolean
|
||||
* @param graphics R3.D3.Graphics
|
||||
* @param triangleMeshShapes R3.D3.Shape[]
|
||||
* @param createDebugView Boolean
|
||||
* @returns {R3.D3.RigidBody}
|
||||
* @constructor
|
||||
*/
|
||||
R3.D3.World.prototype.fixupTriangleMeshShape = function(
|
||||
triangleMeshBody,
|
||||
triangleMeshShapes,
|
||||
rayscale,
|
||||
maxTriangleDistance,
|
||||
createCompoundShape,
|
||||
graphics,
|
||||
createDebugView
|
||||
) {
|
||||
this.engine.isNotCannonThrow();
|
||||
|
||||
graphics.isNotThreeThrow();
|
||||
|
||||
if(rayscale == null || typeof rayscale == 'undefined' || rayscale == 0) {
|
||||
rayscale = 10;
|
||||
}
|
||||
|
||||
if(maxTriangleDistance == null || typeof maxTriangleDistance == 'undefined') {
|
||||
maxTriangleDistance = 13;
|
||||
}
|
||||
|
||||
var world = this.instance;
|
||||
|
||||
var raycastResult = new this.engine.instance.RaycastResult();
|
||||
|
||||
var brokenFaceIndicators = [];
|
||||
|
||||
var totalFaces = 0;
|
||||
var totalBrokenFaces = 0;
|
||||
var totalFixedFaces = 0;
|
||||
var fixedTriangleMeshObjects = [];
|
||||
|
||||
for(var i in triangleMeshShapes) {
|
||||
var trimesh = triangleMeshShapes[i].instance;
|
||||
|
||||
var brokenFaces = [];
|
||||
totalFaces += (trimesh.indices.length / 3);
|
||||
|
||||
for(var face = 0; face < trimesh.indices.length / 3; face++) {
|
||||
|
||||
var i0 = trimesh.indices[face * 3];
|
||||
var i1 = trimesh.indices[face * 3 + 1];
|
||||
var i2 = trimesh.indices[face * 3 + 2];
|
||||
|
||||
var triangleCenterPoint = new graphics.instance.Vector3()
|
||||
.add(new graphics.instance.Vector3(
|
||||
trimesh.vertices[i0 * 3],
|
||||
trimesh.vertices[i0 * 3 + 1],
|
||||
trimesh.vertices[i0 * 3 + 2])
|
||||
)
|
||||
.add(new graphics.instance.Vector3(
|
||||
trimesh.vertices[i1 * 3],
|
||||
trimesh.vertices[i1 * 3 + 1],
|
||||
trimesh.vertices[i1 * 3 + 2])
|
||||
)
|
||||
.add(new graphics.instance.Vector3(
|
||||
trimesh.vertices[i2 * 3],
|
||||
trimesh.vertices[i2 * 3 + 1],
|
||||
trimesh.vertices[i2 * 3 + 2])
|
||||
)
|
||||
.divideScalar(3);
|
||||
|
||||
var triangleNormal = new this.engine.instance.Vec3();
|
||||
trimesh.getNormal(face , triangleNormal);
|
||||
|
||||
var from = new this.engine.instance.Vec3(
|
||||
triangleCenterPoint.x + triangleNormal.x,
|
||||
triangleCenterPoint.y + triangleNormal.y,
|
||||
triangleCenterPoint.z + triangleNormal.z
|
||||
);
|
||||
|
||||
var to = new this.engine.instance.Vec3(
|
||||
from.x - triangleNormal.x * rayscale,
|
||||
from.y - triangleNormal.y * rayscale,
|
||||
from.z - triangleNormal.z * rayscale
|
||||
);
|
||||
|
||||
world.raycastClosest(from, to, {}, raycastResult);
|
||||
|
||||
// visualize results
|
||||
if(createDebugView){
|
||||
var graphicsGeometry = new graphics.instance.Geometry();
|
||||
var wireframeMesh = new graphics.instance.Mesh(
|
||||
graphicsGeometry,
|
||||
new graphics.instance.MeshBasicMaterial({
|
||||
color: 0xff0000,
|
||||
wireframe: true,
|
||||
opacity: 1
|
||||
})
|
||||
);
|
||||
|
||||
var arrow = new graphics.instance.ArrowHelper(
|
||||
new graphics.instance.Vector3(
|
||||
triangleNormal.x,
|
||||
triangleNormal.y,
|
||||
triangleNormal.z
|
||||
).normalize(),
|
||||
|
||||
new graphics.instance.Vector3(
|
||||
from.x,
|
||||
from.y,
|
||||
from.z
|
||||
),
|
||||
|
||||
rayscale / 2,
|
||||
raycastResult.hasHit ? new graphics.instance.Color(0, 1, 0)
|
||||
: new graphics.instance.Color(1, 0, 0)
|
||||
);
|
||||
|
||||
wireframeMesh.add( arrow );
|
||||
brokenFaceIndicators.push(wireframeMesh);
|
||||
}
|
||||
|
||||
if(!raycastResult.hasHit) {
|
||||
brokenFaces.push({
|
||||
faceIndex : face,
|
||||
|
||||
vertices : [
|
||||
new this.engine.instance.Vec3(
|
||||
trimesh.vertices[i0 * 3],
|
||||
trimesh.vertices[i0 * 3 + 1],
|
||||
trimesh.vertices[i0 * 3 + 2]
|
||||
),
|
||||
|
||||
new this.engine.instance.Vec3(
|
||||
trimesh.vertices[i1 * 3],
|
||||
trimesh.vertices[i1 * 3 + 1],
|
||||
trimesh.vertices[i1 * 3 + 2]
|
||||
),
|
||||
|
||||
new this.engine.instance.Vec3(
|
||||
trimesh.vertices[i2 * 3],
|
||||
trimesh.vertices[i2 * 3 + 1],
|
||||
trimesh.vertices[i2 * 3 + 2]
|
||||
)
|
||||
],
|
||||
|
||||
center : triangleCenterPoint,
|
||||
|
||||
parent : trimesh
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// fix up broken faces
|
||||
|
||||
var bFaceIndexed = {};
|
||||
for(var b = 0; b < brokenFaces.length; b++) {
|
||||
var brokenFace = brokenFaces[b];
|
||||
|
||||
if(brokenFace.marked) {
|
||||
continue;
|
||||
}
|
||||
|
||||
bFaceIndexed[b] = {
|
||||
indices : [],
|
||||
vertices : []
|
||||
};
|
||||
|
||||
var indicesAmount = bFaceIndexed[b].indices.length;
|
||||
|
||||
// add the current broken face itself to the array
|
||||
bFaceIndexed[b].indices.push(
|
||||
indicesAmount,
|
||||
indicesAmount + 1,
|
||||
indicesAmount + 2
|
||||
);
|
||||
|
||||
bFaceIndexed[b].vertices.push(
|
||||
brokenFace.vertices[0].x,
|
||||
brokenFace.vertices[0].y,
|
||||
brokenFace.vertices[0].z
|
||||
);
|
||||
|
||||
bFaceIndexed[b].vertices.push(
|
||||
brokenFace.vertices[1].x,
|
||||
brokenFace.vertices[1].y,
|
||||
brokenFace.vertices[1].z
|
||||
);
|
||||
|
||||
bFaceIndexed[b].vertices.push(
|
||||
brokenFace.vertices[2].x,
|
||||
brokenFace.vertices[2].y,
|
||||
brokenFace.vertices[2].z
|
||||
);
|
||||
|
||||
for(var bb = 0; bb < brokenFaces.length; bb++) {
|
||||
|
||||
if(bb == b) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var otherBrokenFace = brokenFaces[bb];
|
||||
|
||||
if(otherBrokenFace.marked) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(brokenFace.center.distanceTo(otherBrokenFace.center) <= maxTriangleDistance) {
|
||||
var indicesAmount = bFaceIndexed[b].indices.length;
|
||||
|
||||
bFaceIndexed[b].indices.push(
|
||||
indicesAmount,
|
||||
indicesAmount + 1,
|
||||
indicesAmount + 2
|
||||
);
|
||||
|
||||
bFaceIndexed[b].vertices.push(
|
||||
otherBrokenFace.vertices[0].x,
|
||||
otherBrokenFace.vertices[0].y,
|
||||
otherBrokenFace.vertices[0].z
|
||||
);
|
||||
|
||||
bFaceIndexed[b].vertices.push(
|
||||
otherBrokenFace.vertices[1].x,
|
||||
otherBrokenFace.vertices[1].y,
|
||||
otherBrokenFace.vertices[1].z
|
||||
);
|
||||
|
||||
bFaceIndexed[b].vertices.push(
|
||||
otherBrokenFace.vertices[2].x,
|
||||
otherBrokenFace.vertices[2].y,
|
||||
otherBrokenFace.vertices[2].z
|
||||
);
|
||||
|
||||
otherBrokenFace.marked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Decide if we want to create new rigiwyd bodies, or create a compound mesh
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
for(var e in bFaceIndexed) {
|
||||
var element = bFaceIndexed[e];
|
||||
|
||||
var shape = new R3.D3.Shape(this.engine, R3.D3.Shape.SHAPE_TYPE_TRIMESH, { x : 1, y : 1, z : 1 }, element.vertices, element.indices);
|
||||
|
||||
if(createCompoundShape) {
|
||||
triangleMeshBody.addShape(shape);
|
||||
} else {
|
||||
|
||||
var body = new R3.D3.RigidBody(this.engine, 0, 12);
|
||||
|
||||
//TODO: this is just a hack.
|
||||
body.instance.collisionFilterGroup = 1 | 2; // puts this body in two groups.
|
||||
|
||||
body.addShape(shape);
|
||||
this.addRigidBody(body);
|
||||
}
|
||||
|
||||
fixedTriangleMeshObjects.push(shape);
|
||||
totalFixedFaces += element.indices.length / 3;
|
||||
}
|
||||
|
||||
// TODO: remove duplicate indices
|
||||
/*trimesh.updateNormals();
|
||||
trimesh.updateEdges();
|
||||
trimesh.updateTree();
|
||||
trimesh.updateAABB();
|
||||
trimesh.updateBoundingSphereRadius();*/
|
||||
|
||||
// map faceIndex to flat face index (faceIndex * 3) +0, 1, 2 -> triangle indices
|
||||
console.log("i = " + i, brokenFaces);
|
||||
totalBrokenFaces += brokenFaces.length;
|
||||
}
|
||||
|
||||
console.log("total faces", totalFaces);
|
||||
console.log("total broken faces", totalBrokenFaces);
|
||||
console.log("broken faces in percent", (totalBrokenFaces / totalFaces) * 100);
|
||||
console.log("total fixed faces", totalFixedFaces);
|
||||
console.log("fixed triangle mesh shapes", fixedTriangleMeshObjects.length);
|
||||
|
||||
return {
|
||||
brokenFaceIndicators : brokenFaceIndicators,
|
||||
fixedTriangleMeshShapes : fixedTriangleMeshObjects
|
||||
};
|
||||
};
|
|
@ -0,0 +1,13 @@
|
|||
/**
|
||||
* Runtime Dom
|
||||
* @constructor
|
||||
* @param document DOM Document
|
||||
* @param window DOM Window
|
||||
*/
|
||||
R3.Dom = function(
|
||||
document,
|
||||
window
|
||||
) {
|
||||
this.document = document;
|
||||
this.window = window;
|
||||
};
|
|
@ -0,0 +1,116 @@
|
|||
/**
|
||||
* R3.GraphicsRuntime.Impact
|
||||
* @param apiGraphicsRuntimeImpact
|
||||
* @constructor
|
||||
*/
|
||||
R3.GraphicsRuntime.Impact = function(
|
||||
apiGraphicsRuntimeImpact
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiGraphicsRuntimeImpact)) {
|
||||
apiGraphicsRuntimeImpact = {
|
||||
graphicsType : R3.API.GraphicsRuntime.GRAPHICS_TYPE_IMPACT_JS
|
||||
};
|
||||
}
|
||||
|
||||
R3.API.GraphicsRuntime.Impact.call(
|
||||
this,
|
||||
apiGraphicsRuntimeImpact
|
||||
);
|
||||
|
||||
R3.GraphicsRuntime.call(
|
||||
this,
|
||||
this
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
R3.GraphicsRuntime.Impact.prototype = Object.create(R3.GraphicsRuntime.prototype);
|
||||
R3.GraphicsRuntime.Impact.prototype.constructor = R3.GraphicsRuntime.Impact;
|
||||
|
||||
/**
|
||||
* Create R3.GraphicsRuntime.Impact Instance
|
||||
* @returns {*}
|
||||
*/
|
||||
R3.GraphicsRuntime.Impact.prototype.createInstance = function() {
|
||||
|
||||
this.instance = ig;
|
||||
|
||||
/**
|
||||
* We override the game load to lookup the canvas from our r3 and not the DOM, since our canvas
|
||||
* does not necessarily live inside the DOM
|
||||
*/
|
||||
ig.System.inject({
|
||||
init : function( canvasId, fps, width, height, scale ) {
|
||||
this.fps = fps;
|
||||
|
||||
this.clock = new ig.Timer();
|
||||
this.canvas = R3.EntityManager.Instance.findComponentById(canvasId).instance;
|
||||
this.resize( width, height, scale );
|
||||
this.context = this.canvas.getContext('2d');
|
||||
|
||||
this.getDrawPos = ig.System.drawMode;
|
||||
|
||||
// Automatically switch to crisp scaling when using a scale
|
||||
// other than 1
|
||||
if( this.scale !== 1 ) {
|
||||
ig.System.scaleMode = ig.System.SCALE.CRISP;
|
||||
}
|
||||
|
||||
ig.System.scaleMode( this.canvas, this.context );
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* We override image loading to specify that it loads from cross-origins
|
||||
*/
|
||||
ig.Image.inject({
|
||||
load: function( loadCallback ) {
|
||||
if( this.loaded ) {
|
||||
if( loadCallback ) {
|
||||
loadCallback( this.path, true );
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if( !this.loaded && ig.ready ) {
|
||||
this.loadCallback = loadCallback || null;
|
||||
|
||||
this.data = new Image();
|
||||
this.data.crossOrigin = 'anonymous';
|
||||
this.data.onload = this.onload.bind(this);
|
||||
this.data.onerror = this.onerror.bind(this);
|
||||
this.data.src = ig.prefix + this.path + ig.nocache;
|
||||
}
|
||||
else {
|
||||
ig.addResource( this );
|
||||
}
|
||||
|
||||
ig.Image.cache[this.path] = this;
|
||||
}
|
||||
});
|
||||
|
||||
R3.GraphicsRuntime.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update GraphicsRuntime.Impact Instance
|
||||
*/
|
||||
R3.GraphicsRuntime.Impact.prototype.updateInstance = function(property) {
|
||||
|
||||
R3.GraphicsRuntime.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {R3.API.GraphicsRuntime.Impact}
|
||||
*/
|
||||
R3.GraphicsRuntime.Impact.prototype.toApiObject = function() {
|
||||
|
||||
var apiGraphicsRuntime = R3.GraphicsRuntime.prototype.toApiObject.call(this);
|
||||
|
||||
var apiGraphicsRuntimeImpact = new R3.API.GraphicsRuntime.Impact(
|
||||
apiGraphicsRuntime
|
||||
);
|
||||
|
||||
return apiGraphicsRuntimeImpact;
|
||||
};
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* Matrix 3 Maths
|
||||
* @param row0 R3.API.Vector3
|
||||
* @param row1 R3.API.Vector3
|
||||
* @param row2 R3.API.Vector3
|
||||
* @constructor
|
||||
*/
|
||||
R3.Matrix3 = function(
|
||||
row0,
|
||||
row1,
|
||||
row2
|
||||
) {
|
||||
this.identity();
|
||||
|
||||
if (row0) {
|
||||
this.rows[0] = row0;
|
||||
}
|
||||
|
||||
if (row1) {
|
||||
this.rows[1] = row1;
|
||||
}
|
||||
|
||||
if (row2) {
|
||||
this.rows[2] = row2;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set matrix to identity
|
||||
*/
|
||||
R3.Matrix3.prototype.identity = function () {
|
||||
this.rows = [
|
||||
new R3.API.Vector3(1, 0, 0),
|
||||
new R3.API.Vector3(0, 1, 0),
|
||||
new R3.API.Vector3(0, 0, 1)
|
||||
];
|
||||
};
|
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* Runtime vector2 for updating instance objects
|
||||
* @param apiNumber R3.API.Number
|
||||
* @param parentObject
|
||||
* @constructor
|
||||
*/
|
||||
R3.Number = function(
|
||||
apiNumber,
|
||||
parentObject
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiNumber)) {
|
||||
apiNumber = {};
|
||||
}
|
||||
|
||||
R3.API.Number.call(
|
||||
this,
|
||||
apiNumber
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(parentObject)) {
|
||||
parentObject = null;
|
||||
}
|
||||
this.parentObject = parentObject;
|
||||
|
||||
this.createInstance();
|
||||
};
|
||||
|
||||
R3.Number.prototype = Object.create(R3.API.Number.prototype);
|
||||
R3.Number.prototype.constructor = R3.Number;
|
||||
|
||||
|
||||
/**
|
||||
* Creates an instance vector2
|
||||
* @returns {*}
|
||||
*/
|
||||
R3.Number.prototype.createInstance = function() {
|
||||
this.instance = {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the instance vector, calls updateInstance on the parent object
|
||||
*/
|
||||
R3.Number.prototype.updateInstance = function(property, parentProperty) {
|
||||
|
||||
if (property === 'value') {
|
||||
if (this.parentObject && this.parentObject.updateInstance) {
|
||||
this.parentObject.updateInstance(parentProperty);
|
||||
}
|
||||
}
|
||||
|
||||
if (property === 'grain') {
|
||||
console.warn('todo: update number instance grain');
|
||||
}
|
||||
|
||||
if (property === 'min') {
|
||||
console.warn('todo: update number instance min');
|
||||
}
|
||||
|
||||
if (property === 'max') {
|
||||
console.warn('todo: update number instance max');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Converts runtime vector to API Vector
|
||||
* @returns {R3.API.Number}
|
||||
*/
|
||||
R3.Number.prototype.toApiObject = function() {
|
||||
return new R3.API.Number(
|
||||
this.value,
|
||||
this.grain,
|
||||
this.min,
|
||||
this.max
|
||||
);
|
||||
};
|
|
@ -0,0 +1,270 @@
|
|||
/**
|
||||
* R3.RenderConfiguration
|
||||
* @param graphics
|
||||
* @param apiRenderConfiguration R3.API.RenderConfiguration
|
||||
* @constructor
|
||||
*/
|
||||
R3.RenderConfiguration = function (
|
||||
graphics,
|
||||
apiRenderConfiguration
|
||||
) {
|
||||
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiRenderConfiguration)) {
|
||||
apiRenderConfiguration = {};
|
||||
}
|
||||
|
||||
R3.API.RenderConfiguration.call(
|
||||
this,
|
||||
apiRenderConfiguration.id,
|
||||
apiRenderConfiguration.name,
|
||||
apiRenderConfiguration.parentEntity,
|
||||
apiRenderConfiguration.logicalSize,
|
||||
apiRenderConfiguration.aspectRatio,
|
||||
apiRenderConfiguration.scaleMode,
|
||||
apiRenderConfiguration.activeCamera,
|
||||
apiRenderConfiguration.activeScene,
|
||||
apiRenderConfiguration.activeScenes,
|
||||
apiRenderConfiguration.activeRenderer,
|
||||
apiRenderConfiguration.activeComposer,
|
||||
apiRenderConfiguration.activeEffect,
|
||||
apiRenderConfiguration.enableComposer,
|
||||
apiRenderConfiguration.enableEffect,
|
||||
apiRenderConfiguration.defaultMode
|
||||
);
|
||||
|
||||
this.logicalSize = new R3.Vector2(
|
||||
this.graphics,
|
||||
this.logicalSize,
|
||||
this
|
||||
);
|
||||
|
||||
R3.Component.call(
|
||||
this,
|
||||
{
|
||||
'activeCamera' : R3.D3.Camera,
|
||||
'activeScene' : R3.D3.Scene,
|
||||
'activeScenes' : [R3.D3.Scene],
|
||||
'activeRenderer' : R3.Renderer,
|
||||
'activeComposer' : R3.D3.Composer,
|
||||
'activeEffect' : R3.D3.Effect
|
||||
}
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
R3.RenderConfiguration.prototype = Object.create(R3.Component.prototype);
|
||||
R3.RenderConfiguration.prototype.constructor = R3.RenderConfiguration;
|
||||
|
||||
/**
|
||||
* Create RenderConfiguration Instance
|
||||
* @returns {*}
|
||||
*/
|
||||
R3.RenderConfiguration.prototype.createInstance = function() {
|
||||
|
||||
this.instance = {};
|
||||
|
||||
R3.Component.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update RenderConfiguration Instance
|
||||
*/
|
||||
R3.RenderConfiguration.prototype.updateInstance = function(property) {
|
||||
|
||||
if (
|
||||
property === 'logicalSize' ||
|
||||
property === 'aspectRatio' ||
|
||||
property === 'scaleMode'
|
||||
) {
|
||||
|
||||
console.log('todo: implement fixed aspect ratios for different scale modes');
|
||||
|
||||
if (
|
||||
R3.Utils.Defined(this.activeCamera) &&
|
||||
R3.Utils.Defined(this.activeCamera.instance)
|
||||
) {
|
||||
|
||||
/**
|
||||
* For now - just use normal aspect ratio
|
||||
*/
|
||||
R3.Event.Emit(
|
||||
R3.Event.GET_WINDOW_SIZE,
|
||||
{},
|
||||
function(data) {
|
||||
|
||||
if (data.width === data.height) {
|
||||
console.log('square');
|
||||
}
|
||||
|
||||
if (data.width > data.height) {
|
||||
console.log('landscape');
|
||||
}
|
||||
|
||||
if (data.width < data.height) {
|
||||
console.log('portrait');
|
||||
}
|
||||
|
||||
this.activeCamera.aspect = data.width / data.height;
|
||||
this.activeCamera.updateInstance('aspect');
|
||||
|
||||
}.bind(this)
|
||||
)
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'activeCamera') {
|
||||
|
||||
if (
|
||||
R3.Utils.Defined(this.activeCamera) &&
|
||||
R3.Utils.Defined(this.activeCamera.instance)
|
||||
) {
|
||||
/**
|
||||
* Update the aspect ratio for the active camera
|
||||
*/
|
||||
this.updateInstance('aspectRatio');
|
||||
|
||||
R3.EntityManager.Instance.queryComponents(R3.Component.PASS_RENDER).map(
|
||||
function(renderPass) {
|
||||
renderPass.camera = this.activeCamera;
|
||||
renderPass.updateInstance('camera');
|
||||
}.bind(this)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
property === 'activeScene' ||
|
||||
property === 'activeScenes' ||
|
||||
property === 'activeRenderer'
|
||||
) {
|
||||
console.log('todo: active component update');
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
property === 'activeComposer'
|
||||
) {
|
||||
|
||||
if (this.activeComposer === null) {
|
||||
if (this.enableComposer) {
|
||||
console.warn('no composer active - nothing will render');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
this.activeComposer.passes.length === 0
|
||||
) {
|
||||
console.warn('this composer has no passes - nothing will render when this composer is enabled');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
property === 'activeEffect'
|
||||
) {
|
||||
|
||||
if (this.activeEffect === null) {
|
||||
if (this.enableEffect) {
|
||||
console.warn('no effects active - nothing will render');
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
property === 'enableComposer'
|
||||
) {
|
||||
|
||||
if (this.enableComposer) {
|
||||
if (this.enableEffect) {
|
||||
this.enableComposer = false;
|
||||
console.warn('Only one of effect or composer can be enabled, not both at the same time');
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
this.activeComposer === null
|
||||
) {
|
||||
console.warn('no composer active - nothing will render');
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
this.activeComposer.passes.length === 0
|
||||
) {
|
||||
console.warn('this composer has no passes - nothing will render');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
property === 'enableEffect'
|
||||
) {
|
||||
|
||||
if (this.enableEffect) {
|
||||
if (this.enableComposer) {
|
||||
this.enableEffect = false;
|
||||
console.warn('Only one of effect or composer can be enabled, not both at the same time');
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.activeEffect === null) {
|
||||
console.warn('no effect active - nothing will render');
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
property === 'defaultMode'
|
||||
) {
|
||||
console.log('todo: defaultMode change');
|
||||
return;
|
||||
}
|
||||
|
||||
R3.Component.prototype.updateInstance.call(this, property);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {R3.API.RenderConfiguration}
|
||||
*/
|
||||
R3.RenderConfiguration.prototype.toApiObject = function() {
|
||||
|
||||
var apiRenderConfiguration = new R3.API.RenderConfiguration(
|
||||
this.id,
|
||||
this.name,
|
||||
R3.Utils.IdOrNull(this.parentEntity),
|
||||
this.logicalSize.toApiObject(),
|
||||
this.aspectRatio,
|
||||
this.scaleMode,
|
||||
R3.Utils.IdOrNull(this.activeCamera),
|
||||
R3.Utils.IdOrNull(this.activeScene),
|
||||
this.activeScenes.map(
|
||||
function(activeScene) {
|
||||
return R3.Utils.IdOrNull(activeScene);
|
||||
}
|
||||
),
|
||||
R3.Utils.IdOrNull(this.activeRenderer),
|
||||
R3.Utils.IdOrNull(this.activeComposer),
|
||||
R3.Utils.IdOrNull(this.activeEffect),
|
||||
this.enableComposer,
|
||||
this.enableEffect,
|
||||
this.defaultMode
|
||||
);
|
||||
|
||||
return apiRenderConfiguration;
|
||||
};
|
|
@ -0,0 +1,540 @@
|
|||
/**
|
||||
* R3.Renderer.D3.Target
|
||||
* @param graphics R3.Runtime.Graphics
|
||||
* @param apiRendererD3 R3.API.Renderer.D3
|
||||
* @constructor
|
||||
*/
|
||||
R3.Renderer.D3.Target = function(
|
||||
graphics,
|
||||
apiRendererD3
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiRendererD3)) {
|
||||
apiRendererD3 = {
|
||||
rendererType : R3.API.Renderer.RENDERER_TYPE_3D
|
||||
};
|
||||
}
|
||||
|
||||
R3.API.Renderer.D3.call(
|
||||
this,
|
||||
apiRendererD3,
|
||||
apiRendererD3.renderMode,
|
||||
apiRendererD3.autoClear,
|
||||
apiRendererD3.autoClearColor,
|
||||
apiRendererD3.autoClearDepth,
|
||||
apiRendererD3.autoClearStencil,
|
||||
apiRendererD3.gammaFactor,
|
||||
apiRendererD3.gammaInput,
|
||||
apiRendererD3.gammaOutput,
|
||||
apiRendererD3.maxMorphTargets,
|
||||
apiRendererD3.maxMorphNormals,
|
||||
apiRendererD3.physicallyCorrectLights,
|
||||
apiRendererD3.shadowMapEnabled,
|
||||
apiRendererD3.shadowMapAutoUpdate,
|
||||
apiRendererD3.shadowMapNeedsUpdate,
|
||||
apiRendererD3.shadowMapType,
|
||||
apiRendererD3.shadowMapRenderReverseSided,
|
||||
apiRendererD3.shadowMapRenderSingleSided,
|
||||
apiRendererD3.sortObjects,
|
||||
apiRendererD3.toneMapping,
|
||||
apiRendererD3.toneMappingExposure,
|
||||
apiRendererD3.toneMappingWhitePoint,
|
||||
apiRendererD3.premultipliedAlpha,
|
||||
apiRendererD3.antialias,
|
||||
apiRendererD3.stencil,
|
||||
apiRendererD3.preserveDrawingBuffer,
|
||||
apiRendererD3.depth,
|
||||
apiRendererD3.logarithmicDepthBuffer,
|
||||
apiRendererD3.localClippingEnabled,
|
||||
apiRendererD3.renderTarget,
|
||||
apiRendererD3.clippingPlanes,
|
||||
apiRendererD3.clearColor,
|
||||
apiRendererD3.viewports,
|
||||
apiRendererD3.alpha,
|
||||
apiRendererD3.opacity,
|
||||
apiRendererD3.composer,
|
||||
apiRendererD3.effect,
|
||||
apiRendererD3.enableComposer,
|
||||
apiRendererD3.enableEffect
|
||||
);
|
||||
|
||||
if (this.renderTarget instanceof R3.D3.API.RenderTarget) {
|
||||
this.renderTarget = R3.Component.ConstructFromObject(this.renderTarget);
|
||||
}
|
||||
|
||||
this.clippingPlanes = this.clippingPlanes.reduce(
|
||||
function(result, clippingPlane) {
|
||||
|
||||
if (clippingPlane instanceof R3.API.Plane) {
|
||||
clippingPlane = R3.Component.ConstructFromObject(clippingPlane);
|
||||
}
|
||||
|
||||
result.push(clippingPlane);
|
||||
|
||||
return result;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
this.clearColor = new R3.Color(
|
||||
this.graphics,
|
||||
this.clearColor,
|
||||
this
|
||||
);
|
||||
|
||||
this.viewports = this.viewports.reduce(
|
||||
function(result, viewport) {
|
||||
|
||||
if (viewport instanceof R3.D3.API.Viewport) {
|
||||
viewport = R3.Component.ConstructFromObject(viewport);
|
||||
}
|
||||
|
||||
result.push(viewport);
|
||||
|
||||
return result;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
if (this.composer instanceof R3.D3.API.Composer) {
|
||||
this.composer = R3.Component.ConstructFromObject(this.composer);
|
||||
}
|
||||
|
||||
if (this.effect instanceof R3.D3.API.Effect) {
|
||||
this.effect = R3.Component.ConstructFromObject(this.effect);
|
||||
}
|
||||
|
||||
R3.Renderer.call(
|
||||
this,
|
||||
this.graphics,
|
||||
this
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
R3.Renderer.D3.Target.prototype = Object.create(R3.Renderer.D3.prototype);
|
||||
R3.Renderer.D3.Target.prototype.constructor = R3.Renderer.D3.Target;
|
||||
|
||||
R3.Renderer.D3.Target.prototype.getSize = function() {
|
||||
return {
|
||||
width : this.target.width,
|
||||
height : this.target.height
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create R3.Renderer.D3 Instance
|
||||
* @returns {*}
|
||||
*/
|
||||
R3.Renderer.D3.prototype.createInstance = function() {
|
||||
|
||||
if (
|
||||
R3.Utils.UndefinedOrNull(this.canvas) ||
|
||||
R3.Utils.UndefinedOrNull(this.canvas.instance)
|
||||
) {
|
||||
console.warn('no canvas instance');
|
||||
return;
|
||||
}
|
||||
|
||||
this.instance = new THREE.WebGLRenderer(
|
||||
{
|
||||
canvas : this.canvas.instance,
|
||||
alpha : this.alpha,
|
||||
premultipliedAlpha : this.premultipliedAlpha,
|
||||
antialias : this.antialias,
|
||||
stencil : this.stencil,
|
||||
preserveDrawingBuffer : this.preserveDrawingBuffer,
|
||||
depth : this.depth,
|
||||
logarithmicDepthBuffer : this.logarithmicDepthBuffer
|
||||
}
|
||||
);
|
||||
|
||||
this.instance.setPixelRatio(window.devicePixelRatio);
|
||||
|
||||
this.instance.autoClear = this.autoClear;
|
||||
this.instance.autoClearColor = this.autoClearColor;
|
||||
this.instance.autoClearDepth = this.autoClearDepth;
|
||||
this.instance.autoClearStencil = this.autoClearStencil;
|
||||
|
||||
this.instance.gammaFactor = this.gammaFactor;
|
||||
this.instance.gammaInput = this.gammaInput;
|
||||
this.instance.gammaOutput = this.gammaOutput;
|
||||
|
||||
this.instance.maxMorphTargets = this.maxMorphTargets;
|
||||
this.instance.maxMorphNormals = this.maxMorphNormals;
|
||||
|
||||
this.instance.physicallyCorrectLights = this.physicallyCorrectLights;
|
||||
|
||||
this.instance.shadowMap.enabled = this.shadowMapEnabled;
|
||||
this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate;
|
||||
this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate;
|
||||
this.instance.shadowMap.type = this.shadowMapType;
|
||||
this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided;
|
||||
this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided;
|
||||
|
||||
this.instance.sortObjects = this.sortObjects;
|
||||
|
||||
this.instance.toneMapping = this.toneMapping;
|
||||
this.instance.toneMappingExposure = this.toneMappingExposure;
|
||||
this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint;
|
||||
|
||||
this.instance.premultipliedAlpha = this.premultipliedAlpha;
|
||||
|
||||
this.instance.localClippingEnabled = this.localClippingEnabled;
|
||||
|
||||
if (this.renderTarget) {
|
||||
this.instance.setRenderTarget(this.renderTarget.instance);
|
||||
}
|
||||
|
||||
if (this.clippingPlanes.length > 0) {
|
||||
this.instance.clippingPlanes = this.clippingPlanes.map(
|
||||
function(clippingPlane) {
|
||||
return clippingPlane.instance;
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
this.instance.setClearColor(
|
||||
new THREE.Color(
|
||||
this.clearColor.r,
|
||||
this.clearColor.g,
|
||||
this.clearColor.b
|
||||
),
|
||||
this.opacity
|
||||
);
|
||||
|
||||
R3.Renderer.prototype.createInstance.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update Renderer.D3 Instance
|
||||
*/
|
||||
R3.Renderer.D3.prototype.updateInstance = function(property) {
|
||||
|
||||
if (!property) {
|
||||
throw new Error('no renderer property');
|
||||
}
|
||||
|
||||
if (!this.instance) {
|
||||
throw new Error('no renderer instance');
|
||||
}
|
||||
|
||||
if (property === 'renderMode') {
|
||||
console.log('render mode change');
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'autoClear') {
|
||||
this.instance.autoClear = this.autoClear;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'autoClearColor') {
|
||||
this.instance.autoClearColor = this.autoClearColor;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'autoClearDepth') {
|
||||
this.instance.autoClearDepth = this.autoClearDepth;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'autoClearStencil') {
|
||||
this.instance.autoClearStencil = this.autoClearStencil;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'gammaFactor') {
|
||||
this.instance.gammaFactor = this.gammaFactor;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'gammaInput') {
|
||||
this.instance.gammaInput = this.gammaInput;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'gammaOutput') {
|
||||
this.instance.gammaOutput = this.gammaOutput;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'maxMorphTargets') {
|
||||
this.instance.maxMorphTargets = this.maxMorphTargets;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'maxMorphNormals') {
|
||||
this.instance.maxMorphNormals = this.maxMorphNormals;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'physicallyCorrectLights') {
|
||||
this.instance.physicallyCorrectLights = this.physicallyCorrectLights;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'shadowMapEnabled') {
|
||||
this.instance.shadowMap.enabled = this.shadowMapEnabled;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'shadowMapAutoUpdate') {
|
||||
this.instance.shadowMap.autoUpdate = this.shadowMapAutoUpdate;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'shadowMapNeedsUpdate') {
|
||||
this.instance.shadowMap.needsUpdate = this.shadowMapNeedsUpdate;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'shadowMapType') {
|
||||
this.instance.shadowMap.type = this.shadowMapType;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'shadowMapRenderReverseSided') {
|
||||
this.instance.shadowMap.renderReverseSided = this.shadowMapRenderReverseSided;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'shadowMapRenderSingleSided') {
|
||||
this.instance.shadowMap.renderSingleSided = this.shadowMapRenderSingleSided;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'sortObjects') {
|
||||
this.instance.sortObjects = this.sortObjects;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'toneMapping') {
|
||||
this.instance.toneMapping = this.toneMapping;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'toneMappingExposure') {
|
||||
this.instance.toneMappingExposure = this.toneMappingExposure;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'toneMappingWhitePoint') {
|
||||
this.instance.toneMappingWhitePoint = this.toneMappingWhitePoint;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'premultipliedAlpha') {
|
||||
this.instance.premultipliedAlpha = this.premultipliedAlpha;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'premultipliedAlpha') {
|
||||
this.instance.premultipliedAlpha = this.premultipliedAlpha;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'antialias') {
|
||||
this.instance.antialias = this.antialias;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'stencil') {
|
||||
this.instance.stencil = this.stencil;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'preserveDrawingBuffer') {
|
||||
this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'depth') {
|
||||
this.instance.depth = this.depth;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'logarithmicDepthBuffer') {
|
||||
this.instance.logarithmicDepthBuffer = this.logarithmicDepthBuffer;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'localClippingEnabled') {
|
||||
this.instance.localClippingEnabled = this.localClippingEnabled;
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'canvas') {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(this.instance)) {
|
||||
this.createInstance();
|
||||
} else {
|
||||
console.warn('experimental canvas change for renderer');
|
||||
this.instance.dispose();
|
||||
this.createInstance();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'renderTarget') {
|
||||
|
||||
if (
|
||||
R3.Utils.Defined(this.instance) &&
|
||||
R3.Utils.Defined(this.renderTarget) &&
|
||||
R3.Utils.Defined(this.renderTarget.instance)
|
||||
) {
|
||||
this.instance.setRenderTarget(this.renderTarget.instance);
|
||||
console.log('updated render target on render instance');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'clippingPlanes') {
|
||||
console.warn('todo: clipping planes change');
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
property === 'clearColor' ||
|
||||
property === 'opacity'
|
||||
) {
|
||||
this.instance.setClearColor(
|
||||
new THREE.Color(
|
||||
this.clearColor.r,
|
||||
this.clearColor.g,
|
||||
this.clearColor.b
|
||||
),
|
||||
this.opacity
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (property === 'viewports') {
|
||||
console.warn('todo: viewports change');
|
||||
}
|
||||
|
||||
if (property === 'alpha') {
|
||||
this.instance.alpha = this.alpha;
|
||||
return;
|
||||
}
|
||||
|
||||
R3.Renderer.prototype.updateInstance.call(this, property);
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper for clear()
|
||||
*/
|
||||
R3.Renderer.D3.prototype.clear = function() {
|
||||
return this.instance.clear();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Convenience function to set viewport
|
||||
* @param x
|
||||
* @param y
|
||||
* @param width
|
||||
* @param height
|
||||
*/
|
||||
R3.Renderer.D3.prototype.setViewport = function(
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height
|
||||
) {
|
||||
this.instance.setViewport(
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders to this.renderTarget
|
||||
* @param scene
|
||||
* @param camera
|
||||
*/
|
||||
R3.Renderer.D3.prototype.renderToTarget = function(scene, camera) {
|
||||
|
||||
this.instance.render(
|
||||
scene.instance,
|
||||
camera.instance,
|
||||
this.renderTarget.instance
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders normally
|
||||
* @param scene
|
||||
* @param camera
|
||||
*/
|
||||
R3.Renderer.D3.prototype.render = function(scene, camera) {
|
||||
this.instance.render(
|
||||
scene.instance,
|
||||
camera.instance
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {R3.API.Renderer.D3}
|
||||
*/
|
||||
R3.Renderer.D3.prototype.toApiObject = function() {
|
||||
|
||||
var apiRenderer = R3.Renderer.prototype.toApiObject.call(this);
|
||||
|
||||
var apiRendererD3 = new R3.API.Renderer.D3(
|
||||
apiRenderer,
|
||||
this.renderMode,
|
||||
this.autoClear,
|
||||
this.autoClearColor,
|
||||
this.autoClearDepth,
|
||||
this.autoClearStencil,
|
||||
this.gammaFactor,
|
||||
this.gammaInput,
|
||||
this.gammaOutput,
|
||||
this.maxMorphTargets,
|
||||
this.maxMorphNormals,
|
||||
this.physicallyCorrectLights,
|
||||
this.shadowMapEnabled,
|
||||
this.shadowMapAutoUpdate,
|
||||
this.shadowMapNeedsUpdate,
|
||||
this.shadowMapType,
|
||||
this.shadowMapRenderReverseSided,
|
||||
this.shadowMapRenderSingleSided,
|
||||
this.sortObjects,
|
||||
this.toneMapping,
|
||||
this.toneMappingExposure,
|
||||
this.toneMappingWhitePoint,
|
||||
this.premultipliedAlpha,
|
||||
this.antialias,
|
||||
this.stencil,
|
||||
this.preserveDrawingBuffer,
|
||||
this.depth,
|
||||
this.logarithmicDepthBuffer,
|
||||
this.localClippingEnabled,
|
||||
R3.Utils.IdOrNull(this.renderTarget),
|
||||
this.clippingPlanes.map(
|
||||
function(clippingPlane){
|
||||
return R3.Utils.IdOrNull(clippingPlane);
|
||||
}
|
||||
),
|
||||
this.clearColor.toApiObject(),
|
||||
this.viewports.map(
|
||||
function(viewport){
|
||||
return R3.Utils.IdOrNull(viewport);
|
||||
}
|
||||
),
|
||||
this.alpha,
|
||||
this.opacity
|
||||
);
|
||||
|
||||
return apiRendererD3;
|
||||
};
|
|
@ -0,0 +1,237 @@
|
|||
var gulp = require('gulp');
|
||||
var concat = require('gulp-concat');
|
||||
var sort = require('gulp-sort');
|
||||
var minify = require('gulp-minify');
|
||||
var replace = require('gulp-string-replace');
|
||||
|
||||
gulp.task('build', build);
|
||||
gulp.task('monitor', monitor);
|
||||
|
||||
//__API_COMPONENT__
|
||||
var code = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n';
|
||||
code += '\t\tapiComponent = {};\n';
|
||||
code += '\t}\n';
|
||||
code += '\n';
|
||||
code += '\tR3.API.Component.call(\n';
|
||||
code += '\t\tthis,\n';
|
||||
code += '\t\tapiComponent.parent,\n';
|
||||
code += '\t\tapiComponent.id,\n';
|
||||
code += '\t\tapiComponent.name,\n';
|
||||
code += '\t\tapiComponent.register,\n';
|
||||
code += '\t\tapiComponent.selected,\n';
|
||||
code += '\t\tapiComponent.isPublic\n';
|
||||
code += '\t)\n';
|
||||
code += '\n';
|
||||
code += '\tif (R3.Utils.UndefinedOrNull(apiComponent.guiInfo)) {\n';
|
||||
code += '\t\tapiComponent.guiInfo = {};\n';
|
||||
code += '\t}\n';
|
||||
code += '\tthis.guiInfo = apiComponent.guiInfo;\n';
|
||||
|
||||
//__DEFINE_API_COMPONENT__
|
||||
var code1 = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n';
|
||||
code1 += '\t\tapiComponent = {};\n';
|
||||
code1 += '\t}\n';
|
||||
code1 += '\n';
|
||||
code1 += '\tif (R3.Utils.UndefinedOrNull(apiComponent.guiInfo)) {\n';
|
||||
code1 += '\t\tapiComponent.guiInfo = {};\n';
|
||||
code1 += '\t}\n';
|
||||
code1 += '\tthis.guiInfo = apiComponent.guiInfo;\n';
|
||||
|
||||
var code2 = 'R3.D3.API.Geometry.Buffer.call(\n';
|
||||
code2 += '\t\tthis,\n';
|
||||
code2 += '\t\tapiComponent\n';
|
||||
code2 += '\t)';
|
||||
|
||||
var code3 = 'R3.D3.API.Geometry.Normal.call(\n';
|
||||
code3 += '\t\tthis,\n';
|
||||
code3 += '\t\tapiComponent\n';
|
||||
code3 += '\t)';
|
||||
|
||||
var code4 = 'R3.D3.API.Material.call(\n';
|
||||
code4 += '\t\tthis,\n';
|
||||
code4 += '\t\tapiComponent\n';
|
||||
code4 += '\t)';
|
||||
|
||||
var code5 = 'if (R3.Utils.UndefinedOrNull(apiTexture)) {\n';
|
||||
code5 += '\t\tapiTexture = {};\n';
|
||||
code5 += '\t}\n';
|
||||
code5 += '\n';
|
||||
code5 += '\tR3.D3.API.Texture.call(\n';
|
||||
code5 += '\t\tthis,\n';
|
||||
code5 += '\t\tapiTexture,\n';
|
||||
code5 += '\t\tapiTexture.parentMaterials,\n';
|
||||
code5 += '\t\tapiTexture.mipmaps,\n';
|
||||
code5 += '\t\tapiTexture.mapping,\n';
|
||||
code5 += '\t\tapiTexture.wrapS,\n';
|
||||
code5 += '\t\tapiTexture.wrapT,\n';
|
||||
code5 += '\t\tapiTexture.magFilter,\n';
|
||||
code5 += '\t\tapiTexture.minFilter,\n';
|
||||
code5 += '\t\tapiTexture.anisotropy,\n';
|
||||
code5 += '\t\tapiTexture.format,\n';
|
||||
code5 += '\t\tapiTexture.storageType,\n';
|
||||
code5 += '\t\tapiTexture.offset,\n';
|
||||
code5 += '\t\tapiTexture.repeat,\n';
|
||||
code5 += '\t\tapiTexture.rotation,\n';
|
||||
code5 += '\t\tapiTexture.center,\n';
|
||||
code5 += '\t\tapiTexture.matrixAutoUpdate,\n';
|
||||
code5 += '\t\tapiTexture.generateMipMaps,\n';
|
||||
code5 += '\t\tapiTexture.premultiplyAlpha,\n';
|
||||
code5 += '\t\tapiTexture.flipY,\n';
|
||||
code5 += '\t\tapiTexture.unpackAlignment,\n';
|
||||
code5 += '\t\tapiTexture.encoding,\n';
|
||||
code5 += '\t\tapiTexture.version,\n';
|
||||
code5 += '\t\tapiTexture.animated,\n';
|
||||
code5 += '\t\tapiTexture.reverseAnimation,\n';
|
||||
code5 += '\t\tapiTexture.forward\n';
|
||||
code5 += '\t)';
|
||||
|
||||
//__RUNTIME_COMPONENT__
|
||||
var code6 = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n';
|
||||
code6 += '\t\tapiComponent = {};\n';
|
||||
code6 += '\t}\n';
|
||||
code6 += '\n';
|
||||
code6 += '\tif (R3.Utils.UndefinedOrNull(this.linkedComponents)) {\n';
|
||||
code6 += '\t\tthis.linkedComponents = {};\n';
|
||||
code6 += '\t}\n';
|
||||
code6 += '\n';
|
||||
code6 += '\tthis.initialize(apiComponent)\n';
|
||||
code6 += '\n';
|
||||
code6 += '\tthis.graphics\t= null;\n';
|
||||
code6 += '\tthis.physics\t= null;\n';
|
||||
code6 += '\tthis.coder\t\t= null;\n';
|
||||
code6 += '\tthis.gui\t\t= null;\n';
|
||||
code6 += '\tthis.stats\t\t= null;\n';
|
||||
code6 += '\n';
|
||||
code6 += '\tR3.Event.Emit(\n';
|
||||
code6 += '\t\tR3.Event.GET_RUNTIME,\n';
|
||||
code6 += '\t\tthis,\n';
|
||||
code6 += '\t\tfunction(runtime) {\n';
|
||||
code6 += '\t\t\tif (R3.Utils.UndefinedOrNull(runtime)) {\n';
|
||||
code6 += '\t\t\t\treturn;\n';
|
||||
code6 += '\t\t\t}\n';
|
||||
code6 += '\t\t\tthis.graphics\t= runtime.graphics;\n';
|
||||
code6 += '\t\t\tthis.physics\t= runtime.physics;\n';
|
||||
code6 += '\t\t\tthis.coder\t\t= runtime.coder;\n';
|
||||
code6 += '\t\t\tthis.gui\t\t= runtime.gui;\n';
|
||||
code6 += '\t\t\tthis.stats\t\t= runtime.stats;\n';
|
||||
code6 += '\t\t}.bind(this)\n';
|
||||
code6 += '\t)';
|
||||
|
||||
//__RUNTIME_COMPONENT_INHERITABLE__
|
||||
var code14 = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n';
|
||||
code14 += '\t\t\tapiComponent = {};\n';
|
||||
code14 += '\t\t}\n';
|
||||
code14 += '\n';
|
||||
code14 += '\t\tthis.initialize(apiComponent)\n';
|
||||
code14 += '\n';
|
||||
code14 += '\t\tthis.graphics\t= null;\n';
|
||||
code14 += '\t\tthis.physics\t= null;\n';
|
||||
code14 += '\t\tthis.coder\t\t= null;\n';
|
||||
code14 += '\t\tthis.gui\t\t= null;\n';
|
||||
code14 += '\t\tthis.stats\t\t= null;\n';
|
||||
code14 += '\n';
|
||||
code14 += '\t\tR3.Event.Emit(\n';
|
||||
code14 += '\t\t\tR3.Event.GET_RUNTIME,\n';
|
||||
code14 += '\t\t\tthis,\n';
|
||||
code14 += '\t\t\tfunction(runtime) {\n';
|
||||
code14 += '\t\t\t\tif (R3.Utils.UndefinedOrNull(runtime)) {\n';
|
||||
code14 += '\t\t\t\t\treturn;\n';
|
||||
code14 += '\t\t\t\t}\n';
|
||||
code14 += '\t\t\t\tthis.graphics\t= runtime.graphics;\n';
|
||||
code14 += '\t\t\t\tthis.physics\t= runtime.physics;\n';
|
||||
code14 += '\t\t\t\tthis.coder\t\t= runtime.coder;\n';
|
||||
code14 += '\t\t\t\tthis.gui\t\t= runtime.gui;\n';
|
||||
code14 += '\t\t\t\tthis.stats\t\t= runtime.stats;\n';
|
||||
code14 += '\t\t\t}.bind(this)\n';
|
||||
code14 += '\t\t)';
|
||||
|
||||
//__DEREGISTER_COMPONENT__
|
||||
var code7 = 'if (R3.Utils.UndefinedOrNull(apiComponent)) {\n';
|
||||
code7 += '\t\tapiComponent = {};\n';
|
||||
code7 += '\t}\n';
|
||||
code7 += '\n';
|
||||
code7 += '\tif (R3.Utils.UndefinedOrNull(apiComponent.register)) {\n';
|
||||
code7 += '\t\tapiComponent.register = false;\n';
|
||||
code7 += '\t}\n';
|
||||
code7 += '\n';
|
||||
code7 += '\tR3.Event.Emit(\n';
|
||||
code7 += '\t\tR3.Event.GET_REGISTER_FACES,\n';
|
||||
code7 += '\t\tnull,\n';
|
||||
code7 += '\t\tfunction(register) {\n';
|
||||
code7 += '\t\t\tif (R3.Utils.UndefinedOrNull(register)) {\n';
|
||||
code7 += '\t\t\t\treturn;\n';
|
||||
code7 += '\t\t\t}\n';
|
||||
code7 += '\t\t\tapiComponent.register = register;\n';
|
||||
code7 += '\t\t}\n';
|
||||
code7 += '\t)';
|
||||
|
||||
//__UPGRADE_TO_RUNTIME__
|
||||
var code8 = 'R3.Component.call(this)';
|
||||
|
||||
var code9 = 'R3.Component.prototype.createInstance.call(this)';
|
||||
|
||||
var code10 = 'R3.Component.prototype.updateInstance.call(this, property)';
|
||||
|
||||
var code11 = 'R3.D3.Geometry.Buffer.call(\n';
|
||||
code11 += '\t\tthis,\n';
|
||||
code11 += '\t\ttrue\n';
|
||||
code11 += '\t);';
|
||||
|
||||
//__INHERIT_ONLY__
|
||||
var code12 = 'if (R3.Utils.UndefinedOrNull(this.linkedComponents)) {\n';
|
||||
code12 += '\t\tthis.linkedComponents = {};\n';
|
||||
code12 += '\t}\n';
|
||||
code12 += '\t\n';
|
||||
code12 += '\tif (inherited !== true && inherited !== false) {\n';
|
||||
code12 += '\t\tthrow new Error(R3.GetComponentName(this) + " should not be instantiated directly");\n';
|
||||
code12 += '\t}';
|
||||
|
||||
//__INHERIT_AND_INSTANTIATE__
|
||||
var code13 = 'if (R3.Utils.UndefinedOrNull(this.linkedComponents)) {\n';
|
||||
code13 += '\t\tthis.linkedComponents = {};\n';
|
||||
code13 += '\t}\n';
|
||||
code13 += '\t\n';
|
||||
code13 += '\tif (R3.Utils.UndefinedOrNull(inherited)) {\n\n';
|
||||
code13 += '\t\t' + code14+ '\n';
|
||||
code13 += '\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__', code))
|
||||
.pipe(replace('__DEFINE_API_COMPONENT__', code1))
|
||||
.pipe(replace('__API_GEOMETRY_BUFFER__', code2))
|
||||
.pipe(replace('__API_GEOMETRY_NORMAL__', code3))
|
||||
.pipe(replace('__API_MATERIAL__', code4))
|
||||
.pipe(replace('__API_TEXTURE__', code5))
|
||||
.pipe(replace('__RUNTIME_COMPONENT__', code6))
|
||||
.pipe(replace('__DEREGISTER_COMPONENT__', code7))
|
||||
.pipe(replace('__UPGRADE_TO_RUNTIME__', code8))
|
||||
.pipe(replace('__CREATE_INSTANCE__', code9))
|
||||
.pipe(replace('__UPDATE_INSTANCE__', code10))
|
||||
.pipe(replace('__RUNTIME_BUFFER_COMPONENT__', code11))
|
||||
.pipe(replace('__INHERIT_ONLY__', code12))
|
||||
.pipe(replace('__INHERIT_AND_INSTANTIATE__', code13))
|
||||
// .pipe(minify({
|
||||
// ext:{
|
||||
// src:'.js',
|
||||
// min:'-min.js'
|
||||
// }
|
||||
// }))
|
||||
.pipe(gulp.dest('./build/'));
|
||||
}
|
||||
|
||||
|
||||
function monitor() {
|
||||
gulp.watch('src/*.js', build);
|
||||
}
|
||||
|
||||
gulp.task(
|
||||
'default',
|
||||
gulp.series(
|
||||
build,
|
||||
monitor
|
||||
)
|
||||
);
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "r3",
|
||||
"description": "R3 Library",
|
||||
"author": "-=<yb4f310",
|
||||
"version": "1.0.0",
|
||||
"repository": "https://bitbucket.org/cybafelo/r3/src/master/",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cannon": "^0.6.2",
|
||||
"gulp-cli": "^2.0.1",
|
||||
"three": "^0.107.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp": "git://github.com/gulpjs/gulp.git#6d71a658c61edb3090221579d8f97dbe086ba2ed",
|
||||
"gulp-concat": "*",
|
||||
"gulp-inject-string": "*",
|
||||
"gulp-minify": "*",
|
||||
"gulp-sort": "*",
|
||||
"gulp-string-replace": "*",
|
||||
"lodash": "^4.17.15",
|
||||
"npm": "^6.13.1"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
$files = scandir('.', SCANDIR_SORT_DESCENDING);
|
||||
|
||||
$statement = "/**
|
||||
* R3.GetComponentType
|
||||
* @param component
|
||||
* @returns {number}
|
||||
*/\n";
|
||||
|
||||
$statement .= "R3.GetComponentType = function(component) {\n\n";
|
||||
|
||||
$componentDefines = '';
|
||||
|
||||
$i = 1;
|
||||
|
||||
$apiComponents = [];
|
||||
$components = [];
|
||||
$componentTypes = [];
|
||||
|
||||
|
||||
foreach ($files as $file) {
|
||||
|
||||
if (
|
||||
!preg_match('/r3\-system/', $file) &&
|
||||
!preg_match('/entityManager/', $file) &&
|
||||
!preg_match('/r3\-runtime/', $file) &&
|
||||
!preg_match('/r3\-gui/', $file) &&
|
||||
!preg_match('/r3\-z\./', $file) &&
|
||||
!preg_match('/^r3\-a\-.*/', $file) &&
|
||||
!preg_match('/^\.$/', $file) &&
|
||||
!preg_match('/^\.\.$/', $file) &&
|
||||
preg_match('/.*\.js$/', $file)
|
||||
) {
|
||||
|
||||
$file = str_replace('-', '.', $file);
|
||||
$file = str_replace('api.y.', '', $file);
|
||||
$file = str_replace('api.z.', '', $file);
|
||||
$file = str_replace('api', 'API', $file);
|
||||
$file = str_replace('sql', 'SQL', $file);
|
||||
$file = str_replace('.vr.', '.VR.', $file);
|
||||
$file = str_replace('vpn', 'VPN', $file);
|
||||
$file = str_replace('gui', 'GUI', $file);
|
||||
$file = str_replace('ssao', 'SSAO', $file);
|
||||
$file = str_replace('fxaa', 'FXAA', $file);
|
||||
$file = str_replace('.0.js', '', $file);
|
||||
$file = str_replace('.js', '', $file);
|
||||
$file = str_replace('.0.', '.', $file);
|
||||
$file = str_replace('.y.', '.', $file);
|
||||
$file = str_replace('.z.', '.', $file);
|
||||
|
||||
$fileParts = explode('.', $file);
|
||||
|
||||
$parts = [];
|
||||
|
||||
foreach ($fileParts as $filePart) {
|
||||
array_push($parts, ucfirst($filePart));
|
||||
}
|
||||
|
||||
$file = join('.', $parts);
|
||||
|
||||
$componentType = strtoupper($file);
|
||||
$componentType = str_replace('R3.', '', $componentType);
|
||||
$componentType = str_replace('API.', '', $componentType);
|
||||
$componentType = str_replace('.', '_', $componentType);
|
||||
$componentType = 'R3.COMPONENT_' . $componentType;
|
||||
|
||||
if (in_array($componentType, $componentTypes)) {
|
||||
|
||||
if (preg_match('/API/', $file)) {
|
||||
$apiComponents[$componentType] = $file ;
|
||||
} else {
|
||||
$components[$componentType] = $file;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if (preg_match('/API/', $file)) {
|
||||
$apiComponents[$componentType] = $file;
|
||||
} else {
|
||||
$components[$componentType] = $file;
|
||||
}
|
||||
|
||||
array_push($componentTypes, $componentType);
|
||||
$componentDefines .= $componentType . ' = 0x' . dechex($i) . ";\n";
|
||||
$i++;
|
||||
}
|
||||
|
||||
$statement .= "\tif (component instanceof " . $file . ") {\n";
|
||||
$statement .= "\t\treturn " . $componentType . ";\n";
|
||||
$statement .= "\t}\n\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$statement .= "};\n\n";
|
||||
|
||||
$componentDefines .= 'R3.MAX_COMPONENTS = 0x' . dechex($i) . ";\n\n";
|
||||
|
||||
$getComponentInfo = "R3.GetComponentInfo = function(componentType) {\n\n\tswitch (componentType) {\n\n";
|
||||
|
||||
$getApiConstructor = "/**
|
||||
* R3.GetAPIConstructor
|
||||
* @param runtimeComponent
|
||||
* @returns constructor
|
||||
*/\n";
|
||||
|
||||
$getApiConstructor .= "R3.GetAPIConstructor = function(runtimeComponent) {\n\n";
|
||||
|
||||
$getName = "/**
|
||||
* R3.GetComponentName
|
||||
* @param runtimeComponent
|
||||
* @returns string
|
||||
*/\n";
|
||||
$getName .= "R3.GetComponentName = function(runtimeComponent) {\n\n";
|
||||
|
||||
$getConstructor = "/**
|
||||
* R3.GetConstructor
|
||||
* @param apiComponent
|
||||
* @returns constructor
|
||||
*/\n";
|
||||
|
||||
$getConstructor .= "R3.GetConstructor = function(apiComponent) {\n\n";
|
||||
|
||||
$getConstructorFromComponentType = "/**
|
||||
* R3.GetConstructorFromComponentType
|
||||
* @param componentType
|
||||
* @returns constructor
|
||||
*/\n";
|
||||
|
||||
$getConstructorFromComponentType .= "R3.GetConstructorFromComponentType = function(componentType) {\n\n";
|
||||
$getConstructorFromComponentType .= "\tswitch (componentType) {\n\n";
|
||||
|
||||
foreach ($componentTypes as $componentType) {
|
||||
|
||||
// foreach ($components as $component) {
|
||||
// if ()
|
||||
// }
|
||||
$files = array_keys($components);
|
||||
|
||||
$name = $components[$componentType];
|
||||
|
||||
$getApiConstructor .= "\tif (runtimeComponent instanceof " . $name . "){\n\t\treturn " . $apiComponents[$componentType] . ";\n\t}\n";
|
||||
$getName .= "\tif (runtimeComponent instanceof " . $name . "){\n\t\treturn '" . $name . "';\n\t}\n";
|
||||
$getConstructor .= "\tif (apiComponent instanceof " . $apiComponents[$componentType] . "){\n\t\treturn " . $name . ";\n\t}\n";
|
||||
$getConstructorFromComponentType .= "\t\tcase " . $componentType . ": return " . $name . ";\n";
|
||||
|
||||
$runtime = 'R3.Runtime.DEFAULT';
|
||||
|
||||
if (preg_match('/Bone|Box|Camera|Canvas|Clock|Color|Composer|Controls|Curve|Effect|Fog|Geometry|Graphics|Image|Light|Material|Mesh|Mouse|Object|Particle|Pass|Raycaster|Render|Scene|Shader|Shadow|Skeleton|Text|Video|Viewport/', $name)) {
|
||||
$runtime = 'R3.Runtime.GRAPHICS';
|
||||
}
|
||||
|
||||
if (preg_match('/Code/', $name)) {
|
||||
$runtime = 'R3.Runtime.CODER';
|
||||
}
|
||||
|
||||
if (preg_match('/GUI/', $name)) {
|
||||
$runtime = 'R3.Runtime.GUI';
|
||||
}
|
||||
|
||||
if (preg_match('/Server|Socket/', $name)) {
|
||||
$runtime = 'R3.Runtime.SOCKETS';
|
||||
}
|
||||
|
||||
if (preg_match('/Broadphase|Friction|Physics|Rigid|Shape|Solver|Vehicle|Wheel/', $name)) {
|
||||
$runtime = 'R3.Runtime.PHYSICS';
|
||||
}
|
||||
|
||||
$getComponentInfo .= "\t\tcase " . $componentType . " : return {\n";
|
||||
$getComponentInfo .= "\t\t\tname : '" . $name . "',\n";
|
||||
$getComponentInfo .= "\t\t\tconstructor : " . $name . ",\n";
|
||||
$getComponentInfo .= "\t\t\tapiConstructor : " . $apiComponents[$componentType] . ",\n";
|
||||
$getComponentInfo .= "\t\t\truntime: " . $runtime . "\n";
|
||||
$getComponentInfo .= "\t\t};\n";
|
||||
}
|
||||
|
||||
$getComponentInfo .= "\t\tdefault : \n";
|
||||
$getComponentInfo .= "\t\t\tthrow new Error('Invalid component type: ' + componentType);\n\n";
|
||||
$getComponentInfo .= "\t}\n";
|
||||
$getComponentInfo .= "};\n\n";
|
||||
|
||||
$getApiConstructor .= "\tthrow new Error('Invalid Runtime Constructor : ' + runtimeConstructor);\n\n";
|
||||
$getApiConstructor .= "};\n\n";
|
||||
|
||||
$getConstructor .= "\tthrow new Error('Invalid API Constructor : ' + apiConstructor);\n\n";
|
||||
$getConstructor .= "};\n\n";
|
||||
|
||||
$getConstructorFromComponentType .= "\t\tdefault : \n";
|
||||
$getConstructorFromComponentType .= "\t\t\tthrow new Error('Invalid componentType : ' + componentType);\n\n";
|
||||
$getConstructorFromComponentType .= "\t}\n";
|
||||
$getConstructorFromComponentType .= "};\n\n";
|
||||
|
||||
$getName .= "\tthrow new Error('Invalid Runtime Constructor : ' + runtimeConstructor);\n\n";
|
||||
$getName .= "};\n";
|
||||
|
||||
|
||||
echo $componentDefines;
|
||||
echo $statement;
|
||||
echo $getComponentInfo;
|
||||
echo $getApiConstructor;
|
||||
echo $getConstructor;
|
||||
echo $getConstructorFromComponentType;
|
||||
echo $getName;
|
||||
|
||||
file_put_contents('r3-a-1-component-info.js', $componentDefines . $statement . $getComponentInfo . $getApiConstructor . $getConstructor . $getConstructorFromComponentType . $getName);
|
||||
|
||||
?>
|
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
$files = scandir('.', SCANDIR_SORT_DESCENDING);
|
||||
|
||||
$events = [];
|
||||
|
||||
foreach ($files as $file) {
|
||||
|
||||
|
||||
if (
|
||||
preg_match('/\.js$/', $file) &&
|
||||
!preg_match('/r3\-a\-2\-event/', $file)
|
||||
) {
|
||||
echo "processing file " . $file . "\n";
|
||||
|
||||
$fn = fopen($file, "r");
|
||||
|
||||
while (!feof($fn)) {
|
||||
$line = fgets($fn);
|
||||
|
||||
|
||||
if (
|
||||
preg_match('/R3.Event\./', $line) &&
|
||||
!preg_match('/Emit|Subscribe|.call|GetEventName|Async|prototype/', $line)
|
||||
) {
|
||||
$matches = [];
|
||||
preg_match_all('/(R3.Event\..*?)(\s+|,|;|$|\))/', $line, $matches);
|
||||
|
||||
if ($matches[1] && $matches[1][0]) {
|
||||
|
||||
$event = $matches[1][0];
|
||||
|
||||
if (in_array($event, $events)) {
|
||||
// Do nothing
|
||||
} else {
|
||||
array_push($events, $event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
fclose($fn);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
array_push($events, 'R3.Event.START');
|
||||
array_push($events, 'R3.Event.PAUSE');
|
||||
array_push($events, 'R3.Event.RESTART');
|
||||
|
||||
sort($events);
|
||||
|
||||
$i = 1;
|
||||
|
||||
$eventList = '';
|
||||
|
||||
$eventFunction = "/**\n * R3.Event.GetEventName\n * @param eventId\n * @returns {string}\n * @constructor\n */\nR3.Event.GetEventName = function(eventId) {\n\n\tswitch(eventId) {\n";
|
||||
|
||||
foreach ($events as $event) {
|
||||
$eventList .= $event . " = " . "0x" . dechex($i) . ";\n";
|
||||
|
||||
$eventFunction .= "\t\tcase 0x" . dechex($i). " : return '" . strtolower(str_replace('R3.Event.', '', $event)) . "';\n";
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$eventList .= "R3.Event.MAX_EVENTS = " . "0x" . dechex($i) . ";\n\n";
|
||||
|
||||
$eventFunction .= "\t\tdefault :\n\t\t\tthrow new Error('Event type not defined : ' + eventId);\n";
|
||||
$eventFunction .= "\t}\n\n";
|
||||
$eventFunction .= "};\n";
|
||||
|
||||
echo $eventList;
|
||||
echo $eventFunction;
|
||||
|
||||
file_put_contents('r3-a-2-event-1.js', $eventList . $eventFunction);
|
||||
|
||||
?>
|
|
@ -0,0 +1,39 @@
|
|||
console.log("Loading R3 compiled at: __DATE__");
|
||||
|
||||
/**
|
||||
* R3 Namespace
|
||||
*/
|
||||
if (typeof R3 === 'undefined') {
|
||||
function R3() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* R3.D3 Namespace
|
||||
*/
|
||||
if (typeof R3.D3 === 'undefined') {
|
||||
R3.D3 = function(){};
|
||||
}
|
||||
|
||||
/**
|
||||
* R3.D3.API Namespace
|
||||
* @constructor
|
||||
*/
|
||||
if (typeof R3.D3.API === 'undefined') {
|
||||
R3.D3.API = function(){};
|
||||
}
|
||||
|
||||
/**
|
||||
* R3.API Namespace
|
||||
*/
|
||||
if (typeof R3.API === 'undefined') {
|
||||
R3.API = function(){};
|
||||
}
|
||||
|
||||
/**
|
||||
* R3.D3.Runtime Namespace
|
||||
* @constructor
|
||||
*/
|
||||
if (typeof R3.D3.Runtime === 'undefined') {
|
||||
R3.D3.Runtime = function(){};
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,174 @@
|
|||
/**
|
||||
* Event Core
|
||||
* @constructor
|
||||
*/
|
||||
R3.Event = function() {
|
||||
};
|
||||
|
||||
/**
|
||||
* Some nice Events handling
|
||||
* @type {{}}
|
||||
*/
|
||||
R3.Event.Subscriptions = {};
|
||||
|
||||
/**
|
||||
* Subscribe to some events
|
||||
* @param eventName
|
||||
* @param callback
|
||||
*/
|
||||
R3.Event.prototype.subscribe = function(
|
||||
eventName,
|
||||
callback
|
||||
) {
|
||||
return R3.Event.Subscribe(eventName, callback.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Publish some event happened with some data
|
||||
* @param eventName
|
||||
* @param data
|
||||
* @param clientCallback
|
||||
* @param clientErrorCallback
|
||||
* @returns {number} of callbacks executed
|
||||
*/
|
||||
R3.Event.prototype.emit = function(
|
||||
eventName,
|
||||
data,
|
||||
clientCallback,
|
||||
clientErrorCallback
|
||||
) {
|
||||
return R3.Event.Emit(
|
||||
eventName,
|
||||
data,
|
||||
clientCallback,
|
||||
clientErrorCallback
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Static Synchrnonous Event - Calls clientCallback directly after the event result is obtained
|
||||
* @param eventId
|
||||
* @param data
|
||||
* @param clientCallback is executed ideally when the event completed
|
||||
* @param clientErrorCallback
|
||||
* @returns {number} of callbacks executed
|
||||
* @constructor
|
||||
*/
|
||||
R3.Event.Emit = function(
|
||||
eventId,
|
||||
data,
|
||||
clientCallback,
|
||||
clientErrorCallback
|
||||
) {
|
||||
|
||||
if (R3.Event.Subscriptions.hasOwnProperty(eventId)) {
|
||||
|
||||
var subscriptionIds = Object.keys(R3.Event.Subscriptions[eventId]);
|
||||
|
||||
subscriptionIds.map(
|
||||
function(subscriptionId) {
|
||||
try {
|
||||
var result = R3.Event.Subscriptions[eventId][subscriptionId](data);
|
||||
|
||||
if (clientCallback) {
|
||||
clientCallback(result);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
if (clientErrorCallback) {
|
||||
clientErrorCallback(error);
|
||||
} else {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Execute the functions which subscribe to this event, but don't process the client callback - the subscription function
|
||||
* should execute the client callback
|
||||
* @param eventId
|
||||
* @param data
|
||||
* @param clientCallback
|
||||
* @param clientErrorCallback
|
||||
* @returns {number}
|
||||
* @constructor
|
||||
*/
|
||||
R3.Event.Async = function(
|
||||
eventId,
|
||||
data,
|
||||
clientCallback,
|
||||
clientErrorCallback
|
||||
) {
|
||||
if (R3.Event.Subscriptions.hasOwnProperty(eventId)) {
|
||||
|
||||
var subscriptionIds = Object.keys(R3.Event.Subscriptions[eventId]);
|
||||
|
||||
subscriptionIds.map(
|
||||
function(subscriptionId) {
|
||||
try {
|
||||
R3.Event.Subscriptions[eventId][subscriptionId](data, clientCallback, clientErrorCallback);
|
||||
} catch (error) {
|
||||
if (clientErrorCallback) {
|
||||
clientErrorCallback(error);
|
||||
} else {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
R3.Event.Subscribe = function(
|
||||
eventName,
|
||||
fn,
|
||||
) {
|
||||
/**
|
||||
* Todo - maybe eventually store a boolean which indicates if the function has been executed
|
||||
*/
|
||||
var subscriptionId = R3.Utils.RandomId(10);
|
||||
|
||||
if (R3.Event.Subscriptions.hasOwnProperty(eventName)) {
|
||||
|
||||
if (R3.Event.Subscriptions[eventName][subscriptionId]) {
|
||||
throw new Error('A component can only subscribe to a particular event ID once');
|
||||
}
|
||||
|
||||
R3.Event.Subscriptions[eventName][subscriptionId] = fn;
|
||||
} else {
|
||||
R3.Event.Subscriptions[eventName] = {};
|
||||
R3.Event.Subscriptions[eventName][subscriptionId] = fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a handle to the caller to allow us to unsubscribe to this event
|
||||
*/
|
||||
return {
|
||||
fn: fn,
|
||||
remove: function (eventId, subscriptionId) {
|
||||
|
||||
return function () {
|
||||
|
||||
/**
|
||||
* Stop listening for this event from this component
|
||||
*/
|
||||
delete R3.Event.Subscriptions[eventId][subscriptionId];
|
||||
|
||||
/**
|
||||
* If the length of listeners is 0, stop referencing this event
|
||||
* @type {string[]}
|
||||
*/
|
||||
var listeners = Object.keys(R3.Event.Subscriptions[eventId]);
|
||||
if (listeners.length === 0) {
|
||||
delete R3.Event.Subscriptions[eventId];
|
||||
}
|
||||
}
|
||||
|
||||
}(eventName, subscriptionId),
|
||||
subscriptionId : subscriptionId
|
||||
};
|
||||
|
||||
};
|
|
@ -0,0 +1,254 @@
|
|||
R3.Event.AFTER_RENDER = 0x1;
|
||||
R3.Event.AFTER_WINDOW_RESIZE = 0x2;
|
||||
R3.Event.ANIMATE_TEXTURE_INSTANCE = 0x3;
|
||||
R3.Event.ANIMATION_COMPILE_FAILED = 0x4;
|
||||
R3.Event.ANIMATION_COMPILE_SUCCESS = 0x5;
|
||||
R3.Event.ANIMATION_MESH_ADDED = 0x6;
|
||||
R3.Event.ANIMATION_MESH_REMOVED = 0x7;
|
||||
R3.Event.ARRAY_ITEM_ADDED = 0x8;
|
||||
R3.Event.AUDIO_ENDED = 0x9;
|
||||
R3.Event.BEFORE_RENDER = 0xa;
|
||||
R3.Event.BEFORE_WINDOW_RESIZE = 0xb;
|
||||
R3.Event.BLENDER_DATA_RECEIVED = 0xc;
|
||||
R3.Event.BUILD_GUI = 0xd;
|
||||
R3.Event.CANVAS_CHANGE = 0xe;
|
||||
R3.Event.CANVAS_RESIZE = 0xf;
|
||||
R3.Event.CAST_SOURCE_CHANGED = 0x10;
|
||||
R3.Event.CLEAR_GUI = 0x11;
|
||||
R3.Event.COMPILE_FAILED = 0x12;
|
||||
R3.Event.COMPILE_SUCCESS = 0x13;
|
||||
R3.Event.COMPONENTS_LINKED = 0x14;
|
||||
R3.Event.COMPONENT_CLONED = 0x15;
|
||||
R3.Event.COMPONENT_CREATED = 0x16;
|
||||
R3.Event.COMPONENT_DELETED = 0x17;
|
||||
R3.Event.COMPONENT_DOWNLOAD_COMPLETE = 0x18;
|
||||
R3.Event.COMPONENT_LINKED = 0x19;
|
||||
R3.Event.COMPONENT_REGISTER = 0x1a;
|
||||
R3.Event.COMPONENT_REPLACED = 0x1b;
|
||||
R3.Event.COMPONENT_SAVED = 0x1c;
|
||||
R3.Event.COMPONENT_TYPES_UPDATE = 0x1d;
|
||||
R3.Event.COMPONENT_UPDATE = 0x1e;
|
||||
R3.Event.CONTINUE_ALL_AUDIO = 0x1f;
|
||||
R3.Event.CONTROLS_CANVAS_CHANGE = 0x20;
|
||||
R3.Event.DELETE_COMPONENT = 0x21;
|
||||
R3.Event.DELETE_COMPONENT_ERROR = 0x22;
|
||||
R3.Event.DONE_SAVING = 0x23;
|
||||
R3.Event.ENGINE_FIRED_PARTICLES_ZERO = 0x24;
|
||||
R3.Event.ENTITY_LOADED = 0x25;
|
||||
R3.Event.EVENT_ID_UPDATE = 0x26;
|
||||
R3.Event.EXCLUDE_FROM_ENVIRONMENT = 0x27;
|
||||
R3.Event.FETCH_COMPONENTS = 0x28;
|
||||
R3.Event.FETCH_COMPONENT_TYPES = 0x29;
|
||||
R3.Event.GET_API_URL = 0x2a;
|
||||
R3.Event.GET_APPLICATION_MODE = 0x2b;
|
||||
R3.Event.GET_GRAPHICS_RUNTIME = 0x2c;
|
||||
R3.Event.GET_PHYSICS_RUNTIME = 0x2d;
|
||||
R3.Event.GET_PROJECT = 0x2e;
|
||||
R3.Event.GET_PROJECTS = 0x2f;
|
||||
R3.Event.GET_REMOTE_API_URL = 0x30;
|
||||
R3.Event.GET_RENDER_CONFIGURATION = 0x31;
|
||||
R3.Event.GET_RUNTIME = 0x32;
|
||||
R3.Event.GET_USER = 0x33;
|
||||
R3.Event.GET_WEBSOCKET_CONFIG = 0x34;
|
||||
R3.Event.GET_WINDOW_SIZE = 0x35;
|
||||
R3.Event.GUI_CREATED = 0x36;
|
||||
R3.Event.GUI_REMOVED = 0x37;
|
||||
R3.Event.IMAGE_UPLOAD_COMPLETE = 0x38;
|
||||
R3.Event.INSTANCE_CLONED = 0x39;
|
||||
R3.Event.INSTANCE_CREATED = 0x3a;
|
||||
R3.Event.INSTANCE_DISPOSAL = 0x3b;
|
||||
R3.Event.INSTANCE_LOADED = 0x3c;
|
||||
R3.Event.KEY_DOWN = 0x3d;
|
||||
R3.Event.KEY_UP = 0x3e;
|
||||
R3.Event.LOAD_COMPONENT = 0x3f;
|
||||
R3.Event.LOAD_COMPONENT_ERROR = 0x40;
|
||||
R3.Event.LOAD_FONT = 0x41;
|
||||
R3.Event.LOAD_IMAGE = 0x42;
|
||||
R3.Event.LOAD_PROGRESS = 0x43;
|
||||
R3.Event.MATERIAL_TEXTURES_UPDATED = 0x44;
|
||||
R3.Event.MATERIAL_TYPE_CHANGED = 0x45;
|
||||
R3.Event.MAXIMUM_PROJECTS = 0x46;
|
||||
R3.Event.MESH_DESELECTED = 0x47;
|
||||
R3.Event.MESH_FACE_DESELECTED = 0x48;
|
||||
R3.Event.MESH_FACE_SELECTED = 0x49;
|
||||
R3.Event.MESH_SELECTED = 0x4a;
|
||||
R3.Event.MOUSE_DOWN = 0x4b;
|
||||
R3.Event.MOUSE_MOVE = 0x4c;
|
||||
R3.Event.MOUSE_UP = 0x4d;
|
||||
R3.Event.MOUSE_WHEEL = 0x4e;
|
||||
R3.Event.MUTE_AUDIO = 0x4f;
|
||||
R3.Event.NAME_UPDATE = 0x50;
|
||||
R3.Event.PARENT_SCENE_CHANGE = 0x51;
|
||||
R3.Event.PARENT_WORLD_CHANGE = 0x52;
|
||||
R3.Event.PAUSE = 0x53;
|
||||
R3.Event.PAUSE_ALL_AUDIO = 0x54;
|
||||
R3.Event.PLAY_AUDIO = 0x55;
|
||||
R3.Event.PROJECT_LOADED = 0x56;
|
||||
R3.Event.QUERY = 0x57;
|
||||
R3.Event.QUERY_INTERVAL_CHANGE = 0x58;
|
||||
R3.Event.QUERY_PARSED = 0x59;
|
||||
R3.Event.RECEIVE_DESTINATION_CHANGED = 0x5a;
|
||||
R3.Event.REGISTER_COMPONENT = 0x5b;
|
||||
R3.Event.REGISTER_DEPENDENCIES = 0x5c;
|
||||
R3.Event.REGISTER_UPDATE = 0x5d;
|
||||
R3.Event.REMOVE_COMPONENT = 0x5e;
|
||||
R3.Event.REMOVE_MESH = 0x5f;
|
||||
R3.Event.REMOVE_PARTICLE_ENGINE = 0x60;
|
||||
R3.Event.RENDERER_SIZE_CHANGE = 0x61;
|
||||
R3.Event.REPLACE_COMPONENT = 0x62;
|
||||
R3.Event.RESOLVE_DEPENDENCIES = 0x63;
|
||||
R3.Event.RESTART = 0x64;
|
||||
R3.Event.SAVE_COMPONENT = 0x65;
|
||||
R3.Event.SAVE_COMPONENT_ERROR = 0x66;
|
||||
R3.Event.SAVING = 0x67;
|
||||
R3.Event.SELECTION_MODE_CHANGE = 0x68;
|
||||
R3.Event.SIGN_IN = 0x69;
|
||||
R3.Event.SIGN_OUT = 0x6a;
|
||||
R3.Event.START = 0x6b;
|
||||
R3.Event.STOP_ALL_AUDIO = 0x6c;
|
||||
R3.Event.STOP_AUDIO = 0x6d;
|
||||
R3.Event.STOP_VISUALIZE = 0x6e;
|
||||
R3.Event.TEXTURE_ANIMATED_CHANGE = 0x6f;
|
||||
R3.Event.TEXTURE_INSTANCE_UPDATED = 0x70;
|
||||
R3.Event.TOUCH_CANCEL = 0x71;
|
||||
R3.Event.TOUCH_END = 0x72;
|
||||
R3.Event.TOUCH_MOVE = 0x73;
|
||||
R3.Event.TOUCH_START = 0x74;
|
||||
R3.Event.UNRESOLVED_DEPENDENCIES_UPDATE = 0x75;
|
||||
R3.Event.VISUALIZE = 0x76;
|
||||
R3.Event.WINDOW_RESIZE = 0x77;
|
||||
R3.Event.MAX_EVENTS = 0x78;
|
||||
|
||||
/**
|
||||
* R3.Event.GetEventName
|
||||
* @param eventId
|
||||
* @returns {string}
|
||||
* @constructor
|
||||
*/
|
||||
R3.Event.GetEventName = function(eventId) {
|
||||
|
||||
switch(eventId) {
|
||||
case 0x1 : return 'after_render';
|
||||
case 0x2 : return 'after_window_resize';
|
||||
case 0x3 : return 'animate_texture_instance';
|
||||
case 0x4 : return 'animation_compile_failed';
|
||||
case 0x5 : return 'animation_compile_success';
|
||||
case 0x6 : return 'animation_mesh_added';
|
||||
case 0x7 : return 'animation_mesh_removed';
|
||||
case 0x8 : return 'array_item_added';
|
||||
case 0x9 : return 'audio_ended';
|
||||
case 0xa : return 'before_render';
|
||||
case 0xb : return 'before_window_resize';
|
||||
case 0xc : return 'blender_data_received';
|
||||
case 0xd : return 'build_gui';
|
||||
case 0xe : return 'canvas_change';
|
||||
case 0xf : return 'canvas_resize';
|
||||
case 0x10 : return 'cast_source_changed';
|
||||
case 0x11 : return 'clear_gui';
|
||||
case 0x12 : return 'compile_failed';
|
||||
case 0x13 : return 'compile_success';
|
||||
case 0x14 : return 'components_linked';
|
||||
case 0x15 : return 'component_cloned';
|
||||
case 0x16 : return 'component_created';
|
||||
case 0x17 : return 'component_deleted';
|
||||
case 0x18 : return 'component_download_complete';
|
||||
case 0x19 : return 'component_linked';
|
||||
case 0x1a : return 'component_register';
|
||||
case 0x1b : return 'component_replaced';
|
||||
case 0x1c : return 'component_saved';
|
||||
case 0x1d : return 'component_types_update';
|
||||
case 0x1e : return 'component_update';
|
||||
case 0x1f : return 'continue_all_audio';
|
||||
case 0x20 : return 'controls_canvas_change';
|
||||
case 0x21 : return 'delete_component';
|
||||
case 0x22 : return 'delete_component_error';
|
||||
case 0x23 : return 'done_saving';
|
||||
case 0x24 : return 'engine_fired_particles_zero';
|
||||
case 0x25 : return 'entity_loaded';
|
||||
case 0x26 : return 'event_id_update';
|
||||
case 0x27 : return 'exclude_from_environment';
|
||||
case 0x28 : return 'fetch_components';
|
||||
case 0x29 : return 'fetch_component_types';
|
||||
case 0x2a : return 'get_api_url';
|
||||
case 0x2b : return 'get_application_mode';
|
||||
case 0x2c : return 'get_graphics_runtime';
|
||||
case 0x2d : return 'get_physics_runtime';
|
||||
case 0x2e : return 'get_project';
|
||||
case 0x2f : return 'get_projects';
|
||||
case 0x30 : return 'get_remote_api_url';
|
||||
case 0x31 : return 'get_render_configuration';
|
||||
case 0x32 : return 'get_runtime';
|
||||
case 0x33 : return 'get_user';
|
||||
case 0x34 : return 'get_websocket_config';
|
||||
case 0x35 : return 'get_window_size';
|
||||
case 0x36 : return 'gui_created';
|
||||
case 0x37 : return 'gui_removed';
|
||||
case 0x38 : return 'image_upload_complete';
|
||||
case 0x39 : return 'instance_cloned';
|
||||
case 0x3a : return 'instance_created';
|
||||
case 0x3b : return 'instance_disposal';
|
||||
case 0x3c : return 'instance_loaded';
|
||||
case 0x3d : return 'key_down';
|
||||
case 0x3e : return 'key_up';
|
||||
case 0x3f : return 'load_component';
|
||||
case 0x40 : return 'load_component_error';
|
||||
case 0x41 : return 'load_font';
|
||||
case 0x42 : return 'load_image';
|
||||
case 0x43 : return 'load_progress';
|
||||
case 0x44 : return 'material_textures_updated';
|
||||
case 0x45 : return 'material_type_changed';
|
||||
case 0x46 : return 'maximum_projects';
|
||||
case 0x47 : return 'mesh_deselected';
|
||||
case 0x48 : return 'mesh_face_deselected';
|
||||
case 0x49 : return 'mesh_face_selected';
|
||||
case 0x4a : return 'mesh_selected';
|
||||
case 0x4b : return 'mouse_down';
|
||||
case 0x4c : return 'mouse_move';
|
||||
case 0x4d : return 'mouse_up';
|
||||
case 0x4e : return 'mouse_wheel';
|
||||
case 0x4f : return 'mute_audio';
|
||||
case 0x50 : return 'name_update';
|
||||
case 0x51 : return 'parent_scene_change';
|
||||
case 0x52 : return 'parent_world_change';
|
||||
case 0x53 : return 'pause';
|
||||
case 0x54 : return 'pause_all_audio';
|
||||
case 0x55 : return 'play_audio';
|
||||
case 0x56 : return 'project_loaded';
|
||||
case 0x57 : return 'query';
|
||||
case 0x58 : return 'query_interval_change';
|
||||
case 0x59 : return 'query_parsed';
|
||||
case 0x5a : return 'receive_destination_changed';
|
||||
case 0x5b : return 'register_component';
|
||||
case 0x5c : return 'register_dependencies';
|
||||
case 0x5d : return 'register_update';
|
||||
case 0x5e : return 'remove_component';
|
||||
case 0x5f : return 'remove_mesh';
|
||||
case 0x60 : return 'remove_particle_engine';
|
||||
case 0x61 : return 'renderer_size_change';
|
||||
case 0x62 : return 'replace_component';
|
||||
case 0x63 : return 'resolve_dependencies';
|
||||
case 0x64 : return 'restart';
|
||||
case 0x65 : return 'save_component';
|
||||
case 0x66 : return 'save_component_error';
|
||||
case 0x67 : return 'saving';
|
||||
case 0x68 : return 'selection_mode_change';
|
||||
case 0x69 : return 'sign_in';
|
||||
case 0x6a : return 'sign_out';
|
||||
case 0x6b : return 'start';
|
||||
case 0x6c : return 'stop_all_audio';
|
||||
case 0x6d : return 'stop_audio';
|
||||
case 0x6e : return 'stop_visualize';
|
||||
case 0x6f : return 'texture_animated_change';
|
||||
case 0x70 : return 'texture_instance_updated';
|
||||
case 0x71 : return 'touch_cancel';
|
||||
case 0x72 : return 'touch_end';
|
||||
case 0x73 : return 'touch_move';
|
||||
case 0x74 : return 'touch_start';
|
||||
case 0x75 : return 'unresolved_dependencies_update';
|
||||
case 0x76 : return 'visualize';
|
||||
case 0x77 : return 'window_resize';
|
||||
default :
|
||||
throw new Error('Event type not defined : ' + eventId);
|
||||
}
|
||||
|
||||
};
|
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
* API Component Interface - Do not construct objects of this type directly
|
||||
* @param parent
|
||||
* @param id
|
||||
* @param name
|
||||
* @param register
|
||||
* @param selected
|
||||
* @param isPublic
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.Component = function(
|
||||
parent,
|
||||
id,
|
||||
name,
|
||||
register,
|
||||
selected,
|
||||
isPublic
|
||||
) {
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(parent)) {
|
||||
parent = null;
|
||||
}
|
||||
this.parent = parent;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(id)) {
|
||||
id = R3.Utils.RandomId();
|
||||
}
|
||||
this.id = id;
|
||||
|
||||
this.componentType = R3.GetComponentType(this);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(name)) {
|
||||
name = R3.Component.GetComponentFriendlyName(this.componentType) + ' (' + this.id + ')';
|
||||
}
|
||||
this.name = name;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(register)) {
|
||||
register = true;
|
||||
}
|
||||
this.register = register;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(selected)) {
|
||||
selected = false;
|
||||
}
|
||||
this.selected = selected;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(isPublic)) {
|
||||
isPublic = true;
|
||||
}
|
||||
this.isPublic = isPublic;
|
||||
|
||||
};
|
||||
|
||||
R3.API.Component.prototype.constructor = R3.API.Component;
|
||||
|
||||
/**
|
||||
* Wrapper for R3.Utils.GetFirstParent
|
||||
* @param constructor
|
||||
* @returns {*}
|
||||
*/
|
||||
R3.API.Component.prototype.getFirstParent = function(constructor) {
|
||||
return R3.Utils.GetFirstParent(this, constructor);
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper for R3.Utils.GetParent
|
||||
* @param property
|
||||
* @param index
|
||||
* @param constructor
|
||||
* @returns {*}
|
||||
*/
|
||||
R3.API.Component.getParent = function(property, index, constructor) {
|
||||
return R3.Utils.GetParent(this, property, index, constructor);
|
||||
};
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* R3.API.Box3
|
||||
* @param apiComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.Box3 = function(
|
||||
apiComponent
|
||||
) {
|
||||
__API_COMPONENT__;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.min)) {
|
||||
apiComponent.min = new R3.API.Vector3(
|
||||
{
|
||||
parent : this,
|
||||
register : true
|
||||
},
|
||||
0,
|
||||
0,
|
||||
0
|
||||
);
|
||||
}
|
||||
this.min = apiComponent.min;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.max)) {
|
||||
apiComponent.max = new R3.API.Vector3(
|
||||
{
|
||||
parent : this,
|
||||
register : true
|
||||
},
|
||||
1,
|
||||
1,
|
||||
1
|
||||
);
|
||||
}
|
||||
this.max = apiComponent.max;
|
||||
};
|
||||
|
||||
R3.API.Box3.prototype = Object.create(R3.API.Component.prototype);
|
||||
R3.API.Box3.prototype.constructor = R3.API.Box3;
|
|
@ -0,0 +1,60 @@
|
|||
/**
|
||||
* R3.API.Canvas
|
||||
* @param apiComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.Canvas = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
__API_COMPONENT__;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.autoUpdateSize)) {
|
||||
apiComponent.autoUpdateSize = true;
|
||||
}
|
||||
this.autoUpdateSize = apiComponent.autoUpdateSize;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.width)) {
|
||||
apiComponent.width = 450;
|
||||
}
|
||||
this.width = apiComponent.width;
|
||||
this.guiInfo.width = {
|
||||
range: [0, 5120],
|
||||
step: 1,
|
||||
dp: 0
|
||||
};
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.height)) {
|
||||
apiComponent.height = 450;
|
||||
}
|
||||
this.height = apiComponent.height;
|
||||
this.guiInfo.height = {
|
||||
range: [0, 5120],
|
||||
step: 1,
|
||||
dp: 0
|
||||
};
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.tabIndex)) {
|
||||
apiComponent.tabIndex = 1;
|
||||
}
|
||||
this.tabIndex = apiComponent.tabIndex;
|
||||
this.guiInfo.tabIndex = {
|
||||
range: [0, 100],
|
||||
step: 1,
|
||||
dp: 0
|
||||
};
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.texts)) {
|
||||
apiComponent.texts = [];
|
||||
}
|
||||
this.texts = apiComponent.texts;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.textBaseline)) {
|
||||
apiComponent.textBaseline = 'middle';
|
||||
}
|
||||
this.textBaseline = apiComponent.textBaseline;
|
||||
|
||||
};
|
||||
|
||||
R3.API.Canvas.prototype = Object.create(R3.API.Component.prototype);
|
||||
R3.API.Canvas.prototype.constructor = R3.API.Canvas;
|
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* R3.API.Clock
|
||||
* @constructor
|
||||
* @param apiComponent
|
||||
*/
|
||||
R3.API.Clock = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
__API_COMPONENT__;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.delta)) {
|
||||
apiComponent.delta = 0;
|
||||
}
|
||||
this.delta = apiComponent.delta;
|
||||
|
||||
};
|
||||
|
||||
R3.API.Clock.prototype = Object.create(R3.API.Component.prototype);
|
||||
R3.API.Clock.prototype.constructor = R3.API.Clock;
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* API Color
|
||||
* @param apiComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.Color = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
__API_COMPONENT__;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.r)) {
|
||||
apiComponent.r = 1;
|
||||
}
|
||||
this.r = apiComponent.r;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.g)) {
|
||||
apiComponent.g = 1;
|
||||
}
|
||||
this.g = apiComponent.g;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.b)) {
|
||||
apiComponent.b = 1;
|
||||
}
|
||||
this.b = apiComponent.b;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.a)) {
|
||||
apiComponent.a = 0;
|
||||
}
|
||||
this.a = apiComponent.a;
|
||||
|
||||
};
|
||||
|
||||
R3.API.Color.prototype = Object.create(R3.API.Component.prototype);
|
||||
R3.API.Color.prototype.constructor = R3.API.Color;
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* R3.API.Controls
|
||||
* @param apiComponent
|
||||
*
|
||||
* @property canvas
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.Controls = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
__DEFINE_API_COMPONENT__
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.canvas)) {
|
||||
apiComponent.canvas = null;
|
||||
}
|
||||
this.canvas = apiComponent.canvas;
|
||||
};
|
||||
|
||||
R3.API.Controls.prototype = Object.create(R3.API.Component.prototype);
|
||||
R3.API.Controls.prototype.constructor = R3.API.Controls;
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* R3.API.Controls.D3
|
||||
* @param apiComponent
|
||||
*
|
||||
* @property camera
|
||||
* @property enabled
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.Controls.D3 = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
__DEFINE_API_COMPONENT__
|
||||
|
||||
R3.API.Controls.call(
|
||||
this,
|
||||
apiComponent
|
||||
);
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.camera)) {
|
||||
apiComponent.camera = null;
|
||||
}
|
||||
this.camera = apiComponent.camera;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.enabled)) {
|
||||
apiComponent.enabled = true;
|
||||
}
|
||||
this.enabled = apiComponent.enabled;
|
||||
|
||||
};
|
||||
|
||||
R3.API.Controls.D3.prototype = Object.create(R3.API.Controls.prototype);
|
||||
R3.API.Controls.D3.prototype.constructor = R3.API.Controls.D3;
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* R3.API.Controls.D3.FirstPerson
|
||||
* @param apiComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.Controls.D3.FirstPerson = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
__API_COMPONENT__;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.movementSpeed)) {
|
||||
apiComponent.movementSpeed = 1.0;
|
||||
}
|
||||
this.movementSpeed = apiComponent.movementSpeed;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.lookSpeed)) {
|
||||
apiComponent.lookSpeed = 0.005;
|
||||
}
|
||||
this.lookSpeed = apiComponent.lookSpeed;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.lookVertical)) {
|
||||
apiComponent.lookVertical = true;
|
||||
}
|
||||
this.lookVertical = apiComponent.lookVertical;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.autoForward)) {
|
||||
apiComponent.autoForward = false;
|
||||
}
|
||||
this.autoForward = apiComponent.autoForward;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.activeLook)) {
|
||||
apiComponent.activeLook = false;
|
||||
}
|
||||
this.activeLook = apiComponent.activeLook;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.heightSpeed)) {
|
||||
apiComponent.heightSpeed = false;
|
||||
}
|
||||
this.heightSpeed = apiComponent.heightSpeed;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.heightCoef)) {
|
||||
apiComponent.heightCoef = 1.0;
|
||||
}
|
||||
this.heightCoef = apiComponent.heightCoef;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.heightMin)) {
|
||||
apiComponent.heightMin = 0.0;
|
||||
}
|
||||
this.heightMin = apiComponent.heightMin;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.heightMax)) {
|
||||
apiComponent.heightMax = 1.0;
|
||||
}
|
||||
this.heightMax = apiComponent.heightMax;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.constrainVertical)) {
|
||||
apiComponent.constrainVertical = false;
|
||||
}
|
||||
this.constrainVertical = apiComponent.constrainVertical;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.verticalMin)) {
|
||||
apiComponent.verticalMin = 0;
|
||||
}
|
||||
this.verticalMin = apiComponent.verticalMin;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.verticalMax)) {
|
||||
apiComponent.verticalMax = Math.PI;
|
||||
}
|
||||
this.verticalMax = apiComponent.verticalMax;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.autoSpeedFactor)) {
|
||||
apiComponent.autoSpeedFactor = 0;
|
||||
}
|
||||
this.autoSpeedFactor = apiComponent.autoSpeedFactor;
|
||||
|
||||
R3.API.Controls.D3.call(
|
||||
this,
|
||||
apiComponent
|
||||
);
|
||||
};
|
||||
|
||||
R3.API.Controls.D3.FirstPerson.prototype = Object.create(R3.API.Controls.D3.prototype);
|
||||
R3.API.Controls.D3.FirstPerson.prototype.constructor = R3.API.Controls.D3.FirstPerson;
|
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* R3.API.Controls.D3.Orbit
|
||||
* @param apiComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.Controls.D3.Orbit = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
__API_COMPONENT__;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.target)) {
|
||||
apiComponent.target = null;
|
||||
}
|
||||
this.target = apiComponent.target;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.minPolarAngle)) {
|
||||
apiComponent.minPolarAngle = 0;
|
||||
}
|
||||
this.minPolarAngle = apiComponent.minPolarAngle;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.maxPolarAngle)) {
|
||||
apiComponent.maxPolarAngle = Math.PI;
|
||||
}
|
||||
this.maxPolarAngle = apiComponent.maxPolarAngle;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.enableDamping)) {
|
||||
apiComponent.enableDamping = false;
|
||||
}
|
||||
this.enableDamping = apiComponent.enableDamping;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.dampingFactor)) {
|
||||
apiComponent.dampingFactor = 0.25;
|
||||
}
|
||||
this.dampingFactor = apiComponent.dampingFactor;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.enableZoom)) {
|
||||
apiComponent.enableZoom = true;
|
||||
}
|
||||
this.enableZoom = apiComponent.enableZoom;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.zoomSpeed)) {
|
||||
apiComponent.zoomSpeed = 1.0;
|
||||
}
|
||||
this.zoomSpeed = apiComponent.zoomSpeed;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.enableRotate)) {
|
||||
apiComponent.enableRotate = true;
|
||||
}
|
||||
this.enableRotate = apiComponent.enableRotate;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.rotateSpeed)) {
|
||||
apiComponent.rotateSpeed = 1.0;
|
||||
}
|
||||
this.rotateSpeed = apiComponent.rotateSpeed;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.enablePan)) {
|
||||
apiComponent.enablePan = true;
|
||||
}
|
||||
this.enablePan = apiComponent.enablePan;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.keyPanSpeed)) {
|
||||
apiComponent.keyPanSpeed = 7.0;
|
||||
}
|
||||
this.keyPanSpeed = apiComponent.keyPanSpeed;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.autoRotate)) {
|
||||
apiComponent.autoRotate = false;
|
||||
}
|
||||
this.autoRotate = apiComponent.autoRotate;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.autoRotateSpeed)) {
|
||||
apiComponent.autoRotateSpeed = 2.0;
|
||||
}
|
||||
this.autoRotateSpeed = apiComponent.autoRotateSpeed;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.enableKeys)) {
|
||||
apiComponent.enableKeys = false;
|
||||
}
|
||||
this.enableKeys = apiComponent.enableKeys;
|
||||
|
||||
R3.API.Controls.D3.call(
|
||||
this,
|
||||
apiComponent
|
||||
);
|
||||
};
|
||||
|
||||
R3.API.Controls.D3.Orbit.prototype = Object.create(R3.API.Controls.D3.prototype);
|
||||
R3.API.Controls.D3.Orbit.prototype.constructor = R3.API.Controls.D3.Orbit;
|
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* R3.API.Controls.Keyboard
|
||||
* @param apiComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.Controls.Keyboard = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
__API_COMPONENT__;
|
||||
|
||||
R3.API.Controls.call(
|
||||
this,
|
||||
apiComponent
|
||||
);
|
||||
};
|
||||
|
||||
R3.API.Controls.Keyboard.prototype = Object.create(R3.API.Controls.prototype);
|
||||
R3.API.Controls.Keyboard.prototype.constructor = R3.API.Controls.Keyboard;
|
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* R3.API.Controls.Mouse
|
||||
* @param apiComponent
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.Controls.Mouse = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
__API_COMPONENT__;
|
||||
|
||||
R3.API.Controls.call(
|
||||
this,
|
||||
apiComponent
|
||||
);
|
||||
};
|
||||
|
||||
R3.API.Controls.Mouse.prototype = Object.create(R3.API.Controls.prototype);
|
||||
R3.API.Controls.Mouse.prototype.constructor = R3.API.Controls.Mouse;
|
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* R3.API.Controls.Touch
|
||||
* @param apiComponent
|
||||
*
|
||||
* @property sensitivity
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
R3.API.Controls.Touch = function(
|
||||
apiComponent
|
||||
) {
|
||||
|
||||
__API_COMPONENT__;
|
||||
|
||||
if (R3.Utils.UndefinedOrNull(apiComponent.sensitivity)) {
|
||||
apiComponent.sensitivity = 5;
|
||||
}
|
||||
this.sensitivity = apiComponent.sensitivity;
|
||||
|
||||
R3.API.Controls.call(
|
||||
this,
|
||||
apiComponent
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
R3.API.Controls.Touch.prototype = Object.create(R3.API.Controls.prototype);
|
||||
R3.API.Controls.Touch.prototype.constructor = R3.API.Controls.Touch;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue