editor to API
parent
f5d8c0d69f
commit
3adc03f200
|
@ -47,12 +47,12 @@ GameLib.API.Component.FromObjectComponent = function(objectComponent) {
|
||||||
return GameLib.D3.API.Renderer.FromObjectComponent(objectComponent);
|
return GameLib.D3.API.Renderer.FromObjectComponent(objectComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectComponent.componentType === GameLib.Component.COMPONENT_STEREO_RENDERER) {
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_COMPOSER) {
|
||||||
return GameLib.D3.API.Renderer.FromObjectComponent(objectComponent);
|
return GameLib.D3.API.Composer.FromObjectComponent(objectComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectComponent.componentType === GameLib.Component.COMPONENT_STEREO_CAMERA) {
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_PASS) {
|
||||||
return GameLib.D3.API.Camera.FromObjectComponent(objectComponent);
|
return GameLib.D3.API.Pass.FromObjectComponent(objectComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectComponent.componentType === GameLib.Component.COMPONENT_LOOK_AT) {
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_LOOK_AT) {
|
||||||
|
@ -63,8 +63,8 @@ GameLib.API.Component.FromObjectComponent = function(objectComponent) {
|
||||||
return GameLib.D3.API.Follow.FromObjectComponent(objectComponent);
|
return GameLib.D3.API.Follow.FromObjectComponent(objectComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectComponent.componentType === GameLib.Component.COMPONENT_MESH) {
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_RENDER_TARGET) {
|
||||||
return GameLib.D3.API.Mesh.FromObjectComponent(objectComponent);
|
return GameLib.D3.API.RenderTarget.FromObjectComponent(objectComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectComponent.componentType === GameLib.Component.COMPONENT_SPLINE) {
|
if (objectComponent.componentType === GameLib.Component.COMPONENT_SPLINE) {
|
||||||
|
|
|
@ -36,9 +36,13 @@ GameLib.Component.COMPONENT_MESH = 0x8;
|
||||||
GameLib.Component.COMPONENT_SPLINE = 0x9;
|
GameLib.Component.COMPONENT_SPLINE = 0x9;
|
||||||
GameLib.Component.COMPONENT_LIGHT = 0xa;
|
GameLib.Component.COMPONENT_LIGHT = 0xa;
|
||||||
GameLib.Component.COMPONENT_INPUT_DRIVE = 0xb;
|
GameLib.Component.COMPONENT_INPUT_DRIVE = 0xb;
|
||||||
GameLib.Component.COMPONENT_STEREO_RENDERER = 0xc;
|
GameLib.Component.COMPONENT_COMPOSER = 0xc;
|
||||||
GameLib.Component.COMPONENT_STEREO_CAMERA = 0xd;
|
GameLib.Component.COMPONENT_RENDER_TARGET = 0xd;
|
||||||
GameLib.Component.COMPONENT_ORTHOGONAL_CAMERA = 0xe;
|
GameLib.Component.COMPONENT_PASS = 0xe;
|
||||||
|
GameLib.Component.COMPONENT_SCENE = 0xf;
|
||||||
|
GameLib.Component.COMPONENT_GAME = 0x10;
|
||||||
|
GameLib.Component.COMPONENT_INPUT_EDITOR = 0x11;
|
||||||
|
GameLib.Component.COMPONENT_EDITOR = 0x12;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Components are linked at runtime - for storing, we just store the ID
|
* Components are linked at runtime - for storing, we just store the ID
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
/**
|
||||||
|
* This component renders a scene
|
||||||
|
* @param id String
|
||||||
|
* @param name String
|
||||||
|
* @param renderer GameLib.D3.Renderer
|
||||||
|
* @param renderTarget GameLib.D3.API.RenderTarget
|
||||||
|
* @param passes GameLib.D3.API.Pass[]
|
||||||
|
* @param parentEntity
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Composer = function (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
renderer,
|
||||||
|
renderTarget,
|
||||||
|
passes,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_COMPOSER,
|
||||||
|
{
|
||||||
|
'renderer' : GameLib.D3.Renderer,
|
||||||
|
'renderTarget' : GameLib.D3.RenderTarget,
|
||||||
|
'passes' : [GameLib.D3.Pass]
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Composer (' + id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(renderer)) {
|
||||||
|
renderer = null;
|
||||||
|
}
|
||||||
|
this.renderer = renderer;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(renderTarget)) {
|
||||||
|
renderTarget = null;
|
||||||
|
}
|
||||||
|
this.renderTarget = renderTarget;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(passes)) {
|
||||||
|
passes = [];
|
||||||
|
}
|
||||||
|
this.passes = passes;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Composer.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.Composer.prototype.constructor = GameLib.D3.API.Composer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.Composer
|
||||||
|
* @param objectComponent
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Composer.FromObjectComponent = function(objectComponent) {
|
||||||
|
return new GameLib.D3.API.Composer(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.renderer,
|
||||||
|
objectComponent.renderTarget,
|
||||||
|
objectComponent.passes,
|
||||||
|
objectComponent.parentEntity
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,63 @@
|
||||||
|
/**
|
||||||
|
* Raw Editor API object - should always correspond with the Editor Schema
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
|
* @param games [GameLib.API.D3.Game]
|
||||||
|
* @param allSelected
|
||||||
|
* @param parentEntity
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Editor = function(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
games,
|
||||||
|
allSelected,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_EDITOR,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Editor (' + this.id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(games)) {
|
||||||
|
games = [];
|
||||||
|
}
|
||||||
|
this.games = games;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(allSelected)) {
|
||||||
|
allSelected = false;
|
||||||
|
}
|
||||||
|
this.allSelected = allSelected;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Editor.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.Editor.prototype.constructor = GameLib.D3.API.Editor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an API Editor from an Object Editor
|
||||||
|
* @param objectEditor
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Editor.FromObjectEditor = function(objectEditor) {
|
||||||
|
return new GameLib.D3.API.Editor(
|
||||||
|
objectEditor.id,
|
||||||
|
objectEditor.name,
|
||||||
|
objectEditor.games,
|
||||||
|
objectEditor.allSelected,
|
||||||
|
objectEditor.parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,223 @@
|
||||||
|
/**
|
||||||
|
* Raw Game API object - should always correspond with the Game Schema
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
|
* @param gameType
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
* @param scenes
|
||||||
|
* @param cameras
|
||||||
|
* @param renderers
|
||||||
|
* @param composers
|
||||||
|
* @param systems
|
||||||
|
* @param entityManager
|
||||||
|
* @param mouse
|
||||||
|
* @param raycaster
|
||||||
|
* @param activeCameraIndex
|
||||||
|
* @param activeRendererIndex
|
||||||
|
* @param parentEntity
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Game = function(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
gameType,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
scenes,
|
||||||
|
cameras,
|
||||||
|
renderers,
|
||||||
|
composers,
|
||||||
|
systems,
|
||||||
|
entityManager,
|
||||||
|
mouse,
|
||||||
|
raycaster,
|
||||||
|
activeCameraIndex,
|
||||||
|
activeRendererIndex,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_GAME,
|
||||||
|
{
|
||||||
|
'scenes' : [GameLib.D3.Scene],
|
||||||
|
'cameras' : [GameLib.D3.Camera],
|
||||||
|
'renderers' : [GameLib.D3.Renderer],
|
||||||
|
'composers' : [GameLib.D3.Composer],
|
||||||
|
'systems' : [GameLib.D3.System],
|
||||||
|
'entityManager' : GameLib.EntityManager,
|
||||||
|
'mouse' : GameLib.D3.Mouse,
|
||||||
|
'raycaster' : GameLib.D3.Raycaster
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Game (' + this.id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(gameType)) {
|
||||||
|
gameType = GameLib.D3.Game.GAME_TYPE_VR_PONG;
|
||||||
|
}
|
||||||
|
this.gameType = gameType;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||||
|
width = 800;
|
||||||
|
}
|
||||||
|
this.width = width;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||||
|
height = 600;
|
||||||
|
}
|
||||||
|
this.height = height;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(scenes)) {
|
||||||
|
scenes = [];
|
||||||
|
}
|
||||||
|
this.scenes = scenes;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(cameras)) {
|
||||||
|
cameras = [];
|
||||||
|
}
|
||||||
|
this.cameras = cameras;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(renderers)) {
|
||||||
|
renderers = [];
|
||||||
|
}
|
||||||
|
this.renderers = renderers;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(composers)) {
|
||||||
|
composers = [];
|
||||||
|
}
|
||||||
|
this.composers = composers;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(systems)) {
|
||||||
|
systems = [];
|
||||||
|
}
|
||||||
|
this.systems = systems;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(entityManager)) {
|
||||||
|
entityManager = new GameLib.API.EntityManager();
|
||||||
|
}
|
||||||
|
this.entityManager = entityManager;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(mouse)) {
|
||||||
|
mouse = null;
|
||||||
|
}
|
||||||
|
this.mouse = mouse;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(raycaster)) {
|
||||||
|
raycaster = null;
|
||||||
|
}
|
||||||
|
this.raycaster = raycaster;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(activeCameraIndex)) {
|
||||||
|
activeCameraIndex = 0;
|
||||||
|
}
|
||||||
|
this.activeCameraIndex = activeCameraIndex;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(activeRendererIndex)) {
|
||||||
|
activeRendererIndex = 0;
|
||||||
|
}
|
||||||
|
this.activeRendererIndex = activeRendererIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Game.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.Game.prototype.constructor = GameLib.D3.API.Game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an API camera from an Object camera
|
||||||
|
* @param objectGame
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Game.FromObjectGame = function(objectGame) {
|
||||||
|
|
||||||
|
var apiScenes = [];
|
||||||
|
var apiCameras = [];
|
||||||
|
var apiRenderers = [];
|
||||||
|
var apiComposers = [];
|
||||||
|
var apiSystems = [];
|
||||||
|
|
||||||
|
var apiEntityManager = null;
|
||||||
|
var apiMouse = null;
|
||||||
|
var apiRaycaster = null;
|
||||||
|
|
||||||
|
if (objectGame.scenes) {
|
||||||
|
apiScenes = objectGame.scenes.map(
|
||||||
|
function(objectScene){
|
||||||
|
return GameLib.API.Scene.FromObjectScene(objectScene);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectGame.cameras) {
|
||||||
|
apiCameras = objectGame.cameras.map(
|
||||||
|
function(objectCamera){
|
||||||
|
return GameLib.API.Camera.FromObjectCamera(objectCamera);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectGame.renderers) {
|
||||||
|
apiRenderers = objectGame.renderers.map(
|
||||||
|
function(objectRenderer){
|
||||||
|
return GameLib.API.Renderer.FromObjectComponent(objectRenderer);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectGame.composers) {
|
||||||
|
apiComposers = objectGame.composers.map(
|
||||||
|
function(objectComposer){
|
||||||
|
return GameLib.API.Composer.FromObjectComponent(objectComposer);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectGame.systems) {
|
||||||
|
apiSystems = objectGame.systems.map(
|
||||||
|
function(objectSystem){
|
||||||
|
return GameLib.API.System.FromObjectComponent(objectSystem);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectGame.entityManager) {
|
||||||
|
apiEntityManager = GameLib.API.Entity.FromObjectEntity(objectGame.entityManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectGame.mouse) {
|
||||||
|
apiMouse = GameLib.API.Mouse.FromObjectMouse(objectGame.mouse);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectGame.raycaster) {
|
||||||
|
apiRaycaster = GameLib.API.Raycaster.FromObjectRaycaster(objectGame.raycaster);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GameLib.D3.API.Game(
|
||||||
|
objectGame.id,
|
||||||
|
objectGame.name,
|
||||||
|
objectGame.gameType,
|
||||||
|
objectGame.width,
|
||||||
|
objectGame.height,
|
||||||
|
apiScenes,
|
||||||
|
apiCameras,
|
||||||
|
apiRenderers,
|
||||||
|
apiComposers,
|
||||||
|
apiSystems,
|
||||||
|
apiEntityManager,
|
||||||
|
apiMouse,
|
||||||
|
apiRaycaster,
|
||||||
|
objectGame.activeCameraIndex,
|
||||||
|
objectGame.activeRendererIndex,
|
||||||
|
objectGame.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,65 @@
|
||||||
|
/**
|
||||||
|
* This component makes the parentEntity (ex. car) follow the path provided by the spline
|
||||||
|
* @param id String
|
||||||
|
* @param name String
|
||||||
|
* @param domElementId
|
||||||
|
* @param camera
|
||||||
|
* @param parentEntity
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Input.Editor = function (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
domElementId,
|
||||||
|
camera,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_INPUT_EDITOR,
|
||||||
|
{
|
||||||
|
'camera' : GameLib.D3.Camera
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = this.constructor.name;
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(domElementId)) {
|
||||||
|
domElementId = 'divCanvas';
|
||||||
|
}
|
||||||
|
this.domElementId = domElementId;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
||||||
|
camera = null;
|
||||||
|
}
|
||||||
|
this.camera = camera;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Input.Editor.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.Input.Editor.prototype.constructor = GameLib.D3.API.Input.Editor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.Input.Editor
|
||||||
|
* @param objectComponent
|
||||||
|
* @returns {GameLib.D3.API.Input.Editor}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Input.Editor.FromObjectComponent = function(objectComponent) {
|
||||||
|
return new GameLib.D3.API.Input.Editor(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.domElementId,
|
||||||
|
objectComponent.camera,
|
||||||
|
objectComponent.parentEntity
|
||||||
|
);
|
||||||
|
};
|
|
@ -52,8 +52,10 @@ GameLib.D3.API.Mesh = function(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_MESH,
|
GameLib.Component.COMPONENT_MESH,
|
||||||
{
|
{
|
||||||
'parentMesh' : GameLib.D3.Mesh,
|
'parentMesh' : GameLib.D3.Mesh,
|
||||||
'parentScene' : GameLib.D3.Scene
|
'parentScene' : GameLib.D3.Scene,
|
||||||
|
'materials' : [GameLib.D3.Material],
|
||||||
|
'skeleton' : GameLib.D3.Skeleton
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
parentEntity
|
parentEntity
|
||||||
|
@ -176,40 +178,89 @@ GameLib.D3.API.Mesh.prototype.constructor = GameLib.D3.API.Mesh;
|
||||||
GameLib.D3.API.Mesh.FromObjectMesh = function (objectMesh){
|
GameLib.D3.API.Mesh.FromObjectMesh = function (objectMesh){
|
||||||
|
|
||||||
var apiSkeleton = null;
|
var apiSkeleton = null;
|
||||||
|
|
||||||
if (objectMesh.skeleton) {
|
if (objectMesh.skeleton) {
|
||||||
apiSkeleton = GameLib.D3.API.Skeleton.FromObjectSkeleton(objectMesh.skeleton);
|
apiSkeleton = GameLib.D3.API.Skeleton.FromObjectSkeleton(objectMesh.skeleton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var apiMaterials = [];
|
||||||
|
if (objectMesh.materials) {
|
||||||
|
apiMaterials = objectMesh.materials.map(
|
||||||
|
function (objectMaterial) {
|
||||||
|
return GameLib.D3.API.Material.FromObjectMaterial(objectMaterial);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiVertices = [];
|
||||||
|
if (objectMesh.vertices) {
|
||||||
|
apiVertices = objectMesh.vertices.map(
|
||||||
|
function (objectVertex) {
|
||||||
|
return GameLib.D3.API.Vertex.FromObjectVertex(objectVertex);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiPosition = new GameLib.API.Vector3();
|
||||||
|
if (objectMesh.position) {
|
||||||
|
apiPosition = GameLib.API.Vector3.FromObjectVector(objectMesh.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiQuaternion = new GameLib.API.Quaternion();
|
||||||
|
if (objectMesh.quaternion) {
|
||||||
|
apiQuaternion = GameLib.API.Quaternion.FromObjectQuaternion(objectMesh.quaternion);
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiScale = new GameLib.API.Vector3(1,1,1);
|
||||||
|
if (objectMesh.scale) {
|
||||||
|
apiScale = GameLib.API.Vector3.FromObjectVector(objectMesh.scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiLocalPosition = new GameLib.API.Vector3();
|
||||||
|
if (objectMesh.localPosition) {
|
||||||
|
apiLocalPosition = GameLib.API.Vector3.FromObjectVector(objectMesh.localPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiLocalRotation = new GameLib.API.Vector3();
|
||||||
|
if (objectMesh.localRotation) {
|
||||||
|
apiLocalRotation = GameLib.API.Vector3.FromObjectVector(objectMesh.localRotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiLocalScale = new GameLib.API.Vector3(1,1,1);
|
||||||
|
if (objectMesh.localScale) {
|
||||||
|
apiLocalScale = GameLib.API.Vector3.FromObjectVector(objectMesh.localScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiUp = new GameLib.API.Vector3(0,1,0);
|
||||||
|
if (objectMesh.up) {
|
||||||
|
apiUp = GameLib.API.Vector3.FromObjectVector(objectMesh.up);
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiModelMatrix = new GameLib.API.Matrix4();
|
||||||
|
if (objectMesh.modelMatrix) {
|
||||||
|
apiModelMatrix = GameLib.API.Matrix4.FromObjectMatrix(objectMesh.modelMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
return new GameLib.D3.API.Mesh(
|
return new GameLib.D3.API.Mesh(
|
||||||
objectMesh.id,
|
objectMesh.id,
|
||||||
objectMesh.meshType,
|
objectMesh.meshType,
|
||||||
objectMesh.name,
|
objectMesh.name,
|
||||||
objectMesh.vertices.map(
|
apiVertices,
|
||||||
function (objectVertex) {
|
|
||||||
return GameLib.D3.API.Vertex.FromObjectVertex(objectVertex);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
objectMesh.faces,
|
objectMesh.faces,
|
||||||
objectMesh.faceVertexUvs,
|
objectMesh.faceVertexUvs,
|
||||||
objectMesh.materials.map(
|
apiMaterials,
|
||||||
function (objectMaterial) {
|
|
||||||
return GameLib.D3.API.Material.FromObjectMaterial(objectMaterial);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
objectMesh.parentMesh,
|
objectMesh.parentMesh,
|
||||||
objectMesh.parentScene,
|
objectMesh.parentScene,
|
||||||
apiSkeleton,
|
apiSkeleton,
|
||||||
objectMesh.skinIndices,
|
objectMesh.skinIndices,
|
||||||
objectMesh.skinWeights,
|
objectMesh.skinWeights,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectMesh.position),
|
apiPosition,
|
||||||
GameLib.API.Quaternion.FromObjectQuaternion(objectMesh.quaternion),
|
apiQuaternion,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectMesh.scale),
|
apiScale,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectMesh.localPosition),
|
apiLocalPosition,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectMesh.localRotation),
|
apiLocalRotation,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectMesh.localScale),
|
apiLocalScale,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectMesh.up),
|
apiUp,
|
||||||
GameLib.API.Matrix4.FromObjectMatrix(objectMesh.modelMatrix),
|
apiModelMatrix,
|
||||||
objectMesh.parentEntity,
|
objectMesh.parentEntity,
|
||||||
objectMesh.renderOrder
|
objectMesh.renderOrder
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
/**
|
||||||
|
* This component renders a scene
|
||||||
|
* @param id String
|
||||||
|
* @param name String
|
||||||
|
* @param passType
|
||||||
|
* @param camera
|
||||||
|
* @param scene
|
||||||
|
* @param renderToScreen
|
||||||
|
* @param parentEntity
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Pass = function (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
passType,
|
||||||
|
camera,
|
||||||
|
scene,
|
||||||
|
renderToScreen,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_PASS,
|
||||||
|
{
|
||||||
|
'camera' : GameLib.D3.Camera,
|
||||||
|
'scene' : GameLib.D3.Scene
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Render Pass (' + id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Render Pass (' + id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(passType)) {
|
||||||
|
passType = GameLib.D3.Pass.PASS_TYPE_RENDER;
|
||||||
|
}
|
||||||
|
this.passType = passType;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(scene)) {
|
||||||
|
scene = null;
|
||||||
|
}
|
||||||
|
this.scene = scene;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(renderToScreen)) {
|
||||||
|
|
||||||
|
if (this.passType == GameLib.D3.Pass.PASS_TYPE_RENDER) {
|
||||||
|
renderToScreen = false;
|
||||||
|
} else if (GameLib.D3.Pass.PASS_TYPE_COPY_SHADER) {
|
||||||
|
renderToScreen = true;
|
||||||
|
} else {
|
||||||
|
console.warn('Unsupported Render Pass Type : ' + this.passType);
|
||||||
|
throw new Error('Unsupported Render Pass Type : ' + this.passType);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
this.renderToScreen = renderToScreen;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Pass.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.Pass.prototype.constructor = GameLib.D3.API.Pass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.Pass
|
||||||
|
* @param objectComponent
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Pass.FromObjectComponent = function(objectComponent) {
|
||||||
|
return new GameLib.D3.API.Pass(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.passType,
|
||||||
|
objectComponent.camera,
|
||||||
|
objectComponent.scene,
|
||||||
|
objectComponent.renderToScreen,
|
||||||
|
objectComponent.parentEntity
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,96 @@
|
||||||
|
/**
|
||||||
|
* This component renders a scene
|
||||||
|
* @param id String
|
||||||
|
* @param name String
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
* @param minFilter
|
||||||
|
* @param magFilter
|
||||||
|
* @param format
|
||||||
|
* @param stencilBuffer
|
||||||
|
* @param parentEntity
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.RenderTarget = function (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
minFilter,
|
||||||
|
magFilter,
|
||||||
|
format,
|
||||||
|
stencilBuffer,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_RENDER_TARGET,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Render Target (' + id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(width)) {
|
||||||
|
width = 800;
|
||||||
|
}
|
||||||
|
this.width = width;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(height)) {
|
||||||
|
height = 600;
|
||||||
|
}
|
||||||
|
this.height = height;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(minFilter)) {
|
||||||
|
minFilter = GameLib.D3.RenderTarget.LINEAR_FILTER;
|
||||||
|
}
|
||||||
|
this.minFilter = minFilter;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(magFilter)) {
|
||||||
|
magFilter = GameLib.D3.RenderTarget.LINEAR_FILTER;
|
||||||
|
}
|
||||||
|
this.magFilter = magFilter;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(format)) {
|
||||||
|
format = GameLib.D3.RenderTarget.RGB_FORMAT;
|
||||||
|
}
|
||||||
|
this.format = format;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(stencilBuffer)) {
|
||||||
|
stencilBuffer = false;
|
||||||
|
}
|
||||||
|
this.stencilBuffer = stencilBuffer;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.RenderTarget.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.D3.API.RenderTarget.prototype.constructor = GameLib.D3.API.RenderTarget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object to GameLib.D3.API.RenderTarget
|
||||||
|
* @param objectComponent
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.RenderTarget.FromObjectComponent = function(objectComponent) {
|
||||||
|
return new GameLib.D3.API.RenderTarget(
|
||||||
|
objectComponent.id,
|
||||||
|
objectComponent.name,
|
||||||
|
objectComponent.width,
|
||||||
|
objectComponent.height,
|
||||||
|
objectComponent.minFilter,
|
||||||
|
objectComponent.magFilter,
|
||||||
|
objectComponent.format,
|
||||||
|
objectComponent.stencilBuffer,
|
||||||
|
objectComponent.parentEntity
|
||||||
|
);
|
||||||
|
};
|
|
@ -3,41 +3,33 @@
|
||||||
* @param id String
|
* @param id String
|
||||||
* @param name String
|
* @param name String
|
||||||
* @param rendererType
|
* @param rendererType
|
||||||
* @param scene GameLib.D3.Scene
|
|
||||||
* @param camera GameLib.D3.Camera
|
|
||||||
* @param autoClear bool
|
* @param autoClear bool
|
||||||
* @param localClipping
|
* @param localClipping
|
||||||
* @param width
|
* @param width
|
||||||
* @param height
|
* @param height
|
||||||
* @param parentEntity
|
* @param parentEntity
|
||||||
* @param preserveDrawingBuffer
|
* @param preserveDrawingBuffer
|
||||||
|
* @param composer GameLib.D3.API.Composer
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Renderer = function (
|
GameLib.D3.API.Renderer = function (
|
||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
rendererType,
|
rendererType,
|
||||||
scene,
|
|
||||||
camera,
|
|
||||||
autoClear,
|
autoClear,
|
||||||
localClipping,
|
localClipping,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
parentEntity,
|
parentEntity,
|
||||||
preserveDrawingBuffer
|
preserveDrawingBuffer,
|
||||||
|
composer
|
||||||
) {
|
) {
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(rendererType)) {
|
|
||||||
rendererType = GameLib.Component.COMPONENT_RENDERER;
|
|
||||||
}
|
|
||||||
this.rendererType = rendererType;
|
|
||||||
|
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
rendererType,
|
GameLib.Component.COMPONENT_RENDERER,
|
||||||
{
|
{
|
||||||
'scene' : GameLib.D3.Scene,
|
'composer' : GameLib.D3.Composer
|
||||||
'camera' : GameLib.D3.Camera
|
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
parentEntity
|
parentEntity
|
||||||
|
@ -53,18 +45,21 @@ GameLib.D3.API.Renderer = function (
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(scene)) {
|
if (GameLib.Utils.UndefinedOrNull(rendererType)) {
|
||||||
scene = null;
|
rendererType = GameLib.D3.Renderer.RENDER_TYPE_NORMAL;
|
||||||
}
|
}
|
||||||
this.scene = scene;
|
this.rendererType = rendererType;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(camera)) {
|
|
||||||
camera = null;
|
|
||||||
}
|
|
||||||
this.camera = camera;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(autoClear)) {
|
if (GameLib.Utils.UndefinedOrNull(autoClear)) {
|
||||||
autoClear = true;
|
|
||||||
|
if (this.rendererType == GameLib.D3.Renderer.RENDER_TYPE_NORMAL) {
|
||||||
|
autoClear = true;
|
||||||
|
} else if (this.rendererType == GameLib.D3.Renderer.RENDER_TYPE_STEREO) {
|
||||||
|
autoClear = false;
|
||||||
|
} else {
|
||||||
|
console.warn('Unhandled render type : ' + this.rendererType);
|
||||||
|
throw new Error('Unhandled render type : ' + this.rendererType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.autoClear = autoClear;
|
this.autoClear = autoClear;
|
||||||
|
|
||||||
|
@ -84,9 +79,22 @@ GameLib.D3.API.Renderer = function (
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(preserveDrawingBuffer)) {
|
if (GameLib.Utils.UndefinedOrNull(preserveDrawingBuffer)) {
|
||||||
preserveDrawingBuffer = false;
|
|
||||||
|
if (this.rendererType == GameLib.D3.Renderer.RENDER_TYPE_NORMAL) {
|
||||||
|
preserveDrawingBuffer = false;
|
||||||
|
} else if (this.rendererType == GameLib.D3.Renderer.RENDER_TYPE_STEREO) {
|
||||||
|
preserveDrawingBuffer = true;
|
||||||
|
} else {
|
||||||
|
console.warn('Unhandled render type : ' + this.rendererType);
|
||||||
|
throw new Error('Unhandled render type : ' + this.rendererType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.preserveDrawingBuffer = preserveDrawingBuffer;
|
this.preserveDrawingBuffer = preserveDrawingBuffer;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(composer)) {
|
||||||
|
composer = null;
|
||||||
|
}
|
||||||
|
this.composer = composer;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.API.Renderer.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.API.Renderer.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
@ -102,13 +110,12 @@ GameLib.D3.API.Renderer.FromObjectComponent = function(objectComponent) {
|
||||||
objectComponent.id,
|
objectComponent.id,
|
||||||
objectComponent.name,
|
objectComponent.name,
|
||||||
objectComponent.rendererType,
|
objectComponent.rendererType,
|
||||||
objectComponent.scene,
|
|
||||||
objectComponent.camera,
|
|
||||||
objectComponent.autoClear,
|
objectComponent.autoClear,
|
||||||
objectComponent.localClipping,
|
objectComponent.localClipping,
|
||||||
objectComponent.width,
|
objectComponent.width,
|
||||||
objectComponent.height,
|
objectComponent.height,
|
||||||
objectComponent.parentEntity,
|
objectComponent.parentEntity,
|
||||||
objectComponent.preserveDrawingBuffer
|
objectComponent.preserveDrawingBuffer,
|
||||||
|
objectComponent.composer
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,76 +1,69 @@
|
||||||
/**
|
/**
|
||||||
* Raw Scene API object - should always correspond with the Scene Schema
|
* Raw Scene API object - should always correspond with the Scene Schema
|
||||||
* @param id String
|
* @param id String
|
||||||
* @param path String
|
|
||||||
* @param name String
|
* @param name String
|
||||||
* @param width
|
* @param baseUrl String
|
||||||
* @param height
|
* @param path String
|
||||||
* @param meshes GameLib.D3.API.Mesh []
|
* @param meshes [GameLib.D3.API.Mesh]
|
||||||
* @param position GameLib.API.Vector3
|
* @param position GameLib.API.Vector3
|
||||||
* @param quaternion GameLib.API.Quaternion
|
* @param quaternion GameLib.API.Quaternion
|
||||||
* @param scale GameLib.API.Vector3
|
* @param scale GameLib.API.Vector3
|
||||||
* @param parentSceneId
|
* @param parentGameId
|
||||||
* @param lights GameLib.D3.API.Light[]
|
* @param lights [GameLib.D3.API.Light]
|
||||||
* @param worlds GameLib.D3.API.World[]
|
* @param materials [GameLib.D3.API.Material]
|
||||||
* @param entityManager GameLib.EntityManager
|
* @param textures [GameLib.D3.API.Texture]
|
||||||
* @param shapes GameLib.D3.API.Shape[]
|
* @param parentEntity
|
||||||
* @param cameras
|
|
||||||
* @param activeCameraIndex
|
|
||||||
* @param textures GameLib.D3.Texture[] - additional textures
|
|
||||||
* @param renderers
|
|
||||||
* @param activeRendererIndex
|
|
||||||
* @param raycaster
|
|
||||||
* @param mouse
|
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Scene = function(
|
GameLib.D3.API.Scene = function(
|
||||||
id,
|
id,
|
||||||
path,
|
|
||||||
name,
|
name,
|
||||||
width,
|
baseUrl,
|
||||||
height,
|
path,
|
||||||
meshes,
|
meshes,
|
||||||
position,
|
position,
|
||||||
quaternion,
|
quaternion,
|
||||||
scale,
|
scale,
|
||||||
parentSceneId,
|
parentGameId,
|
||||||
lights,
|
lights,
|
||||||
worlds,
|
materials,
|
||||||
entityManager,
|
|
||||||
shapes,
|
|
||||||
cameras,
|
|
||||||
activeCameraIndex,
|
|
||||||
textures,
|
textures,
|
||||||
renderers,
|
parentEntity
|
||||||
activeRendererIndex,
|
|
||||||
raycaster,
|
|
||||||
mouse
|
|
||||||
) {
|
) {
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.COMPONENT_SCENE,
|
||||||
|
{
|
||||||
|
'meshes' : [GameLib.D3.Mesh],
|
||||||
|
'lights' : [GameLib.D3.Light],
|
||||||
|
'textures' : [GameLib.D3.Texture],
|
||||||
|
'materials' : [GameLib.D3.Material]
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.Utils.RandomId();
|
id = GameLib.Utils.RandomId();
|
||||||
}
|
}
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Scene (' + this.id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.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 (GameLib.Utils.UndefinedOrNull(path)) {
|
if (GameLib.Utils.UndefinedOrNull(path)) {
|
||||||
path = null;
|
path = null;
|
||||||
}
|
}
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
||||||
name = 'unnamed';
|
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(width)) {
|
|
||||||
width = 800;
|
|
||||||
}
|
|
||||||
this.width = width;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(height)) {
|
|
||||||
height = 600;
|
|
||||||
}
|
|
||||||
this.height = height;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(meshes)) {
|
if (GameLib.Utils.UndefinedOrNull(meshes)) {
|
||||||
meshes = [];
|
meshes = [];
|
||||||
}
|
}
|
||||||
|
@ -91,87 +84,30 @@ GameLib.D3.API.Scene = function(
|
||||||
}
|
}
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentSceneId)) {
|
if (GameLib.Utils.UndefinedOrNull(parentGameId)) {
|
||||||
parentSceneId = null;
|
parentGameId = null;
|
||||||
}
|
}
|
||||||
this.parentSceneId = parentSceneId;
|
this.parentGameId = parentGameId;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(lights)) {
|
if (GameLib.Utils.UndefinedOrNull(lights)) {
|
||||||
lights = [];
|
lights = [];
|
||||||
}
|
}
|
||||||
this.lights = lights;
|
this.lights = lights;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(worlds)) {
|
if (GameLib.Utils.UndefinedOrNull(materials)) {
|
||||||
worlds = [];
|
materials = [];
|
||||||
}
|
}
|
||||||
this.worlds = worlds;
|
this.materials = materials;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(entityManager)) {
|
|
||||||
entityManager = new GameLib.API.EntityManager();
|
|
||||||
}
|
|
||||||
this.entityManager = entityManager;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(shapes)) {
|
|
||||||
shapes = [];
|
|
||||||
}
|
|
||||||
this.shapes = shapes;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(cameras)) {
|
|
||||||
cameras = [
|
|
||||||
new GameLib.D3.API.Camera(
|
|
||||||
null,
|
|
||||||
GameLib.Component.COMPONENT_CAMERA,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
this.width / this.height
|
|
||||||
)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
this.cameras = cameras;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(activeCameraIndex)) {
|
|
||||||
activeCameraIndex = 0;
|
|
||||||
}
|
|
||||||
this.activeCameraIndex = activeCameraIndex;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(textures)) {
|
if (GameLib.Utils.UndefinedOrNull(textures)) {
|
||||||
textures = [];
|
textures = [];
|
||||||
}
|
}
|
||||||
this.textures = textures;
|
this.textures = textures;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(renderers)) {
|
|
||||||
renderers = [
|
|
||||||
new GameLib.D3.API.Renderer(
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
GameLib.Component.COMPONENT_RENDERER,
|
|
||||||
this,
|
|
||||||
this.cameras[this.activeCameraIndex],
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
this.width,
|
|
||||||
this.height
|
|
||||||
)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
this.renderers = renderers;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(activeRendererIndex)) {
|
|
||||||
activeRendererIndex = 0;
|
|
||||||
}
|
|
||||||
this.activeRendererIndex = activeRendererIndex;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(raycaster)) {
|
|
||||||
raycaster = new GameLib.D3.API.Raycaster();
|
|
||||||
}
|
|
||||||
this.raycaster = raycaster;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(mouse)) {
|
|
||||||
mouse = new GameLib.API.Mouse();
|
|
||||||
}
|
|
||||||
this.mouse = mouse;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.Scene.prototype = Object.create(GameLib.Scene.prototype);
|
||||||
|
GameLib.D3.API.Scene.prototype.constructor = GameLib.D3.API.Scene;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an API scene from an Object scene
|
* Returns an API scene from an Object scene
|
||||||
* @param objectScene
|
* @param objectScene
|
||||||
|
@ -179,75 +115,73 @@ GameLib.D3.API.Scene = function(
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
|
GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
|
||||||
|
|
||||||
var apiEntityManager = null;
|
var apiMeshes = [];
|
||||||
|
var apiLights = [];
|
||||||
|
var apiMaterials = [];
|
||||||
|
var apiTextures = [];
|
||||||
|
|
||||||
var apiTextures = null;
|
var apiPosition = new GameLib.API.Vector3();
|
||||||
var apiRenderers = null;
|
var apiQuaternion = new GameLib.API.Quaternion();
|
||||||
var apiRaycaster = null;
|
var apiScale = new GameLib.API.Vector3(1,1,1);
|
||||||
var apiMouse = null;
|
|
||||||
|
|
||||||
if (objectScene.entityManager) {
|
if (objectScene.meshes) {
|
||||||
apiEntityManager = GameLib.API.EntityManager.FromObjectEntityManager(objectScene.entityManager);
|
apiMeshes = objectScene.meshes.map(
|
||||||
|
function(objectMesh) {
|
||||||
|
return GameLib.D3.API.Mesh.FromObjectMesh(objectMesh);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectScene.lights) {
|
||||||
|
apiLights = objectScene.lights.map(
|
||||||
|
function(objectLight) {
|
||||||
|
return GameLib.D3.API.Light.FromObjectLight(objectLight);
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectScene.textures) {
|
if (objectScene.textures) {
|
||||||
apiTextures = objectScene.textures.map(
|
apiTextures = objectScene.textures.map(
|
||||||
function(objectTexture) {
|
function(objectTexture) {
|
||||||
return GameLib.D3.API.Texture.FromObjectTexture(objectTexture)
|
return GameLib.D3.API.Texture.FromObjectTexture(objectTexture);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectScene.renderers) {
|
if (objectScene.materials) {
|
||||||
apiRenderers = objectScene.renderers.map(
|
apiMaterials = objectScene.materials.map(
|
||||||
function(objectRenderer) {
|
function(objectMaterial) {
|
||||||
return GameLib.D3.API.Renderer.FromObjectComponent(objectRenderer)
|
return GameLib.D3.API.Material.FromObjectMaterial(objectMaterial);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectScene.raycaster) {
|
if (objectScene.position) {
|
||||||
apiRaycaster = GameLib.D3.API.Raycaster.FromObjectRaycaster(objectScene.raycaster);
|
apiPosition = GameLib.API.Vector3.FromObjectVector(objectScene.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectScene.mouse) {
|
if (objectScene.quaternion) {
|
||||||
apiMouse = GameLib.API.Mouse.FromObjectMouse(objectScene.mouse);
|
apiQuaternion = GameLib.API.Quaternion.FromObjectQuaternion(objectScene.quaternion);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectScene.scale) {
|
||||||
|
apiScale = GameLib.API.Vector3.FromObjectVector(objectScene.scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new GameLib.D3.API.Scene(
|
return new GameLib.D3.API.Scene(
|
||||||
objectScene.id,
|
objectScene.id,
|
||||||
objectScene.path,
|
|
||||||
objectScene.name,
|
objectScene.name,
|
||||||
objectScene.width,
|
objectScene.baseUrl,
|
||||||
objectScene.height,
|
objectScene.path,
|
||||||
objectScene.meshes.map(
|
apiMeshes,
|
||||||
function (objectMesh) {
|
apiPosition,
|
||||||
return GameLib.D3.API.Mesh.FromObjectMesh(objectMesh)
|
apiQuaternion,
|
||||||
}
|
apiScale,
|
||||||
),
|
objectScene.parentGameId,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectScene.position),
|
apiLights,
|
||||||
GameLib.API.Quaternion.FromObjectQuaternion(objectScene.quaternion),
|
apiMaterials,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectScene.scale),
|
|
||||||
objectScene.parentSceneId,
|
|
||||||
objectScene.lights.map(
|
|
||||||
function (objectLight) {
|
|
||||||
return GameLib.D3.API.Light.FromObjectLight(objectLight)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
[], //TODO : implement worlds here
|
|
||||||
apiEntityManager,
|
|
||||||
[], //TODO : implement shapes here
|
|
||||||
objectScene.cameras.map(
|
|
||||||
function (objectCamera) {
|
|
||||||
return GameLib.D3.API.Camera.FromObjectCamera(objectCamera);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
objectScene.activeCameraIndex,
|
|
||||||
apiTextures,
|
apiTextures,
|
||||||
apiRenderers,
|
objectScene.parentEntity
|
||||||
objectScene.activeRendererIndex,
|
|
||||||
apiRaycaster,
|
|
||||||
apiMouse
|
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -61,6 +61,10 @@ GameLib.D3.Camera = function(
|
||||||
GameLib.D3.Camera.prototype = Object.create(GameLib.D3.API.Camera.prototype);
|
GameLib.D3.Camera.prototype = Object.create(GameLib.D3.API.Camera.prototype);
|
||||||
GameLib.D3.Camera.prototype.constructor = GameLib.D3.Camera;
|
GameLib.D3.Camera.prototype.constructor = GameLib.D3.Camera;
|
||||||
|
|
||||||
|
GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE = 0x1;
|
||||||
|
GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL = 0x2;
|
||||||
|
GameLib.D3.Camera.CAMERA_TYPE_STEREO = 0x3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a camera instance of 'graphics' type (only THREE for now)
|
* Creates a camera instance of 'graphics' type (only THREE for now)
|
||||||
* @returns {THREE.Camera}
|
* @returns {THREE.Camera}
|
||||||
|
@ -74,14 +78,14 @@ GameLib.D3.Camera.prototype.createInstance = function(update) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
if (this.cameraType == GameLib.Component.COMPONENT_CAMERA) {
|
if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE ) {
|
||||||
instance = new THREE.PerspectiveCamera(
|
instance = new THREE.PerspectiveCamera(
|
||||||
this.fov,
|
this.fov,
|
||||||
this.aspect,
|
this.aspect,
|
||||||
this.near,
|
this.near,
|
||||||
this.far
|
this.far
|
||||||
);
|
);
|
||||||
} else if (this.cameraType == GameLib.Component.COMPONENT_ORTHOGONAL_CAMERA) {
|
} else if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL) {
|
||||||
instance = new THREE.OrthographicCamera(
|
instance = new THREE.OrthographicCamera(
|
||||||
this.minX,
|
this.minX,
|
||||||
this.maxX,
|
this.maxX,
|
||||||
|
@ -90,20 +94,37 @@ GameLib.D3.Camera.prototype.createInstance = function(update) {
|
||||||
this.minZ,
|
this.minZ,
|
||||||
this.maxZ
|
this.maxZ
|
||||||
);
|
);
|
||||||
|
} else if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_STEREO) {
|
||||||
|
if (!instance) {
|
||||||
|
instance = new THREE.StereoCamera();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
instance.minX = this.minX;
|
|
||||||
instance.maxX = this.maxX;
|
if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_ORTHOGONAL) {
|
||||||
instance.minY = this.minY;
|
instance.minX = this.minX;
|
||||||
instance.maxY = this.maxY;
|
instance.maxX = this.maxX;
|
||||||
instance.minZ = this.minZ;
|
instance.minY = this.minY;
|
||||||
instance.maxZ = this.maxZ;
|
instance.maxY = this.maxY;
|
||||||
instance.fov = this.fov;
|
instance.minZ = this.minZ;
|
||||||
instance.aspect = this.aspect;
|
instance.maxZ = this.maxZ;
|
||||||
instance.near = this.near;
|
}
|
||||||
instance.far = this.far;
|
|
||||||
|
if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_PERSPECTIVE) {
|
||||||
|
instance.fov = this.fov;
|
||||||
|
instance.aspect = this.aspect;
|
||||||
|
instance.near = this.near;
|
||||||
|
instance.far = this.far;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.cameraType == GameLib.D3.Camera.CAMERA_TYPE_STEREO) {
|
||||||
|
instance.eyeSeparation = this.eyeSeparation;
|
||||||
|
instance.focalLength = this.focalLength;
|
||||||
|
|
||||||
|
instance.update(this.camera.instance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.position.x = this.position.x;
|
instance.position.x = this.position.x;
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
/**
|
||||||
|
* Renders a scene with a camera
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param apiComposer GameLib.D3.API.Composer
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Composer = function (
|
||||||
|
graphics,
|
||||||
|
apiComposer
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
GameLib.D3.API.Composer.call(
|
||||||
|
this,
|
||||||
|
apiComposer.id,
|
||||||
|
apiComposer.name,
|
||||||
|
apiComposer.renderer,
|
||||||
|
apiComposer.renderTarget,
|
||||||
|
apiComposer.passes,
|
||||||
|
apiComposer.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
this.instance = this.createInstance();
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Composer.prototype = Object.create(GameLib.D3.API.Composer.prototype);
|
||||||
|
GameLib.D3.Composer.prototype.constructor = GameLib.D3.Composer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Composer instance
|
||||||
|
* @param update
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Composer.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (!THREE.EffectComposer) {
|
||||||
|
console.warn('No THREE.EffectComposer');
|
||||||
|
throw new Error('No THREE.EffectComposer');
|
||||||
|
}
|
||||||
|
|
||||||
|
instance = new THREE.EffectComposer(
|
||||||
|
this.renderer.instance,
|
||||||
|
this.renderTarget.instance
|
||||||
|
);
|
||||||
|
|
||||||
|
this.passes.map(
|
||||||
|
function(pass) {
|
||||||
|
this.instance.addPass(pass.instance);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates Composer instance
|
||||||
|
*/
|
||||||
|
GameLib.D3.Composer.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GameLib.D3.Composer to GameLib.D3.API.Composer
|
||||||
|
* @returns {GameLib.D3.API.Composer}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Composer.prototype.toApiComponent = function() {
|
||||||
|
|
||||||
|
var apiComposer = new GameLib.D3.API.Composer(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
GameLib.Utils.IdOrNull(this.renderer),
|
||||||
|
GameLib.Utils.IdOrNull(this.renderTarget),
|
||||||
|
this.passes.map(
|
||||||
|
function(pass) {
|
||||||
|
return GameLib.Utils.IdOrNull(pass);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
|
);
|
||||||
|
|
||||||
|
return apiComposer;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param graphics
|
||||||
|
* @param objectComponent
|
||||||
|
* @returns {GameLib.D3.Composer}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Composer.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
|
var apiComposer = GameLib.D3.API.Composer.FromObjectComponent(objectComponent);
|
||||||
|
|
||||||
|
return new GameLib.D3.Composer(
|
||||||
|
graphics,
|
||||||
|
apiComposer
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,106 @@
|
||||||
|
/**
|
||||||
|
* Creates a Editor object
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param apiEditor GameLib.D3.API.Editor
|
||||||
|
* @param document
|
||||||
|
* @param window
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Editor = function(
|
||||||
|
graphics,
|
||||||
|
apiEditor,
|
||||||
|
document,
|
||||||
|
window
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
GameLib.D3.API.Editor.call(
|
||||||
|
this,
|
||||||
|
apiEditor.id,
|
||||||
|
apiEditor.name,
|
||||||
|
apiEditor.games,
|
||||||
|
apiEditor.allSelected,
|
||||||
|
apiEditor.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(document)) {
|
||||||
|
console.warn('Cannot create an Editor Object without reference to the DOM document');
|
||||||
|
throw new Error('Cannot create an Editor Object without reference to the DOM document');
|
||||||
|
}
|
||||||
|
this.document = document;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(window)) {
|
||||||
|
console.warn('Cannot create an Editor Object without reference to the DOM window');
|
||||||
|
throw new Error('Cannot create an Editor Object without reference to the DOM window');
|
||||||
|
}
|
||||||
|
this.window = window;
|
||||||
|
|
||||||
|
this.instance = this.createInstance();
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Editor.prototype = Object.create(GameLib.D3.API.Editor.prototype);
|
||||||
|
GameLib.D3.Editor.prototype.constructor = GameLib.D3.Editor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a camera instance of 'graphics' type (only THREE for now)
|
||||||
|
* @returns {THREE.Editor}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Editor.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.Editor.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.Editor to a new GameLib.D3.API.Editor
|
||||||
|
* @returns {GameLib.D3.API.Editor}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Editor.prototype.toApiEditor = function() {
|
||||||
|
|
||||||
|
var apiGames = this.games.map(
|
||||||
|
function(game) {
|
||||||
|
return game.toApiComponent();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return new GameLib.D3.API.Editor(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
apiGames,
|
||||||
|
this.allSelected,
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from an Object Editor to a GameLib.D3.Editor
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param objectEditor Object
|
||||||
|
* @returns {GameLib.D3.Editor}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Editor.FromObjectEditor = function(graphics, objectEditor) {
|
||||||
|
|
||||||
|
var apiEditor = GameLib.D3.API.Editor.FromObjectEditor(objectEditor);
|
||||||
|
|
||||||
|
return new GameLib.D3.Editor(
|
||||||
|
graphics,
|
||||||
|
apiEditor
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,111 @@
|
||||||
|
/**
|
||||||
|
* Game Runtime
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param apiGame GameLib.D3.API.Game
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Game = function (
|
||||||
|
graphics,
|
||||||
|
apiGame
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
GameLib.D3.API.Game.call(
|
||||||
|
this,
|
||||||
|
apiGame.id,
|
||||||
|
apiGame.name,
|
||||||
|
apiGame.gameType,
|
||||||
|
apiGame.width,
|
||||||
|
apiGame.height,
|
||||||
|
apiGame.scenes,
|
||||||
|
apiGame.cameras,
|
||||||
|
apiGame.renderers,
|
||||||
|
apiGame.composers,
|
||||||
|
apiGame.systems,
|
||||||
|
apiGame.entityManager,
|
||||||
|
apiGame.mouse,
|
||||||
|
apiGame.raycaster,
|
||||||
|
apiGame.activeCameraIndex,
|
||||||
|
apiGame.activeRendererIndex,
|
||||||
|
apiGame.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
this.scenes = this.scenes.map(
|
||||||
|
function(apiScene) {
|
||||||
|
return GameLib.D3.Scene(
|
||||||
|
this.graphics,
|
||||||
|
apiScene
|
||||||
|
)
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.entityManager.entities.map(
|
||||||
|
function (entity) {
|
||||||
|
this.idToObject[entity.id] = entity;
|
||||||
|
entity.components.map(
|
||||||
|
function(component) {
|
||||||
|
if (component instanceof GameLib.Component) {
|
||||||
|
this.idToObject[component.id] = component;
|
||||||
|
}
|
||||||
|
}.bind(this)
|
||||||
|
)
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.entityManager.linkObjects(this.idToObject);
|
||||||
|
|
||||||
|
this.scenes = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Game.GAME_TYPE_VR_PONG = 0x1;
|
||||||
|
GameLib.D3.Game.GAME_TYPE_VR_RACER = 0x2;
|
||||||
|
|
||||||
|
GameLib.D3.Game.prototype.addScene = function(
|
||||||
|
scene,
|
||||||
|
identifer
|
||||||
|
) {
|
||||||
|
this.scenes[identifer] = scene;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Game.prototype.processPhysics = function (
|
||||||
|
dt
|
||||||
|
) {
|
||||||
|
for(var s in this.scenes) {
|
||||||
|
var scene = this.scenes[s];
|
||||||
|
|
||||||
|
for(var w in scene.worlds) {
|
||||||
|
var world = scene.worlds[w];
|
||||||
|
world.step(dt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Game.prototype.render = function(
|
||||||
|
dt,
|
||||||
|
renderer
|
||||||
|
) {
|
||||||
|
for(var s in this.scenes) {
|
||||||
|
var scene = this.scenes[s];
|
||||||
|
scene.render(dt, renderer);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Game.prototype.update = function(
|
||||||
|
dt,
|
||||||
|
fixedDt
|
||||||
|
) {
|
||||||
|
for(var s in this.scenes) {
|
||||||
|
var scene = this.scenes[s];
|
||||||
|
|
||||||
|
for(var w in scene.worlds) {
|
||||||
|
var world = scene.worlds[w];
|
||||||
|
// NOTE: We are calling the step function with a variable timestep!
|
||||||
|
world.step(fixedDt, dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
scene.update(dt);
|
||||||
|
scene.lateUpdate(dt);
|
||||||
|
}
|
||||||
|
};
|
|
@ -1,7 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Input parent class
|
* Input parent class
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param parentObject
|
|
||||||
* @param apiInputDrive GameLib.D3.API.Input.Drive
|
* @param apiInputDrive GameLib.D3.API.Input.Drive
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,132 @@
|
||||||
|
/**
|
||||||
|
* Input parent class
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param apiInputEditor GameLib.D3.API.Input.Editor
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Editor = function (
|
||||||
|
graphics,
|
||||||
|
apiInputEditor
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
GameLib.D3.API.Input.Editor.call(
|
||||||
|
this,
|
||||||
|
apiInputEditor.id,
|
||||||
|
apiInputEditor.name,
|
||||||
|
apiInputEditor.camera,
|
||||||
|
apiInputEditor.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
this.instance = this.createInstance();
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Editor.prototype = Object.create(GameLib.D3.API.Input.Editor.prototype);
|
||||||
|
GameLib.D3.Input.Editor.prototype.constructor = GameLib.D3.Input.Editor;
|
||||||
|
|
||||||
|
GameLib.D3.Input.Editor.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
return this.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
var instance = document.getElementById(this.domElementId);
|
||||||
|
|
||||||
|
this.resize = this.onWindowResize.bind(this);
|
||||||
|
|
||||||
|
window.addEventListener('resize', this.resize, false );
|
||||||
|
|
||||||
|
// this.clearScene();
|
||||||
|
this.boundMouseMove = this.mouseMove.bind(this);
|
||||||
|
|
||||||
|
instance.addEventListener('contextmenu', function(event){
|
||||||
|
|
||||||
|
if (event.stopPropagation) {
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.preventDefault) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
event.cancelBubble = true;
|
||||||
|
return false;
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
instance.addEventListener('mousedown', this.mouseDown.bind(this), false);
|
||||||
|
instance.addEventListener('keydown', this.keypress.bind(this), false);
|
||||||
|
instance.addEventListener('mousemove', this.boundMouseMove, false);
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Editor.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GameLib.D3.Input.Editor to GameLib.D3.API.Input.Editor
|
||||||
|
* @returns {GameLib.D3.API.Input.Editor}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Input.Editor.prototype.toApiComponent = function() {
|
||||||
|
|
||||||
|
var apiInputEditor = new GameLib.D3.API.Input.Editor(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.domElementId,
|
||||||
|
GameLib.Utils.IdOrNull(this.pathFollowingComponent),
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||||
|
GameLib.Utils.IdOrNull(this.wheelFL),
|
||||||
|
GameLib.Utils.IdOrNull(this.wheelFR),
|
||||||
|
GameLib.Utils.IdOrNull(this.wheelRL),
|
||||||
|
GameLib.Utils.IdOrNull(this.wheelRR),
|
||||||
|
this.heightOffset,
|
||||||
|
this.distance,
|
||||||
|
this.distanceGrain,
|
||||||
|
this.rotationFactor
|
||||||
|
);
|
||||||
|
|
||||||
|
return apiInputEditor;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Editor.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
|
var apiInputEditor = GameLib.D3.API.Input.Editor.FromObjectComponent(objectComponent);
|
||||||
|
|
||||||
|
return new GameLib.D3.Input.Editor(
|
||||||
|
graphics,
|
||||||
|
apiInputEditor
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Input.Editor.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,118 @@
|
||||||
|
/**
|
||||||
|
* Renders a scene with a camera
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param apiPass GameLib.D3.API.Pass
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Pass = function (
|
||||||
|
graphics,
|
||||||
|
apiPass
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
GameLib.D3.API.Pass.call(
|
||||||
|
this,
|
||||||
|
apiPass.id,
|
||||||
|
apiPass.name,
|
||||||
|
apiPass.passType,
|
||||||
|
apiPass.camera,
|
||||||
|
apiPass.scene,
|
||||||
|
apiPass.renderToScreen,
|
||||||
|
apiPass.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
this.instance = this.createInstance();
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.Pass.prototype = Object.create(GameLib.D3.API.Pass.prototype);
|
||||||
|
GameLib.D3.Pass.prototype.constructor = GameLib.D3.Pass;
|
||||||
|
|
||||||
|
GameLib.D3.Pass.PASS_TYPE_RENDER = 0x1;
|
||||||
|
GameLib.D3.Pass.PASS_TYPE_COPY_SHADER = 0x2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Pass instance
|
||||||
|
* @param update
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Pass.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (this.passType == GameLib.D3.Pass.PASS_TYPE_RENDER) {
|
||||||
|
|
||||||
|
if (!THREE.RenderPass) {
|
||||||
|
console.warn('No THREE.RenderPass');
|
||||||
|
throw new Error('No THREE.RenderPass');
|
||||||
|
}
|
||||||
|
|
||||||
|
instance = new THREE.RenderPass(
|
||||||
|
this.scene.instance,
|
||||||
|
this.camera.instance
|
||||||
|
);
|
||||||
|
} else if (this.passType == GameLib.D3.Pass.PASS_TYPE_COPY_SHADER) {
|
||||||
|
if (!THREE.CopyShader) {
|
||||||
|
console.warn('No THREE.CopyShader');
|
||||||
|
throw new Error('No THREE.CopyShader');
|
||||||
|
}
|
||||||
|
|
||||||
|
instance = THREE.CopyShader;
|
||||||
|
} else {
|
||||||
|
console.warn('Render pass not supported yet: ' + this.passType);
|
||||||
|
throw new Error('Render pass not supported yet: ' + this.passType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.renderToScreen = this.renderToScreen;
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Pass instance
|
||||||
|
*/
|
||||||
|
GameLib.D3.Pass.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GameLib.D3.Pass to GameLib.D3.API.Pass
|
||||||
|
* @returns {GameLib.D3.API.Pass}
|
||||||
|
*/
|
||||||
|
GameLib.D3.Pass.prototype.toApiComponent = function() {
|
||||||
|
|
||||||
|
var apiPass = new GameLib.D3.API.Pass(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.passType,
|
||||||
|
GameLib.Utils.IdOrNull(this.camera),
|
||||||
|
GameLib.Utils.IdOrNull(this.scene),
|
||||||
|
this.renderToScreen,
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
|
);
|
||||||
|
|
||||||
|
return apiPass;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GameLib.D3.Pass from Object
|
||||||
|
* @param graphics
|
||||||
|
* @param objectComponent
|
||||||
|
* @returns {GameLib.D3.Pass}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.Pass.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
|
var apiPass = GameLib.D3.API.Pass.FromObjectComponent(objectComponent);
|
||||||
|
|
||||||
|
return new GameLib.D3.Pass(
|
||||||
|
graphics,
|
||||||
|
apiPass
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,117 @@
|
||||||
|
/**
|
||||||
|
* Renders a scene with a camera
|
||||||
|
* @param graphics GameLib.D3.Graphics
|
||||||
|
* @param apiRenderTarget GameLib.D3.API.RenderTarget
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.RenderTarget = function (
|
||||||
|
graphics,
|
||||||
|
apiRenderTarget
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
GameLib.D3.API.RenderTarget.call(
|
||||||
|
this,
|
||||||
|
apiRenderTarget.id,
|
||||||
|
apiRenderTarget.name,
|
||||||
|
apiRenderTarget.width,
|
||||||
|
apiRenderTarget.height,
|
||||||
|
apiRenderTarget.minFilter,
|
||||||
|
apiRenderTarget.magFilter,
|
||||||
|
apiRenderTarget.format,
|
||||||
|
apiRenderTarget.stencilBuffer
|
||||||
|
);
|
||||||
|
|
||||||
|
this.instance = this.createInstance();
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.RenderTarget.prototype = Object.create(GameLib.D3.API.RenderTarget.prototype);
|
||||||
|
GameLib.D3.RenderTarget.prototype.constructor = GameLib.D3.RenderTarget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some constants (based on THREE.js constants - update if needed)
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
GameLib.D3.RenderTarget.LINEAR_FILTER = 1006;
|
||||||
|
GameLib.D3.RenderTarget.RGB_FORMAT = 1022;
|
||||||
|
GameLib.D3.RenderTarget.RGBA_FORMAT = 1023;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Render Target instance
|
||||||
|
* @param update
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
GameLib.D3.RenderTarget.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
var instance = null;
|
||||||
|
|
||||||
|
if (update) {
|
||||||
|
instance = this.instance;
|
||||||
|
instance.width = this.width;
|
||||||
|
instance.height = this.height;
|
||||||
|
instance.minFilter = this.minFilter;
|
||||||
|
instance.magFilter = this.magFilter;
|
||||||
|
instance.format = this.format;
|
||||||
|
instance.stencilBuffer = this.stencilBuffer;
|
||||||
|
} else {
|
||||||
|
instance = new THREE.WebGLRenderTarget(
|
||||||
|
this.width,
|
||||||
|
this.height,
|
||||||
|
{
|
||||||
|
minFilter : this.minFilter,
|
||||||
|
magFilter : this.magFilter,
|
||||||
|
format : this.format,
|
||||||
|
stencilBuffer : this.stencilBuffer
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updates instance
|
||||||
|
*/
|
||||||
|
GameLib.D3.RenderTarget.prototype.updateInstance = function() {
|
||||||
|
this.instance = this.createInstance(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render Target to API Render Target
|
||||||
|
* @returns {GameLib.D3.API.RenderTarget}
|
||||||
|
*/
|
||||||
|
GameLib.D3.RenderTarget.prototype.toApiComponent = function() {
|
||||||
|
|
||||||
|
var apiRenderTarget = new GameLib.D3.API.RenderTarget(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.width,
|
||||||
|
this.height,
|
||||||
|
this.minFilter,
|
||||||
|
this.magFilter,
|
||||||
|
this.format,
|
||||||
|
this.stencilBuffer,
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
|
);
|
||||||
|
|
||||||
|
return apiRenderTarget;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param graphics
|
||||||
|
* @param objectComponent
|
||||||
|
* @returns {GameLib.D3.RenderTarget}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.RenderTarget.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
|
var apiRenderTarget = GameLib.D3.API.RenderTarget.FromObjectComponent(objectComponent);
|
||||||
|
|
||||||
|
return new GameLib.D3.RenderTarget(
|
||||||
|
graphics,
|
||||||
|
apiRenderTarget
|
||||||
|
);
|
||||||
|
};
|
|
@ -17,39 +17,29 @@ GameLib.D3.Renderer = function (
|
||||||
apiRenderer.id,
|
apiRenderer.id,
|
||||||
apiRenderer.name,
|
apiRenderer.name,
|
||||||
apiRenderer.rendererType,
|
apiRenderer.rendererType,
|
||||||
apiRenderer.scene,
|
|
||||||
apiRenderer.camera,
|
|
||||||
apiRenderer.autoClear,
|
apiRenderer.autoClear,
|
||||||
apiRenderer.localClipping,
|
apiRenderer.localClipping,
|
||||||
apiRenderer.width,
|
apiRenderer.width,
|
||||||
apiRenderer.height,
|
apiRenderer.height,
|
||||||
apiRenderer.parentEntity,
|
apiRenderer.parentEntity,
|
||||||
apiRenderer.preserveDrawingBuffer
|
apiRenderer.preserveDrawingBuffer,
|
||||||
|
apiRenderer.composer
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.camera instanceof Object) {
|
|
||||||
if (this.camera.cameraType == GameLib.Component.COMPONENT_CAMERA) {
|
|
||||||
this.camera = new GameLib.D3.Camera(
|
|
||||||
this.graphics,
|
|
||||||
this.camera
|
|
||||||
);
|
|
||||||
} else if (this.camera.cameraType == GameLib.Component.COMPONENT_STEREO_CAMERA) {
|
|
||||||
this.camera = new GameLib.D3.StereoCamera(
|
|
||||||
this.graphics,
|
|
||||||
this.camera
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.warn('Camera type not supported : ' + this.camera.cameraType);
|
|
||||||
throw new Error('Camera type not supported : ' + this.camera.cameraType)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Renderer.prototype = Object.create(GameLib.D3.API.Renderer.prototype);
|
GameLib.D3.Renderer.prototype = Object.create(GameLib.D3.API.Renderer.prototype);
|
||||||
GameLib.D3.Renderer.prototype.constructor = GameLib.D3.Renderer;
|
GameLib.D3.Renderer.prototype.constructor = GameLib.D3.Renderer;
|
||||||
|
|
||||||
|
GameLib.D3.Renderer.RENDER_TYPE_NORMAL = 0x1;
|
||||||
|
GameLib.D3.Renderer.RENDER_TYPE_STEREO = 0x2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Renderer Instance
|
||||||
|
* @param update
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
GameLib.D3.Renderer.prototype.createInstance = function(update) {
|
GameLib.D3.Renderer.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
@ -65,11 +55,6 @@ GameLib.D3.Renderer.prototype.createInstance = function(update) {
|
||||||
instance.autoClear = this.autoClear;
|
instance.autoClear = this.autoClear;
|
||||||
instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
|
instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
|
||||||
|
|
||||||
if (this.camera) {
|
|
||||||
this.camera.aspect = this.width / this.height;
|
|
||||||
this.camera.updateInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,14 +68,13 @@ GameLib.D3.Renderer.prototype.toApiComponent = function() {
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
this.rendererType,
|
this.rendererType,
|
||||||
GameLib.Utils.IdOrNull(this.scene),
|
|
||||||
GameLib.Utils.IdOrNull(this.camera),
|
|
||||||
this.autoClear,
|
this.autoClear,
|
||||||
this.localClipping,
|
this.localClipping,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity),
|
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||||
this.preserveDrawingBuffer
|
preserveDrawingBuffer,
|
||||||
|
GameLib.Utils.IdOrNull(this.composer)
|
||||||
);
|
);
|
||||||
|
|
||||||
return apiRenderer;
|
return apiRenderer;
|
||||||
|
@ -109,17 +93,6 @@ GameLib.D3.Renderer.FromObjectComponent = function(graphics, objectComponent) {
|
||||||
|
|
||||||
return new GameLib.D3.Renderer(
|
return new GameLib.D3.Renderer(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
|
||||||
apiRenderer
|
apiRenderer
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
GameLib.D3.Renderer.prototype.render = function() {
|
|
||||||
this.instance.render(
|
|
||||||
this.scene.instance,
|
|
||||||
this.camera.instance
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
* Scene Superset - The apiScene properties get moved into the Scene object itself, and then the instance is
|
* Scene Superset - The apiScene properties get moved into the Scene object itself, and then the instance is
|
||||||
* created
|
* created
|
||||||
* @param graphics
|
* @param graphics
|
||||||
* @param progressCallback
|
|
||||||
* @param apiScene GameLib.D3.API.Scene
|
* @param apiScene GameLib.D3.API.Scene
|
||||||
* @param imageFactory
|
* @param imageFactory
|
||||||
* @param computeNormals
|
* @param computeNormals
|
||||||
|
@ -10,7 +9,6 @@
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Scene = function Scene(
|
GameLib.D3.Scene = function Scene(
|
||||||
graphics,
|
graphics,
|
||||||
progressCallback,
|
|
||||||
apiScene,
|
apiScene,
|
||||||
imageFactory,
|
imageFactory,
|
||||||
computeNormals
|
computeNormals
|
||||||
|
@ -18,130 +16,61 @@ GameLib.D3.Scene = function Scene(
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
this.graphics.isNotThreeThrow();
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
this.imageFactory = imageFactory;
|
|
||||||
|
|
||||||
GameLib.D3.API.Scene.call(
|
GameLib.D3.API.Scene.call(
|
||||||
this,
|
this,
|
||||||
apiScene.id,
|
apiScene.id,
|
||||||
apiScene.path,
|
|
||||||
apiScene.name,
|
apiScene.name,
|
||||||
apiScene.width,
|
apiScene.baseUrl,
|
||||||
apiScene.height,
|
apiScene.path,
|
||||||
apiScene.meshes,
|
apiScene.meshes,
|
||||||
apiScene.position,
|
apiScene.position,
|
||||||
apiScene.quaternion,
|
apiScene.quaternion,
|
||||||
apiScene.scale,
|
apiScene.scale,
|
||||||
apiScene.parentSceneId,
|
apiScene.parentGameId,
|
||||||
apiScene.lights,
|
apiScene.lights,
|
||||||
apiScene.worlds,
|
apiScene.materials,
|
||||||
apiScene.entityManager,
|
apiScene.textures,
|
||||||
apiScene.shapes,
|
apiScene.parentEntity
|
||||||
apiScene.cameras,
|
|
||||||
apiScene.activeCameraIndex,
|
|
||||||
apiScene.textures,
|
|
||||||
apiScene.renderers,
|
|
||||||
apiScene.activeRendererIndex,
|
|
||||||
apiScene.raycaster,
|
|
||||||
apiScene.mouse
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(imageFactory)) {
|
||||||
|
imageFactory = GameLib.D3.ImageFactory(
|
||||||
|
this.graphics,
|
||||||
|
this.baseUrl
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.imageFactory = imageFactory;
|
||||||
|
|
||||||
|
this.idToObject = {};
|
||||||
|
|
||||||
this.meshes = this.meshes.map(
|
this.meshes = this.meshes.map(
|
||||||
function(apiMesh) {
|
function(apiMesh) {
|
||||||
return new GameLib.D3.Mesh(
|
|
||||||
|
var mesh = new GameLib.D3.Mesh(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiMesh,
|
apiMesh,
|
||||||
computeNormals,
|
computeNormals,
|
||||||
imageFactory
|
imageFactory
|
||||||
)
|
);
|
||||||
}.bind(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.lights = this.lights.map(
|
this.idToObject[mesh.id] = mesh;
|
||||||
function(apiLight) {
|
|
||||||
return new GameLib.D3.Light(
|
|
||||||
this.graphics,
|
|
||||||
apiLight
|
|
||||||
)
|
|
||||||
}.bind(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (this.entityManager) {
|
if (mesh.skeleton) {
|
||||||
this.entityManager = new GameLib.EntityManager(
|
|
||||||
this.graphics,
|
|
||||||
this.entityManager
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.cameras = this.cameras.map(
|
this.idToObject[mesh.skeleton.id] = mesh.skeleton;
|
||||||
function(apiCamera) {
|
|
||||||
if (apiCamera.cameraType == GameLib.D3.Camera.CAMERA_TYPE_STEREO) {
|
mesh.skeleton.bones.map(
|
||||||
return new GameLib.D3.StereoCamera(
|
function (bone) {
|
||||||
this.graphics,
|
this.idToObject[bone.id] = bone;
|
||||||
apiCamera
|
}.bind(this)
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return new GameLib.D3.Camera(
|
|
||||||
this.graphics,
|
|
||||||
apiCamera
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return mesh;
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.textures = this.textures.map(
|
|
||||||
function(apiTexture) {
|
|
||||||
return new GameLib.D3.Texture(
|
|
||||||
this.graphics,
|
|
||||||
apiTexture,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
this.imageFactory
|
|
||||||
)
|
|
||||||
}.bind(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.renderers = this.renderers.map(
|
|
||||||
function(apiRenderer) {
|
|
||||||
var renderer = null;
|
|
||||||
|
|
||||||
if (apiRenderer.rendererType == GameLib.Component.COMPONENT_RENDERER) {
|
|
||||||
|
|
||||||
renderer = new GameLib.D3.Renderer(
|
|
||||||
this.graphics,
|
|
||||||
apiRenderer
|
|
||||||
);
|
|
||||||
|
|
||||||
} else if (apiRenderer.rendererType == GameLib.Component.COMPONENT_STEREO_RENDERER) {
|
|
||||||
renderer = new GameLib.D3.StereoRenderer(
|
|
||||||
this.graphics,
|
|
||||||
apiRenderer
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (renderer.scene.id == this.id) {
|
|
||||||
renderer.scene = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!renderer) {
|
|
||||||
console.log("Renderer type not supported : " + apiRenderer.rendererType);
|
|
||||||
throw new Error("Renderer type not supported : " + apiRenderer.rendererType);
|
|
||||||
}
|
|
||||||
|
|
||||||
return renderer;
|
|
||||||
}.bind(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.raycaster = new GameLib.D3.Raycaster(
|
|
||||||
this.graphics,
|
|
||||||
this.raycaster
|
|
||||||
);
|
|
||||||
|
|
||||||
this.mouse = new GameLib.Mouse(
|
|
||||||
this.graphics,
|
|
||||||
this,
|
|
||||||
this.mouse
|
|
||||||
);
|
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
|
@ -160,83 +89,51 @@ GameLib.D3.Scene = function Scene(
|
||||||
this.scale
|
this.scale
|
||||||
);
|
);
|
||||||
|
|
||||||
this.progressCallback = progressCallback;
|
this.lights = this.lights.map(
|
||||||
|
function(apiLight) {
|
||||||
this.instance = this.createInstance();
|
var light = new GameLib.D3.Light(
|
||||||
|
this.graphics,
|
||||||
this.interestingProperties = [
|
apiLight
|
||||||
"cameras",
|
|
||||||
"meshes",
|
|
||||||
"lights",
|
|
||||||
"textures",
|
|
||||||
"renderers",
|
|
||||||
"raycaster",
|
|
||||||
"mouse"
|
|
||||||
];
|
|
||||||
|
|
||||||
this.idToObject = {};
|
|
||||||
|
|
||||||
this.idToObject[this.id] = this;
|
|
||||||
|
|
||||||
var material = null;
|
|
||||||
|
|
||||||
var object = null;
|
|
||||||
|
|
||||||
for (var p = 0; p < this.interestingProperties.length; p++) {
|
|
||||||
property = this.interestingProperties[p];
|
|
||||||
if (this.hasOwnProperty(property)) {
|
|
||||||
|
|
||||||
if (_.isArray(this[property])) {
|
|
||||||
for (var i = 0; i < this[property].length; i++) {
|
|
||||||
object = this[property][i];
|
|
||||||
this.idToObject[object.id] = object;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
object = this[property];
|
|
||||||
this.idToObject[object.id] = object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var m = 0; m < this.meshes.length; m++) {
|
|
||||||
if (this.meshes[m].skeleton) {
|
|
||||||
this.meshes[m].skeleton.bones.map(
|
|
||||||
function (bone) {
|
|
||||||
this.idToObject[bone.id] = bone;
|
|
||||||
}.bind(this)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
this.idToObject[this.meshes[m].skeleton.id] = this.meshes[m].skeleton;
|
this.idToObject[light.id] = light;
|
||||||
}
|
|
||||||
|
|
||||||
if (this.meshes[m].materials[0]) {
|
return light;
|
||||||
|
|
||||||
material = this.meshes[m].materials[0];
|
|
||||||
|
|
||||||
for (var property in material) {
|
|
||||||
if (material.hasOwnProperty(property) && material[property] instanceof GameLib.D3.Texture) {
|
|
||||||
this.idToObject[material[property].id] = material[property];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.idToObject[material.id] = material;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.entityManager.entities.map(
|
|
||||||
function (entity) {
|
|
||||||
this.idToObject[entity.id] = entity;
|
|
||||||
entity.components.map(
|
|
||||||
function(component) {
|
|
||||||
if (component instanceof GameLib.Component) {
|
|
||||||
this.idToObject[component.id] = component;
|
|
||||||
}
|
|
||||||
}.bind(this)
|
|
||||||
)
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
this.entityManager.linkObjects(this.idToObject);
|
this.materials = this.materials.map(
|
||||||
|
function(apiMaterial) {
|
||||||
|
var material = new GameLib.D3.Material(
|
||||||
|
this.graphics,
|
||||||
|
apiMaterial,
|
||||||
|
this.imageFactory
|
||||||
|
);
|
||||||
|
|
||||||
|
this.idToObject[material.id] = material;
|
||||||
|
|
||||||
|
return material;
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
this.textures = this.textures.map(
|
||||||
|
function(apiTexture) {
|
||||||
|
var texture = new GameLib.D3.Texture(
|
||||||
|
this.graphics,
|
||||||
|
apiTexture,
|
||||||
|
this.imageFactory
|
||||||
|
);
|
||||||
|
|
||||||
|
this.idToObject[texture.id] = texture;
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.idToObject[this.id] = this;
|
||||||
|
|
||||||
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Scene.prototype = Object.create(GameLib.D3.API.Scene.prototype);
|
GameLib.D3.Scene.prototype = Object.create(GameLib.D3.API.Scene.prototype);
|
||||||
|
@ -244,7 +141,7 @@ GameLib.D3.Scene.prototype.constructor = GameLib.D3.Scene;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance scene
|
* Creates an instance scene
|
||||||
* @returns {GameLib.D3.Scene|THREE.Scene|ApiLib.Scene|*|Scene}
|
* @returns {THREE.Scene}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Scene.prototype.createInstance = function() {
|
GameLib.D3.Scene.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
@ -266,8 +163,6 @@ GameLib.D3.Scene.prototype.createInstance = function() {
|
||||||
instance.add(this.lights[l].instance);
|
instance.add(this.lights[l].instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.render = true;
|
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -289,26 +184,9 @@ GameLib.D3.Scene.prototype.toApiScene = function() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
var apiEntityManager = null;
|
var apiMaterials = this.materials.map(
|
||||||
if (this.entityManager) {
|
function(material) {
|
||||||
apiEntityManager = this.entityManager.toApiEntityManager();
|
return material.toApiShape();
|
||||||
}
|
|
||||||
|
|
||||||
var apiCameras = this.cameras.map(
|
|
||||||
function(camera) {
|
|
||||||
return camera.toApiCamera();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
var apiWorlds = this.worlds.map(
|
|
||||||
function(world) {
|
|
||||||
return world.toApiWorld();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
var apiShapes = this.shapes.map(
|
|
||||||
function(shape) {
|
|
||||||
return shape.toApiShape();
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -318,34 +196,20 @@ GameLib.D3.Scene.prototype.toApiScene = function() {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
var apiRenderers = this.renderers.map(
|
|
||||||
function(renderer) {
|
|
||||||
return renderer.toApiComponent();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return new GameLib.D3.API.Scene(
|
return new GameLib.D3.API.Scene(
|
||||||
this.id,
|
this.id,
|
||||||
this.path,
|
|
||||||
this.name,
|
this.name,
|
||||||
this.width,
|
this.baseUrl,
|
||||||
this.height,
|
this.path,
|
||||||
apiMeshes,
|
apiMeshes,
|
||||||
this.position.toApiVector(),
|
this.position.toApiVector(),
|
||||||
this.quaternion.toApiQuaternion(),
|
this.quaternion.toApiQuaternion(),
|
||||||
this.scale.toApiVector(),
|
this.scale.toApiVector(),
|
||||||
this.parentSceneId,
|
this.parentGameId,
|
||||||
apiLights,
|
apiLights,
|
||||||
apiWorlds,
|
apiMaterials,
|
||||||
apiEntityManager,
|
|
||||||
apiShapes,
|
|
||||||
apiCameras,
|
|
||||||
this.activeCameraIndex,
|
|
||||||
apiTextures,
|
apiTextures,
|
||||||
apiRenderers,
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
this.activeRendererIndex,
|
|
||||||
this.raycaster.toApiRaycaster(),
|
|
||||||
this.mouse.toApiMouse()
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -355,7 +219,6 @@ GameLib.D3.Scene.prototype.toApiScene = function() {
|
||||||
* @param objectScene Object
|
* @param objectScene Object
|
||||||
* @param computeNormals boolean to indicate whether or not to recalculate normals
|
* @param computeNormals boolean to indicate whether or not to recalculate normals
|
||||||
* @param imageFactory GameLib.D3.ImageFactory
|
* @param imageFactory GameLib.D3.ImageFactory
|
||||||
* @param progressCallback callback
|
|
||||||
* @returns {GameLib.D3.Scene}
|
* @returns {GameLib.D3.Scene}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
@ -363,14 +226,12 @@ GameLib.D3.Scene.FromObjectScene = function(
|
||||||
graphics,
|
graphics,
|
||||||
objectScene,
|
objectScene,
|
||||||
computeNormals,
|
computeNormals,
|
||||||
imageFactory,
|
imageFactory
|
||||||
progressCallback
|
|
||||||
) {
|
) {
|
||||||
var apiScene = GameLib.D3.API.Scene.FromObjectScene(objectScene);
|
var apiScene = GameLib.D3.API.Scene.FromObjectScene(objectScene);
|
||||||
|
|
||||||
return new GameLib.D3.Scene(
|
return new GameLib.D3.Scene(
|
||||||
graphics,
|
graphics,
|
||||||
progressCallback,
|
|
||||||
apiScene,
|
apiScene,
|
||||||
imageFactory,
|
imageFactory,
|
||||||
computeNormals
|
computeNormals
|
||||||
|
@ -380,52 +241,39 @@ GameLib.D3.Scene.FromObjectScene = function(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms raw scene data into a GameLib.D3.Scene
|
* Transforms raw scene data into a GameLib.D3.Scene
|
||||||
* @param objectScene Object (as it comes from the API)
|
|
||||||
* @param onLoaded
|
|
||||||
* @param graphics
|
* @param graphics
|
||||||
* @param uploadUrl
|
* @param objectScene Object (as it comes from the API)
|
||||||
* @param progressCallback
|
|
||||||
* @param computeNormals
|
* @param computeNormals
|
||||||
|
* @param onLoaded
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Scene.LoadScene = function(
|
GameLib.D3.Scene.LoadScene = function(
|
||||||
objectScene,
|
|
||||||
onLoaded,
|
|
||||||
graphics,
|
graphics,
|
||||||
uploadUrl,
|
objectScene,
|
||||||
progressCallback,
|
computeNormals,
|
||||||
computeNormals
|
onLoaded
|
||||||
) {
|
) {
|
||||||
onLoaded(
|
var scene = GameLib.D3.Scene.FromObjectScene(
|
||||||
GameLib.D3.Scene.FromObjectScene(
|
graphics,
|
||||||
graphics,
|
objectScene,
|
||||||
objectScene,
|
computeNormals
|
||||||
computeNormals,
|
|
||||||
GameLib.D3.ImageFactory(
|
|
||||||
graphics,
|
|
||||||
uploadUrl
|
|
||||||
),
|
|
||||||
progressCallback
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
onLoaded(scene);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a scene directly from the API
|
* Loads a scene directly from the API
|
||||||
* @param partialSceneObject Object {path: '', name: ''}
|
|
||||||
* @param onLoaded callback
|
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param uploadUrl String
|
* @param partialSceneObject Object {path: '', name: ''}
|
||||||
* @param progressCallback callback
|
|
||||||
* @param apiUrl
|
* @param apiUrl
|
||||||
|
* @param onLoaded
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Scene.LoadSceneFromApi = function(
|
GameLib.D3.Scene.LoadSceneFromApi = function(
|
||||||
partialSceneObject,
|
|
||||||
onLoaded,
|
|
||||||
graphics,
|
graphics,
|
||||||
uploadUrl,
|
partialSceneObject,
|
||||||
progressCallback,
|
apiUrl,
|
||||||
apiUrl
|
onLoaded
|
||||||
) {
|
) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -448,18 +296,27 @@ GameLib.D3.Scene.LoadSceneFromApi = function(
|
||||||
|
|
||||||
if (xhr.readyState == 4) {
|
if (xhr.readyState == 4) {
|
||||||
|
|
||||||
var response = JSON.parse(xhr.responseText);
|
try {
|
||||||
|
var response = JSON.parse(xhr.responseText);
|
||||||
if (!response.scene || response.scene.length == 0) {
|
} catch (e) {
|
||||||
return onLoaded(null, null, new Error('Could not load scene'));
|
return onLoaded(null, new Error('Could not load scene : ' + e.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
var scene = response.scene[0];
|
if (!response.scene || response.scene.length == 0) {
|
||||||
|
return onLoaded(null, new Error('Could not load scene'));
|
||||||
|
}
|
||||||
|
|
||||||
GameLib.D3.Scene.LoadScene(scene, onLoaded, graphics, uploadUrl, progressCallback, true);
|
var objectScene = response.scene[0];
|
||||||
|
|
||||||
|
GameLib.D3.Scene.LoadScene(
|
||||||
|
graphics,
|
||||||
|
objectScene,
|
||||||
|
true,
|
||||||
|
onLoaded
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}(xhr);
|
}(xhr);
|
||||||
|
|
||||||
xhr.send();
|
xhr.send();
|
||||||
};
|
};
|
|
@ -1,72 +0,0 @@
|
||||||
/**
|
|
||||||
* Creates a camera object
|
|
||||||
* @param graphics GameLib.D3.Graphics
|
|
||||||
* @param apiCamera GameLib.D3.API.Camera
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.D3.StereoCamera = function (
|
|
||||||
graphics,
|
|
||||||
apiCamera
|
|
||||||
) {
|
|
||||||
|
|
||||||
this.graphics = graphics;
|
|
||||||
this.graphics.isNotThreeThrow();
|
|
||||||
|
|
||||||
GameLib.D3.Camera.call(
|
|
||||||
this,
|
|
||||||
this.graphics,
|
|
||||||
apiCamera
|
|
||||||
);
|
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
|
||||||
|
|
||||||
this.needsUpdate = false;
|
|
||||||
} ;
|
|
||||||
|
|
||||||
GameLib.D3.StereoCamera.prototype = Object.create(GameLib.D3.Camera.prototype);
|
|
||||||
GameLib.D3.StereoCamera.prototype.constructor = GameLib.D3.StereoCamera;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a camera instance of 'graphics' type (only THREE for now)
|
|
||||||
* @returns {THREE.Camera}
|
|
||||||
*/
|
|
||||||
GameLib.D3.StereoCamera.prototype.createInstance = function(update) {
|
|
||||||
|
|
||||||
var instance = null;
|
|
||||||
|
|
||||||
if (update) {
|
|
||||||
instance = this.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!instance) {
|
|
||||||
instance = new THREE.StereoCamera();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (update) {
|
|
||||||
// instance.minX = this.minX;
|
|
||||||
// instance.maxX = this.maxX;
|
|
||||||
// instance.minY = this.minY;
|
|
||||||
// instance.maxY = this.maxY;
|
|
||||||
// instance.minZ = this.minZ;
|
|
||||||
// instance.maxZ = this.maxZ;
|
|
||||||
// instance.fov = this.fov;
|
|
||||||
// instance.aspect = this.aspect;
|
|
||||||
// instance.near = this.near;
|
|
||||||
// instance.far = this.far;
|
|
||||||
}
|
|
||||||
|
|
||||||
// instance.position.x = this.position.x;
|
|
||||||
// instance.position.y = this.position.y;
|
|
||||||
// instance.position.z = this.position.z;
|
|
||||||
//
|
|
||||||
// instance.quaternion.x = this.quaternion.x;
|
|
||||||
// instance.quaternion.y = this.quaternion.y;
|
|
||||||
// instance.quaternion.z = this.quaternion.z;
|
|
||||||
// instance.quaternion.w = this.quaternion.w;
|
|
||||||
|
|
||||||
// instance.lookAt(this.lookAt.instance);
|
|
||||||
//
|
|
||||||
// instance.updateProjectionMatrix();
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
};
|
|
|
@ -1,106 +0,0 @@
|
||||||
/**
|
|
||||||
* Renders a scene with a camera
|
|
||||||
* @param graphics GameLib.D3.Graphics
|
|
||||||
* @param apiRenderer GameLib.D3.API.Renderer
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.D3.StereoRenderer = function (
|
|
||||||
graphics,
|
|
||||||
apiRenderer
|
|
||||||
) {
|
|
||||||
|
|
||||||
this.graphics = graphics;
|
|
||||||
this.graphics.isNotThreeThrow();
|
|
||||||
|
|
||||||
GameLib.D3.Renderer.call(
|
|
||||||
this,
|
|
||||||
this.graphics,
|
|
||||||
apiRenderer
|
|
||||||
);
|
|
||||||
|
|
||||||
this.autoClear = false;
|
|
||||||
|
|
||||||
this.composer = null;
|
|
||||||
|
|
||||||
this.renderPass = null;
|
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.StereoRenderer.prototype = Object.create(GameLib.D3.Renderer.prototype);
|
|
||||||
GameLib.D3.StereoRenderer.prototype.constructor = GameLib.D3.StereoRenderer;
|
|
||||||
|
|
||||||
GameLib.D3.StereoRenderer.prototype.createInstance = function(update) {
|
|
||||||
|
|
||||||
var instance = null;
|
|
||||||
|
|
||||||
if (update) {
|
|
||||||
instance = this.instance;
|
|
||||||
} else {
|
|
||||||
instance = new THREE.WebGLRenderer();
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.localClippingEnabled = this.localClipping;
|
|
||||||
instance.setSize(this.width, this.height);
|
|
||||||
instance.autoClear = false;
|
|
||||||
|
|
||||||
var renderTargetParameters = {
|
|
||||||
minFilter: THREE.LinearFilter,
|
|
||||||
magFilter: THREE.LinearFilter,
|
|
||||||
format: THREE.RGBFormat,
|
|
||||||
stencilBuffer: false
|
|
||||||
};
|
|
||||||
|
|
||||||
var renderTarget = new THREE.WebGLRenderTarget(
|
|
||||||
this.width,
|
|
||||||
this.height,
|
|
||||||
renderTargetParameters
|
|
||||||
);
|
|
||||||
|
|
||||||
if (this.camera instanceof GameLib.D3.Camera) {
|
|
||||||
this.camera.aspect = this.width / this.height;
|
|
||||||
this.camera.updateInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.camera instanceof GameLib.D3.Camera && this.scene instanceof GameLib.D3.Scene) {
|
|
||||||
|
|
||||||
if (!THREE.EffectComposer) {
|
|
||||||
throw "No EffectComposer";
|
|
||||||
}
|
|
||||||
|
|
||||||
this.composer = new THREE.EffectComposer(
|
|
||||||
instance,
|
|
||||||
renderTarget
|
|
||||||
);
|
|
||||||
|
|
||||||
this.renderPass = new THREE.RenderPass(
|
|
||||||
this.scene.instance,
|
|
||||||
this.camera.instance
|
|
||||||
);
|
|
||||||
|
|
||||||
this.composer.addPass(this.renderPass);
|
|
||||||
|
|
||||||
if (!THREE.CopyShader) {
|
|
||||||
throw "No CopyShader found";
|
|
||||||
}
|
|
||||||
|
|
||||||
var copyShader = THREE.CopyShader;
|
|
||||||
var copyPass = new THREE.ShaderPass(copyShader);
|
|
||||||
copyPass.renderToScreen = true;
|
|
||||||
|
|
||||||
this.composer.addPass(copyPass);
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.StereoRenderer.prototype.render = function() {
|
|
||||||
|
|
||||||
this.instance.setViewport(0, 0, this.width / 2, this.height);
|
|
||||||
this.renderPass.camera = this.camera.instance.left;
|
|
||||||
this.composer.render();
|
|
||||||
|
|
||||||
this.instance.setViewport(this.width / 2, 0, this.width / 2, this.height);
|
|
||||||
this.renderPass.camera = this.camera.instance.right;
|
|
||||||
this.composer.render();
|
|
||||||
};
|
|
|
@ -3,16 +3,14 @@
|
||||||
* created
|
* created
|
||||||
* @param apiTexture
|
* @param apiTexture
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param parentMaterial GameLib.D3.Material
|
|
||||||
* @param parentMaterialInstanceMapId String
|
|
||||||
* @param imageFactory GameLib.D3.ImageFactory result
|
* @param imageFactory GameLib.D3.ImageFactory result
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Texture = function Texture(
|
GameLib.D3.Texture = function Texture(
|
||||||
graphics,
|
graphics,
|
||||||
apiTexture,
|
apiTexture,
|
||||||
parentMaterial,
|
// parentMaterial,
|
||||||
parentMaterialInstanceMapId,
|
// parentMaterialInstanceMapId,
|
||||||
imageFactory
|
imageFactory
|
||||||
) {
|
) {
|
||||||
this.graphics = graphics;
|
this.graphics = graphics;
|
||||||
|
@ -55,9 +53,9 @@ GameLib.D3.Texture = function Texture(
|
||||||
this.repeat
|
this.repeat
|
||||||
);
|
);
|
||||||
|
|
||||||
this.parentMaterial = parentMaterial;
|
// this.parentMaterial = parentMaterial;
|
||||||
|
//
|
||||||
this.parentMaterialInstanceMapId = parentMaterialInstanceMapId;
|
// this.parentMaterialInstanceMapId = parentMaterialInstanceMapId;
|
||||||
|
|
||||||
this.imageInstance = null;
|
this.imageInstance = null;
|
||||||
|
|
||||||
|
@ -81,8 +79,8 @@ GameLib.D3.Texture.prototype.loadTexture = function(imageFactory) {
|
||||||
function (imageInstance){
|
function (imageInstance){
|
||||||
this.imageInstance = imageInstance;
|
this.imageInstance = imageInstance;
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
this.parentMaterial.instance[this.parentMaterialInstanceMapId] = this.instance;
|
// this.parentMaterial.instance[this.parentMaterialInstanceMapId] = this.instance;
|
||||||
this.parentMaterial.instance.needsUpdate = true;
|
// this.parentMaterial.instance.needsUpdate = true;
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
function onRejected() {
|
function onRejected() {
|
||||||
}
|
}
|
||||||
|
@ -177,31 +175,29 @@ GameLib.D3.Texture.TEXTURE_TYPE_SPECULAR = 'specular';
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Texture.prototype.createInstance = function(update) {
|
GameLib.D3.Texture.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
// var instance = null;
|
var instance = null;
|
||||||
//
|
|
||||||
// if (update) {
|
|
||||||
// instance = this.instance;
|
|
||||||
// instance.mapping = this.mapping;
|
|
||||||
// instance.wrapS = this.wrapS;
|
|
||||||
// instance.wrapT = this.wrapT;
|
|
||||||
// instance.magFilter = this.magFilter;
|
|
||||||
// instance.minFilter = this.minFilter;
|
|
||||||
// instance.anisotropy = this.anisotropy;
|
|
||||||
// } else {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
var instance = new THREE.Texture(
|
if (update) {
|
||||||
this.imageInstance,
|
instance = this.instance;
|
||||||
this.mapping,
|
instance.mapping = this.mapping;
|
||||||
this.wrapS,
|
instance.wrapS = this.wrapS;
|
||||||
this.wrapT,
|
instance.wrapT = this.wrapT;
|
||||||
this.magFilter,
|
instance.magFilter = this.magFilter;
|
||||||
this.minFilter,
|
instance.minFilter = this.minFilter;
|
||||||
undefined, //format and textureType is different on different archs
|
instance.anisotropy = this.anisotropy;
|
||||||
undefined,
|
} else {
|
||||||
this.anisotropy
|
instance = new THREE.Texture(
|
||||||
);
|
this.imageInstance,
|
||||||
|
this.mapping,
|
||||||
|
this.wrapS,
|
||||||
|
this.wrapT,
|
||||||
|
this.magFilter,
|
||||||
|
this.minFilter,
|
||||||
|
undefined, //format and textureType is different on different archs
|
||||||
|
undefined,
|
||||||
|
this.anisotropy
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
instance.name = this.name;
|
instance.name = this.name;
|
||||||
instance.flipY = this.flipY;
|
instance.flipY = this.flipY;
|
||||||
|
@ -215,11 +211,11 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
|
||||||
instance.premultiplyAlpha = this.premultiplyAlpha;
|
instance.premultiplyAlpha = this.premultiplyAlpha;
|
||||||
instance.textureType = this.textureType;
|
instance.textureType = this.textureType;
|
||||||
|
|
||||||
if (this.parentMaterial &&
|
// if (this.parentMaterial &&
|
||||||
this.parentMaterial.instance &&
|
// this.parentMaterial.instance &&
|
||||||
this.parentMaterialInstanceMapId) {
|
// this.parentMaterialInstanceMapId) {
|
||||||
this.parentMaterial.instance[this.parentMaterialInstanceMapId] = instance;
|
// this.parentMaterial.instance[this.parentMaterialInstanceMapId] = instance;
|
||||||
}
|
// }
|
||||||
|
|
||||||
instance.needsUpdate = true;
|
instance.needsUpdate = true;
|
||||||
|
|
||||||
|
@ -277,23 +273,21 @@ GameLib.D3.Texture.prototype.toApiTexture = function() {
|
||||||
* Converts from an Object texture to a GameLib.D3.Texture
|
* Converts from an Object texture to a GameLib.D3.Texture
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param graphics GameLib.D3.Graphics
|
||||||
* @param objectTexture Object
|
* @param objectTexture Object
|
||||||
* @param gameLibMaterial GameLib.D3.Material
|
|
||||||
* @param instanceMapId String
|
|
||||||
* @param imageFactory GameLib.D3.ImageFactory
|
* @param imageFactory GameLib.D3.ImageFactory
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Texture.FromObjectTexture = function(
|
GameLib.D3.Texture.FromObjectTexture = function(
|
||||||
graphics,
|
graphics,
|
||||||
objectTexture,
|
objectTexture,
|
||||||
gameLibMaterial,
|
// gameLibMaterial,
|
||||||
instanceMapId,
|
// instanceMapId,
|
||||||
imageFactory
|
imageFactory
|
||||||
) {
|
) {
|
||||||
|
var apiTexture = GameLib.D3.API.Texture.FromObjectTexture(objectTexture);
|
||||||
|
|
||||||
return new GameLib.D3.Texture(
|
return new GameLib.D3.Texture(
|
||||||
graphics,
|
graphics,
|
||||||
GameLib.D3.API.Texture.FromObjectTexture(objectTexture),
|
apiTexture,
|
||||||
gameLibMaterial,
|
|
||||||
instanceMapId,
|
|
||||||
imageFactory
|
imageFactory
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,19 +28,23 @@ GameLib.Entity = function (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiComponent instanceof GameLib.D3.API.Renderer) {
|
if (apiComponent instanceof GameLib.D3.API.Renderer) {
|
||||||
if (apiComponent.componentType == GameLib.Component.COMPONENT_RENDERER) {
|
return new GameLib.D3.Renderer(this.graphics, apiComponent);
|
||||||
return new GameLib.D3.Renderer(this.graphics, apiComponent);
|
}
|
||||||
} else if (apiComponent.componentType == GameLib.Component.COMPONENT_STEREO_RENDERER) {
|
|
||||||
return new GameLib.D3.StereoRenderer(this.graphics, apiComponent);
|
if (apiComponent instanceof GameLib.D3.API.RenderTarget) {
|
||||||
}
|
return new GameLib.D3.RenderTarget(this.graphics, apiComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiComponent instanceof GameLib.D3.API.Pass) {
|
||||||
|
return new GameLib.D3.Pass(this.graphics, apiComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiComponent instanceof GameLib.D3.API.Composer) {
|
||||||
|
return new GameLib.D3.Composer(this.graphics, apiComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiComponent instanceof GameLib.D3.API.Camera) {
|
if (apiComponent instanceof GameLib.D3.API.Camera) {
|
||||||
if (apiComponent.componentType == GameLib.Component.COMPONENT_CAMERA) {
|
return new GameLib.D3.Camera(this.graphics, apiComponent);
|
||||||
return new GameLib.D3.Camera(this.graphics, apiComponent);
|
|
||||||
} else if (apiComponent.componentType == GameLib.Component.COMPONENT_STEREO_CAMERA) {
|
|
||||||
return new GameLib.D3.StereoCamera(this.graphics, apiComponent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiComponent instanceof GameLib.D3.API.LookAt) {
|
if (apiComponent instanceof GameLib.D3.API.LookAt) {
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
GameLib.D3.Game = function (
|
|
||||||
|
|
||||||
) {
|
|
||||||
this.scenes = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Game.prototype.addScene = function(
|
|
||||||
scene,
|
|
||||||
identifer
|
|
||||||
) {
|
|
||||||
this.scenes[identifer] = scene;
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Game.prototype.processPhysics = function (
|
|
||||||
dt
|
|
||||||
) {
|
|
||||||
for(var s in this.scenes) {
|
|
||||||
var scene = this.scenes[s];
|
|
||||||
|
|
||||||
for(var w in scene.worlds) {
|
|
||||||
var world = scene.worlds[w];
|
|
||||||
world.step(dt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Game.prototype.render = function(
|
|
||||||
dt,
|
|
||||||
renderer
|
|
||||||
) {
|
|
||||||
for(var s in this.scenes) {
|
|
||||||
var scene = this.scenes[s];
|
|
||||||
scene.render(dt, renderer);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Game.prototype.update = function(
|
|
||||||
dt,
|
|
||||||
fixedDt
|
|
||||||
) {
|
|
||||||
for(var s in this.scenes) {
|
|
||||||
var scene = this.scenes[s];
|
|
||||||
|
|
||||||
for(var w in scene.worlds) {
|
|
||||||
var world = scene.worlds[w];
|
|
||||||
// NOTE: We are calling the step function with a variable timestep!
|
|
||||||
world.step(fixedDt, dt);
|
|
||||||
}
|
|
||||||
|
|
||||||
scene.update(dt);
|
|
||||||
scene.lateUpdate(dt);
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -66,23 +66,31 @@ GameLib.System.Render.prototype.update = function(deltaTime) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// renderObjects.forEach(function(object) {
|
var renderer = this.renderers[this.activeRendererIndex];
|
||||||
//
|
|
||||||
// //TODO camera component stuff
|
var camera = this.cameras[this.activeCameraIndex];
|
||||||
// object.quaternion.x = this.parentEntity.quaternion.x;
|
|
||||||
// object.quaternion.y = this.parentEntity.quaternion.y;
|
if (renderer.rendererType == GameLib.D3.Renderer.RENDER_TYPE_NORMAL) {
|
||||||
// object.quaternion.z = this.parentEntity.quaternion.z;
|
renderer.instance.render(
|
||||||
// object.quaternion.w = this.parentEntity.quaternion.w;
|
this.instance,
|
||||||
//
|
camera.instance
|
||||||
// object.position.x = this.parentEntity.position.x;
|
);
|
||||||
// object.position.y = this.parentEntity.position.y;
|
}
|
||||||
// object.position.z = this.parentEntity.position.z;
|
|
||||||
//
|
if (renderer.rendererType = GameLib.D3.Renderer.RENDER_TYPE_STEREO) {
|
||||||
// object.updateInstance();
|
|
||||||
//
|
renderer.composer.passes[0].instance.scene = this;
|
||||||
// //TODO scene component stuff
|
|
||||||
// renderer.render(this.instance, this.cameras[this.activeCameraIndex].instance);
|
renderer.instance.setViewport(0, 0, this.width / 2, this.height);
|
||||||
// });
|
renderer.composer.passes[0].instance.camera = camera.instance.left;
|
||||||
|
renderer.composer.instance.render();
|
||||||
|
|
||||||
|
renderer.instance.setViewport(this.width / 2, 0, this.width / 2, this.height);
|
||||||
|
renderer.composer.passes[0].instance.camera = camera.instance.right;
|
||||||
|
renderer.composer.instance.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue