From da67665771dcf7578163422ed86bc38042435195 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Tue, 30 Jan 2018 15:02:47 +0100 Subject: [PATCH] lights working - cameras working too - support for stereo camera --- src/game-lib-a-1-event.js | 6 +- src/game-lib-a-component-a.js | 8 +- src/game-lib-controls-d3-editor.js | 18 -- src/game-lib-d3-api-camera-stereo.js | 22 ++- src/game-lib-d3-api-mesh-0.js | 166 +++--------------- src/game-lib-d3-api-mesh-box.js | 71 ++++++++ src/game-lib-d3-api-mesh-curve.js | 57 +++++++ src/game-lib-d3-api-mesh-cylinder.js | 11 +- src/game-lib-d3-api-mesh-line.js | 57 +++++++ src/game-lib-d3-api-mesh-plane.js | 10 +- src/game-lib-d3-api-mesh-sphere.js | 71 ++++++++ src/game-lib-d3-api-mesh-text.js | 113 +++++++++++++ src/game-lib-d3-api-renderer.js | 100 ++++------- src/game-lib-d3-api-shadow-directional.js | 2 +- src/game-lib-d3-api-shadow-spot.js | 2 +- src/game-lib-d3-camera-a.js | 31 ++-- src/game-lib-d3-camera-cube.js | 22 +-- src/game-lib-d3-camera-orthographic.js | 44 +---- src/game-lib-d3-camera-perspective.js | 42 +---- src/game-lib-d3-camera-stereo.js | 46 +++-- src/game-lib-d3-light-a.js | 9 + src/game-lib-d3-material.js | 5 + src/game-lib-d3-mesh-0.js | 43 +++-- src/game-lib-d3-mesh-box.js | 90 +++------- src/game-lib-d3-mesh-curve.js | 58 +++++-- src/game-lib-d3-mesh-cylinder.js | 27 +-- src/game-lib-d3-mesh-line.js | 50 ++---- src/game-lib-d3-mesh-plane.js | 9 +- src/game-lib-d3-mesh-sphere.js | 72 +++----- src/game-lib-d3-mesh-text.js | 179 ++++++-------------- src/game-lib-d3-renderer.js | 195 +++++++++++++--------- src/game-lib-d3-shadow-a.js | 9 +- src/game-lib-d3-shadow-directional.js | 2 +- src/game-lib-d3-shadow-spot.js | 2 +- src/game-lib-system-gui.js | 44 ++++- src/game-lib-system-input.js | 26 ++- src/game-lib-system-render.js | 121 +++++++++----- 37 files changed, 1020 insertions(+), 820 deletions(-) create mode 100644 src/game-lib-d3-api-mesh-box.js create mode 100644 src/game-lib-d3-api-mesh-curve.js create mode 100644 src/game-lib-d3-api-mesh-line.js create mode 100644 src/game-lib-d3-api-mesh-sphere.js create mode 100644 src/game-lib-d3-api-mesh-text.js diff --git a/src/game-lib-a-1-event.js b/src/game-lib-a-1-event.js index bb4d562..24c5a26 100644 --- a/src/game-lib-a-1-event.js +++ b/src/game-lib-a-1-event.js @@ -98,7 +98,7 @@ GameLib.Event.CAST_SOURCE_CHANGED = 0x50; GameLib.Event.ANIMATION_MESH_ADDED = 0x51; GameLib.Event.ANIMATION_MESH_REMOVED = 0x52; GameLib.Event.CANVAS_CHANGE = 0x53; -GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE = 0x54; +GameLib.Event.AFTER_WINDOW_RESIZE = 0x54; GameLib.Event.LOAD_FONT = 0x55; GameLib.Event.FONT_NOT_FOUND = 0x56; GameLib.Event.STOP_ALL_AUDIO = 0x57; @@ -126,6 +126,7 @@ GameLib.Event.RECEIVE_DESTINATION_CHANGED = 0x6c; GameLib.Event.SELECTION_MODE_CHANGE = 0x6d; GameLib.Event.MESH_FACE_SELECTED = 0x6e; GameLib.Event.MESH_FACE_DESELECTED = 0x6f; +GameLib.Event.BEFORE_WINDOW_RESIZE = 0x70; /** * Returns string name of event ID @@ -219,7 +220,7 @@ GameLib.Event.GetEventName = function(number) { case 0x51 : return 'animation_mesh_added'; case 0x52 : return 'animation_mesh_removed'; case 0x53 : return 'dom_element_change'; - case 0x54 : return 'custom_code_window_resize'; + case 0x54 : return 'after_window_resize'; case 0x55 : return 'load_font'; case 0x56 : return 'font_not_found'; case 0x57 : return 'stop_all_audio'; @@ -247,6 +248,7 @@ GameLib.Event.GetEventName = function(number) { case 0x6d : return 'selection_mode_change'; case 0x6e : return 'mesh_face_selected'; case 0x6f : return 'mesh_face_deselected'; + case 0x70 : return 'before_window_resize'; break; } diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js index a48d646..ead4d90 100644 --- a/src/game-lib-a-component-a.js +++ b/src/game-lib-a-component-a.js @@ -481,7 +481,7 @@ GameLib.Component.GetComponentInfo = function(number) { }; case 0x1c : return { name : 'GameLib.D3.Shadow.Spot', - runtime : GameLib.Component.SHADOW_SPOT, + runtime : GameLib.Component.GRAPHICS_RUNTIME, constructor : GameLib.D3.Shadow.Spot, apiConstructor : GameLib.D3.API.Shadow.Spot }; @@ -840,19 +840,19 @@ GameLib.Component.GetComponentInfo = function(number) { }; case 0x58 : return { name : 'GameLib.D3.Camera.Orthographic', - runtime : GameLib.Component.CAMERA_ORTHOGRAPHIC, + runtime : GameLib.Component.GRAPHICS_RUNTIME, constructor : GameLib.D3.Camera.Orthographic, apiConstructor : GameLib.D3.API.Camera.Orthographic }; case 0x59 : return { name : 'GameLib.D3.Camera.Stereo', - runtime : GameLib.Component.CAMERA_STEREO, + runtime : GameLib.Component.GRAPHICS_RUNTIME, constructor : GameLib.D3.Camera.Stereo, apiConstructor : GameLib.D3.API.Camera.Stereo }; case 0x5a : return { name : 'GameLib.D3.Camera.Cube', - runtime : GameLib.Component.CAMERA_CUBE, + runtime : GameLib.Component.GRAPHICS_RUNTIME, constructor : GameLib.D3.Camera.Cube, apiConstructor : GameLib.D3.API.Camera.Cube }; diff --git a/src/game-lib-controls-d3-editor.js b/src/game-lib-controls-d3-editor.js index d012121..8ac8f95 100644 --- a/src/game-lib-controls-d3-editor.js +++ b/src/game-lib-controls-d3-editor.js @@ -91,21 +91,3 @@ GameLib.Controls.D3.Editor.prototype.toApiObject = function() { return apiControls; }; - -/** - * Construct an Editor Controls object from data - * @param graphics - * @param objectControls - * @returns {GameLib.Controls.D3.Editor} - * @constructor - */ -GameLib.Controls.D3.Editor.FromObject = function(graphics, objectControls) { - - var apiEditorControls = GameLib.API.Controls.D3.Editor.FromObject(objectControls); - - return new GameLib.Controls.D3.Editor( - graphics, - apiEditorControls - ); - -}; \ No newline at end of file diff --git a/src/game-lib-d3-api-camera-stereo.js b/src/game-lib-d3-api-camera-stereo.js index fcb189b..71329f4 100644 --- a/src/game-lib-d3-api-camera-stereo.js +++ b/src/game-lib-d3-api-camera-stereo.js @@ -3,12 +3,16 @@ * @constructor * @param apiCamera * @param eyeSep + * @param stereoMode + * @param main * @param cameraL * @param cameraR */ GameLib.D3.API.Camera.Stereo = function( apiCamera, eyeSep, + stereoMode, + main, cameraL, cameraR ) { @@ -29,6 +33,16 @@ GameLib.D3.API.Camera.Stereo = function( } this.eyeSep = eyeSep; + if (GameLib.Utils.UndefinedOrNull(stereoMode)) { + stereoMode = GameLib.D3.API.Camera.Stereo.STEREO_MODE_STEREO; + } + this.stereoMode = stereoMode; + + if (GameLib.Utils.UndefinedOrNull(main)) { + main = new GameLib.D3.API.Camera.Perspective(); + } + this.main = main; + if (GameLib.Utils.UndefinedOrNull(cameraL)) { cameraL = new GameLib.D3.API.Camera.Perspective(); } @@ -44,12 +58,16 @@ GameLib.D3.API.Camera.Stereo = function( apiCamera.id, apiCamera.name, apiCamera.cameraType, - apiCamera.position, apiCamera.aspect, + apiCamera.position, apiCamera.lookAt, apiCamera.parentEntity ); }; GameLib.D3.API.Camera.Stereo.prototype = Object.create(GameLib.D3.API.Camera.prototype); -GameLib.D3.API.Camera.Stereo.prototype.constructor = GameLib.D3.API.Camera.Stereo; \ No newline at end of file +GameLib.D3.API.Camera.Stereo.prototype.constructor = GameLib.D3.API.Camera.Stereo; + +GameLib.D3.API.Camera.Stereo.STEREO_MODE_STEREO = 0x1; +GameLib.D3.API.Camera.Stereo.STEREO_MODE_ANAGLYPH = 0x2; +GameLib.D3.API.Camera.Stereo.STEREO_MODE_PARALLAX = 0x3; \ No newline at end of file diff --git a/src/game-lib-d3-api-mesh-0.js b/src/game-lib-d3-api-mesh-0.js index 89c64de..3de51df 100644 --- a/src/game-lib-d3-api-mesh-0.js +++ b/src/game-lib-d3-api-mesh-0.js @@ -1,5 +1,5 @@ /** - * Raw Mesh API object - should always correspond with the Mesh Schema + * GameLib.D3.API.Mesh * @param id * @param meshType @@ -22,13 +22,15 @@ * @param isBufferMesh * @param useQuaternion * @param visible + * @param castShadow + * @param receiveShadow * @param parentEntity * @constructor */ GameLib.D3.API.Mesh = function( id, - meshType, name, + meshType, vertices, faces, materials, @@ -47,6 +49,8 @@ GameLib.D3.API.Mesh = function( isBufferMesh, useQuaternion, visible, + castShadow, + receiveShadow, parentEntity ) { if (GameLib.Utils.UndefinedOrNull(id)) { @@ -54,16 +58,16 @@ GameLib.D3.API.Mesh = function( } this.id = id; - if (GameLib.Utils.UndefinedOrNull(meshType)) { - meshType = GameLib.D3.API.Mesh.MESH_TYPE_NORMAL; - } - this.meshType = meshType; - if (GameLib.Utils.UndefinedOrNull(name)) { name = 'Mesh (' + id + ')'; } this.name = name; + if (GameLib.Utils.UndefinedOrNull(meshType)) { + meshType = GameLib.D3.API.Mesh.MESH_TYPE_NORMAL; + } + this.meshType = meshType; + if (GameLib.Utils.UndefinedOrNull(vertices)) { vertices = []; } @@ -154,6 +158,16 @@ GameLib.D3.API.Mesh = function( } this.visible = visible; + if (GameLib.Utils.UndefinedOrNull(castShadow)) { + castShadow = false; + } + this.castShadow = castShadow; + + if (GameLib.Utils.UndefinedOrNull(receiveShadow)) { + receiveShadow = false; + } + this.receiveShadow = receiveShadow; + var componentType = GameLib.Component.MESH; if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_PLANE) { @@ -204,141 +218,3 @@ GameLib.D3.API.Mesh.MESH_TYPE_BOX = 0x5; GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER = 0x6; GameLib.D3.API.Mesh.MESH_TYPE_TEXT = 0x7; GameLib.D3.API.Mesh.MESH_TYPE_LINE = 0x8; - -/** - * Returns an API Mesh from an Object mesh - * @param objectMesh - * @constructor - */ -GameLib.D3.API.Mesh.FromObject = function (objectMesh){ - - var apiFaces = []; - if (objectMesh.faces) { - apiFaces = objectMesh.faces.map( - function(face) { - return GameLib.D3.API.Face.FromObject(face); - } - ); - } - - var apiSkeleton = null; - if (objectMesh.skeleton) { - apiSkeleton = GameLib.D3.API.Skeleton.FromObject(objectMesh.skeleton); - } - - var apiMaterials = []; - if (objectMesh.materials) { - apiMaterials = objectMesh.materials.map( - function (objectMaterial) { - /** - * From blender we only get Ids to materials (strings) - */ - if (objectMaterial instanceof Object) { - return GameLib.D3.API.Material.FromObject(objectMaterial); - } else { - return objectMaterial - } - } - ) - } - - var apiVertices = []; - if (objectMesh.vertices) { - apiVertices = objectMesh.vertices.map( - function (objectVertex) { - return GameLib.D3.API.Vertex.FromObject(objectVertex); - } - ) - } - - var apiPosition = new GameLib.API.Vector3(); - if (objectMesh.position) { - apiPosition = GameLib.API.Vector3.FromObject(objectMesh.position); - } - - var apiRotation = new GameLib.API.Vector3(); - if (objectMesh.rotation) { - apiRotation = GameLib.API.Vector3.FromObject(objectMesh.rotation); - } - - var apiQuaternion = new GameLib.API.Quaternion(); - if (objectMesh.quaternion) { - apiQuaternion = GameLib.API.Quaternion.FromObject(objectMesh.quaternion); - } - - var apiScale = new GameLib.API.Vector3(1,1,1); - if (objectMesh.scale) { - apiScale = GameLib.API.Vector3.FromObject(objectMesh.scale); - } - - var apiUp = new GameLib.API.Vector3(0,1,0); - if (objectMesh.up) { - apiUp = GameLib.API.Vector3.FromObject(objectMesh.up); - } - - var apiModelMatrix = new GameLib.API.Matrix4(); - if (objectMesh.modelMatrix) { - apiModelMatrix = GameLib.API.Matrix4.FromObject(objectMesh.modelMatrix); - } - - var meshType = GameLib.D3.API.Mesh.MESH_TYPE_NORMAL; - - if (objectMesh.meshType === GameLib.D3.API.Mesh.MESH_TYPE_NORMAL || - objectMesh.meshType === GameLib.D3.API.Mesh.MESH_TYPE_SKINNED - ) { - meshType = objectMesh.meshType; - } - - if (objectMesh.componentType === GameLib.Component.MESH_PLANE) { - meshType = GameLib.D3.API.Mesh.MESH_TYPE_PLANE; - } - - if (objectMesh.componentType === GameLib.Component.MESH_SPHERE) { - meshType = GameLib.D3.API.Mesh.MESH_TYPE_SPHERE; - } - - if (objectMesh.componentType === GameLib.Component.MESH_CURVE) { - meshType = GameLib.D3.API.Mesh.MESH_TYPE_CURVE; - } - - if (objectMesh.componentType === GameLib.Component.MESH_BOX) { - meshType = GameLib.D3.API.Mesh.MESH_TYPE_BOX; - } - - if (objectMesh.componentType === GameLib.Component.MESH_CYLINDER) { - meshType = GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER; - } - - if (objectMesh.componentType === GameLib.Component.MESH_TEXT) { - meshType = GameLib.D3.API.Mesh.MESH_TYPE_TEXT; - } - - if (objectMesh.componentType === GameLib.Component.MESH_TYPE_LINE) { - meshType = GameLib.D3.API.Mesh.MESH_LINE; - } - - return new GameLib.D3.API.Mesh( - objectMesh.id, - meshType, - objectMesh.name, - apiVertices, - apiFaces, - apiMaterials, - objectMesh.parentMesh, - objectMesh.parentScene, - apiSkeleton, - objectMesh.skinIndices, - objectMesh.skinWeights, - apiPosition, - apiQuaternion, - apiRotation, - apiScale, - apiUp, - apiModelMatrix, - objectMesh.renderOrder, - objectMesh.isBufferMesh, - objectMesh.useQuaternion, - objectMesh.visible, - objectMesh.parentEntity - ); -}; diff --git a/src/game-lib-d3-api-mesh-box.js b/src/game-lib-d3-api-mesh-box.js new file mode 100644 index 0000000..62dbcb8 --- /dev/null +++ b/src/game-lib-d3-api-mesh-box.js @@ -0,0 +1,71 @@ +/** + * GameLib.D3.API.Mesh.Box + * @constructor + * @param apiMesh + * @param width + * @param height + * @param depth + */ +GameLib.D3.API.Mesh.Box = function( + apiMesh, + width, + height, + depth +) { + + if (GameLib.Utils.UndefinedOrNull(apiMesh)) { + apiMesh = { + meshType : GameLib.D3.API.Mesh.MESH_TYPE_BOX + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiMesh.meshType)) { + apiMesh.meshType = GameLib.D3.API.Mesh.MESH_TYPE_BOX; + } + + if (GameLib.Utils.UndefinedOrNull(width)) { + width = 1; + } + this.width = width; + + if (GameLib.Utils.UndefinedOrNull(height)) { + height = 1; + } + this.height = height; + + if (GameLib.Utils.UndefinedOrNull(depth)) { + depth = 1; + } + this.depth = depth; + + GameLib.D3.API.Mesh.call( + this, + apiMesh.id, + apiMesh.name, + apiMesh.meshType, + apiMesh.vertices, + apiMesh.faces, + apiMesh.materials, + apiMesh.parentMesh, + apiMesh.parentScene, + apiMesh.skeleton, + apiMesh.skinIndices, + apiMesh.skinWeights, + apiMesh.position, + apiMesh.quaternion, + apiMesh.rotation, + apiMesh.scale, + apiMesh.up, + apiMesh.modelMatrix, + apiMesh.renderOrder, + apiMesh.isBufferMesh, + apiMesh.useQuaternion, + apiMesh.visible, + apiMesh.castShadow, + apiMesh.receiveShadow, + apiMesh.parentEntity + ); +}; + +GameLib.D3.API.Mesh.Box.prototype = Object.create(GameLib.D3.API.Mesh.prototype); +GameLib.D3.API.Mesh.Box.prototype.constructor = GameLib.D3.API.Mesh.Box; diff --git a/src/game-lib-d3-api-mesh-curve.js b/src/game-lib-d3-api-mesh-curve.js new file mode 100644 index 0000000..9a14000 --- /dev/null +++ b/src/game-lib-d3-api-mesh-curve.js @@ -0,0 +1,57 @@ +/** + * GameLib.D3.API.Mesh.Curve + * @constructor + * @param apiMesh + * @param pointSize + */ +GameLib.D3.API.Mesh.Curve = function( + apiMesh, + pointSize +) { + + if (GameLib.Utils.UndefinedOrNull(apiMesh)) { + apiMesh = { + meshType : GameLib.D3.API.Mesh.MESH_TYPE_CURVE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiMesh.meshType)) { + apiMesh.meshType = GameLib.D3.API.Mesh.MESH_TYPE_CURVE; + } + + if (GameLib.Utils.UndefinedOrNull(pointSize)) { + pointSize = 1; + } + this.pointSize = pointSize; + + GameLib.D3.API.Mesh.call( + this, + apiMesh.id, + apiMesh.name, + apiMesh.meshType, + apiMesh.vertices, + apiMesh.faces, + apiMesh.materials, + apiMesh.parentMesh, + apiMesh.parentScene, + apiMesh.skeleton, + apiMesh.skinIndices, + apiMesh.skinWeights, + apiMesh.position, + apiMesh.quaternion, + apiMesh.rotation, + apiMesh.scale, + apiMesh.up, + apiMesh.modelMatrix, + apiMesh.renderOrder, + apiMesh.isBufferMesh, + apiMesh.useQuaternion, + apiMesh.visible, + apiMesh.castShadow, + apiMesh.receiveShadow, + apiMesh.parentEntity + ); +}; + +GameLib.D3.API.Mesh.Curve.prototype = Object.create(GameLib.D3.API.Mesh.prototype); +GameLib.D3.API.Mesh.Curve.prototype.constructor = GameLib.D3.API.Mesh.Curve; diff --git a/src/game-lib-d3-api-mesh-cylinder.js b/src/game-lib-d3-api-mesh-cylinder.js index 28f80aa..6c254c9 100644 --- a/src/game-lib-d3-api-mesh-cylinder.js +++ b/src/game-lib-d3-api-mesh-cylinder.js @@ -1,5 +1,5 @@ /** - * Raw Mesh.Cylinder API object + * GameLib.D3.API.Mesh.Cylinder * @constructor * @param apiMesh * @param radiusTop @@ -22,13 +22,16 @@ GameLib.D3.API.Mesh.Cylinder = function( thetaStart, thetaLength ) { - if (GameLib.Utils.UndefinedOrNull(apiMesh)) { apiMesh = { meshType : GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER }; } + if (GameLib.Utils.UndefinedOrNull(apiMesh.meshType)) { + apiMesh.meshType = GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER; + } + if (GameLib.Utils.UndefinedOrNull(radiusTop)) { radiusTop = 1; } @@ -72,8 +75,8 @@ GameLib.D3.API.Mesh.Cylinder = function( GameLib.D3.API.Mesh.call( this, apiMesh.id, - apiMesh.meshType, apiMesh.name, + apiMesh.meshType, apiMesh.vertices, apiMesh.faces, apiMesh.materials, @@ -92,6 +95,8 @@ GameLib.D3.API.Mesh.Cylinder = function( apiMesh.isBufferMesh, apiMesh.useQuaternion, apiMesh.visible, + apiMesh.castShadow, + apiMesh.receiveShadow, apiMesh.parentEntity ); }; diff --git a/src/game-lib-d3-api-mesh-line.js b/src/game-lib-d3-api-mesh-line.js new file mode 100644 index 0000000..c819f20 --- /dev/null +++ b/src/game-lib-d3-api-mesh-line.js @@ -0,0 +1,57 @@ +/** + * GameLib.D3.API.Mesh.Line + * @constructor + * @param apiMesh + * @param lineWidth + */ +GameLib.D3.API.Mesh.Line = function( + apiMesh, + lineWidth +) { + + if (GameLib.Utils.UndefinedOrNull(apiMesh)) { + apiMesh = { + meshType : GameLib.D3.API.Mesh.MESH_TYPE_LINE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiMesh.meshType)) { + apiMesh.meshType = GameLib.D3.API.Mesh.MESH_TYPE_LINE; + } + + if (GameLib.Utils.UndefinedOrNull(lineWidth)) { + lineWidth = 1; + } + this.lineWidth = lineWidth; + + GameLib.D3.API.Mesh.call( + this, + apiMesh.id, + apiMesh.name, + apiMesh.meshType, + apiMesh.vertices, + apiMesh.faces, + apiMesh.materials, + apiMesh.parentMesh, + apiMesh.parentScene, + apiMesh.skeleton, + apiMesh.skinIndices, + apiMesh.skinWeights, + apiMesh.position, + apiMesh.quaternion, + apiMesh.rotation, + apiMesh.scale, + apiMesh.up, + apiMesh.modelMatrix, + apiMesh.renderOrder, + apiMesh.isBufferMesh, + apiMesh.useQuaternion, + apiMesh.visible, + apiMesh.castShadow, + apiMesh.receiveShadow, + apiMesh.parentEntity + ); +}; + +GameLib.D3.API.Mesh.Line.prototype = Object.create(GameLib.D3.API.Mesh.prototype); +GameLib.D3.API.Mesh.Line.prototype.constructor = GameLib.D3.API.Mesh.Line; diff --git a/src/game-lib-d3-api-mesh-plane.js b/src/game-lib-d3-api-mesh-plane.js index 930c7b3..44ea58d 100644 --- a/src/game-lib-d3-api-mesh-plane.js +++ b/src/game-lib-d3-api-mesh-plane.js @@ -1,5 +1,5 @@ /** - * Raw Mesh.Plane API object + * GameLib.D3.API.Mesh.Plane * @constructor * @param apiMesh * @param width @@ -35,6 +35,10 @@ GameLib.D3.API.Mesh.Plane = function( }; } + if (GameLib.Utils.UndefinedOrNull(apiMesh.meshType)) { + apiMesh.meshType = GameLib.D3.API.Mesh.MESH_TYPE_PLANE; + } + if (GameLib.Utils.UndefinedOrNull(width)) { width = 1; } @@ -93,8 +97,8 @@ GameLib.D3.API.Mesh.Plane = function( GameLib.D3.API.Mesh.call( this, apiMesh.id, - apiMesh.meshType, apiMesh.name, + apiMesh.meshType, apiMesh.vertices, apiMesh.faces, apiMesh.materials, @@ -113,6 +117,8 @@ GameLib.D3.API.Mesh.Plane = function( apiMesh.isBufferMesh, apiMesh.useQuaternion, apiMesh.visible, + apiMesh.castShadow, + apiMesh.receiveShadow, apiMesh.parentEntity ); }; diff --git a/src/game-lib-d3-api-mesh-sphere.js b/src/game-lib-d3-api-mesh-sphere.js new file mode 100644 index 0000000..972b75c --- /dev/null +++ b/src/game-lib-d3-api-mesh-sphere.js @@ -0,0 +1,71 @@ +/** + * GameLib.D3.API.Mesh.Sphere + * @constructor + * @param apiMesh + * @param radius + * @param widthSegments + * @param heightSegments + */ +GameLib.D3.API.Mesh.Sphere = function( + apiMesh, + radius, + widthSegments, + heightSegments +) { + + if (GameLib.Utils.UndefinedOrNull(apiMesh)) { + apiMesh = { + meshType : GameLib.D3.API.Mesh.MESH_TYPE_SPHERE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiMesh.meshType)) { + apiMesh.meshType = GameLib.D3.API.Mesh.MESH_TYPE_SPHERE; + } + + if (GameLib.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + if (GameLib.Utils.UndefinedOrNull(widthSegments)) { + widthSegments = 5; + } + this.widthSegments = widthSegments; + + if (GameLib.Utils.UndefinedOrNull(heightSegments)) { + heightSegments = 5; + } + this.heightSegments = heightSegments; + + GameLib.D3.API.Mesh.call( + this, + apiMesh.id, + apiMesh.name, + apiMesh.meshType, + apiMesh.vertices, + apiMesh.faces, + apiMesh.materials, + apiMesh.parentMesh, + apiMesh.parentScene, + apiMesh.skeleton, + apiMesh.skinIndices, + apiMesh.skinWeights, + apiMesh.position, + apiMesh.quaternion, + apiMesh.rotation, + apiMesh.scale, + apiMesh.up, + apiMesh.modelMatrix, + apiMesh.renderOrder, + apiMesh.isBufferMesh, + apiMesh.useQuaternion, + apiMesh.visible, + apiMesh.castShadow, + apiMesh.receiveShadow, + apiMesh.parentEntity + ); +}; + +GameLib.D3.API.Mesh.Sphere.prototype = Object.create(GameLib.D3.API.Mesh.prototype); +GameLib.D3.API.Mesh.Sphere.prototype.constructor = GameLib.D3.API.Mesh.Sphere; diff --git a/src/game-lib-d3-api-mesh-text.js b/src/game-lib-d3-api-mesh-text.js new file mode 100644 index 0000000..c90eb0f --- /dev/null +++ b/src/game-lib-d3-api-mesh-text.js @@ -0,0 +1,113 @@ +/** + * GameLib.D3.API.Mesh.Text + * @constructor + * @param apiMesh + * @param text + * @param font + * @param size + * @param height + * @param curveSegments + * @param bevelEnabled + * @param bevelThickness + * @param bevelSize + * @param bevelSegments + */ +GameLib.D3.API.Mesh.Text = function( + apiMesh, + text, + font, + size, + height, + curveSegments, + bevelEnabled, + bevelThickness, + bevelSize, + bevelSegments +) { + + if (GameLib.Utils.UndefinedOrNull(apiMesh)) { + apiMesh = { + meshType : GameLib.D3.API.Mesh.MESH_TYPE_TEXT + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiMesh.meshType)) { + apiMesh.meshType = GameLib.D3.API.Mesh.MESH_TYPE_TEXT; + } + + if (GameLib.Utils.UndefinedOrNull(text)) { + text = '-= this.windowSize.y) { + /** + * Landscape Mode + */ + // this.camera.aspect = this.windowSize.x / this.windowSize.y; + // this.editCamera.aspect = this.windowSize.x / this.windowSize.y; + console.log('landscape'); + } + + if (this.windowSize.x < this.windowSize.y) { + /** + * Portrait Mode + */ + // this.camera.aspect = this.windowSize.y / this.windowSize.x; + // this.editCamera.aspect = this.windowSize.y / this.windowSize.x; + console.log('portrait'); + } + this.camera.aspect = this.windowSize.x / this.windowSize.y; + this.editCamera.aspect = this.windowSize.x / this.windowSize.y; + this.camera.updateInstance('aspect'); + this.editCamera.updateInstance('aspect'); + + return; + } + + console.warn('todo : update aspect ratio for scale mode : ' + this.scaleMode); + + return; + } + + if (property === 'scaleMode') { + this.updateInstance('aspectRatio'); + return; + } + if (property === 'windowSize') { - trueWidth = this.width * this.windowSize.x; - trueHeight = this.height * this.windowSize.y; + trueWidth = this.width * this.windowSize.x; + trueHeight = this.height * this.windowSize.y; this.canvas.width = trueWidth; this.canvas.height = trueHeight; @@ -467,32 +511,38 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) { ); this.canvas.instance.style.left = (this.offset.x * this.windowSize.x) + 'px'; - this.canvas.instance.style.top = (this.offset.y * this.windowSize.y) + 'px'; + this.canvas.instance.style.top = (this.offset.y * this.windowSize.y) + 'px'; - this.camera.aspect = trueWidth / trueHeight; - this.camera.updateInstance('aspect'); - - this.editCamera.aspect = trueWidth / trueHeight; - this.editCamera.updateInstance('aspect'); + this.updateInstance('aspectRatio'); + return; } + if (property === 'logicalSize') { + this.updateInstance('aspectRatio'); + return; + } + if (property === 'offset') { this.canvas.instance.style.left = (this.offset.x * this.windowSize.x) + 'px'; this.canvas.instance.style.top = (this.offset.y * this.windowSize.y) + 'px'; + return; } if (property === 'canvas') { console.warn('experimental canvas change for renderer'); this.instance.dispose(); this.createInstance(); + return; } if (property === 'renderTarget') { console.warn('todo: render target change'); + return; } if (property === 'clippingPlanes') { console.warn('todo: clipping planes change'); + return; } if (property === 'clearColor') { @@ -504,6 +554,7 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) { ), 1 - this.clearColor.a ); + return; } if (property === 'camera') { @@ -575,8 +626,10 @@ GameLib.D3.Renderer.prototype.toApiObject = function() { this.depth, this.logarithmicDepthBuffer, this.localClippingEnabled, - this.fullscreen, + this.aspectRatio, + this.scaleMode, this.windowSize.toApiObject(), + this.logicalSize.toApiObject(), this.offset.toApiObject(), GameLib.Utils.IdOrNull(this.canvas), GameLib.Utils.IdOrNull(this.renderTarget), @@ -604,21 +657,3 @@ GameLib.D3.Renderer.prototype.toApiObject = function() { return apiRenderer; }; - -/** - * - * @param graphics - * @param objectComponent - * @returns {GameLib.D3.Renderer} - * @constructor - */ -GameLib.D3.Renderer.FromObject = function(graphics, objectComponent) { - - var apiRenderer = GameLib.D3.API.Renderer.FromObject(objectComponent); - - return new GameLib.D3.Renderer( - graphics, - apiRenderer - ); -}; - diff --git a/src/game-lib-d3-shadow-a.js b/src/game-lib-d3-shadow-a.js index 8269dee..0693e16 100644 --- a/src/game-lib-d3-shadow-a.js +++ b/src/game-lib-d3-shadow-a.js @@ -37,6 +37,12 @@ GameLib.D3.Shadow = function( ) } + this.mapSize = new GameLib.Vector2( + this.graphics, + this.mapSize, + this + ); + GameLib.Component.call(this); }; @@ -120,7 +126,8 @@ GameLib.D3.Shadow.prototype.toApiObject = function() { GameLib.D3.Shadow.prototype.updateFromInstance = function() { this.bias = this.instance.bias; - this.mapSize = this.instance.mapSize; + this.mapSize.x = this.instance.mapSize.x; + this.mapSize.y = this.instance.mapSize.y; this.radius = this.instance.radius; this.camera.instance = this.instance.camera; this.camera.updateFromInstance(); diff --git a/src/game-lib-d3-shadow-directional.js b/src/game-lib-d3-shadow-directional.js index 8c47c46..d0a772f 100644 --- a/src/game-lib-d3-shadow-directional.js +++ b/src/game-lib-d3-shadow-directional.js @@ -33,7 +33,7 @@ GameLib.D3.Shadow.Directional = function( GameLib.D3.Shadow.call( this, this.graphics, - apiDirectionalShadow + this ); }; diff --git a/src/game-lib-d3-shadow-spot.js b/src/game-lib-d3-shadow-spot.js index 8654e54..fb735ac 100644 --- a/src/game-lib-d3-shadow-spot.js +++ b/src/game-lib-d3-shadow-spot.js @@ -59,7 +59,7 @@ GameLib.D3.Shadow.Spot.prototype.updateInstance = function(property) { if (property === 'camera') { - console.warn('todo: updateInstance for directional shadow camera instance'); + console.warn('todo: updateInstance for spot shadow camera instance'); return; } diff --git a/src/game-lib-system-gui.js b/src/game-lib-system-gui.js index 1386ed8..f6f77ac 100644 --- a/src/game-lib-system-gui.js +++ b/src/game-lib-system-gui.js @@ -72,6 +72,8 @@ GameLib.System.GUI.prototype.initialize = function(gui) { gui.instance.domElement.style.right = '0px'; gui.domElement.instance.parentElement.appendChild(gui.instance.domElement); + + gui.instance.domElement.getElementsByTagName('ul')[0].style.maxHeight = window.screen.availHeight - 93 + 'px'; }; GameLib.System.GUI.prototype.instanceCreated = function(data) { @@ -915,6 +917,18 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, } ) ); + } else if (property === 'stereoMode') { + controllers.push( + folder.add( + object, + property, + { + 'stereo' : GameLib.D3.API.Camera.Stereo.STEREO_MODE_STEREO, + 'anaglyph' : GameLib.D3.API.Camera.Stereo.STEREO_MODE_ANAGLYPH, + 'parallax' : GameLib.D3.API.Camera.Stereo.STEREO_MODE_PARALLAX + } + ) + ); } else if (property === 'socketType') { controllers.push( folder.add( @@ -1386,7 +1400,35 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate, } ) ); - } else if (property === 'encoding') { + } else if (property === 'aspectRatio') { + controllers.push( + folder.add( + object, + property, + { + 'none': GameLib.D3.API.Renderer.ASPECT_RATIO_NONE, + '4:3 (1.3333)': GameLib.D3.API.Renderer.ASPECT_RATIO_4_3, + '3:2 (1.5)': GameLib.D3.API.Renderer.ASPECT_RATIO_3_2, + '16:10 (1.6667)': GameLib.D3.API.Renderer.ASPECT_RATIO_16_10, + '17:10 (1.7)': GameLib.D3.API.Renderer.ASPECT_RATIO_17_10, + '16:9 (1.7778)': GameLib.D3.API.Renderer.ASPECT_RATIO_16_9 + } + ) + ); + } else if (property === 'scaleMode') { + controllers.push( + folder.add( + object, + property, + { + 'none': GameLib.D3.API.Renderer.SCALE_MODE_NONE, + 'letterbox': GameLib.D3.API.Renderer.SCALE_MODE_LETTERBOX, + 'zoom-bigger': GameLib.D3.API.Renderer.SCALE_MODE_ZOOM_TO_BIGGER, + 'non-uniform': GameLib.D3.API.Renderer.SCALE_MODE_NON_UNIFORM + } + ) + ); + } else if (property === 'encoding') { controllers.push( folder.add( object, diff --git a/src/game-lib-system-input.js b/src/game-lib-system-input.js index 7c2d361..9e85799 100644 --- a/src/game-lib-system-input.js +++ b/src/game-lib-system-input.js @@ -1083,6 +1083,24 @@ GameLib.System.Input.prototype.onMouseMoveEdit = function(event) { mouse.y = event.clientY; } ) + + this.editorControls.map( + function(editorControl) { + editorControl.camera.position.x = editorControl.camera.instance.position.x; + editorControl.camera.position.y = editorControl.camera.instance.position.y; + editorControl.camera.position.z = editorControl.camera.instance.position.z; + // + // editorControl.camera.quaternion.x = editorControl.camera.instance.quaternion.x; + // editorControl.camera.quaternion.y = editorControl.camera.instance.quaternion.y; + // editorControl.camera.quaternion.z = editorControl.camera.instance.quaternion.z; + // editorControl.camera.quaternion.w = editorControl.camera.instance.quaternion.w; + + editorControl.camera.lookAt.x = editorControl.instance.center.x; + editorControl.camera.lookAt.y = editorControl.instance.center.y; + editorControl.camera.lookAt.z = editorControl.instance.center.z; + editorControl.camera.lookAt.instance.copy(editorControl.instance.center); + } + ); }; /** @@ -1100,7 +1118,13 @@ GameLib.System.Input.prototype.onMouseUpEdit = function(event) { * @param event */ GameLib.System.Input.prototype.onMouseWheelEdit = function(event) { - + this.editorControls.map( + function(editorControl) { + editorControl.camera.position.x = editorControl.camera.instance.position.x; + editorControl.camera.position.y = editorControl.camera.instance.position.y; + editorControl.camera.position.z = editorControl.camera.instance.position.z; + } + ); }; GameLib.System.Input.prototype.selectFace = function(mesh, face) { diff --git a/src/game-lib-system-render.js b/src/game-lib-system-render.js index 524f114..0a01379 100644 --- a/src/game-lib-system-render.js +++ b/src/game-lib-system-render.js @@ -58,25 +58,25 @@ GameLib.System.Render.prototype.start = function() { this.windowResize ); - window.addEventListener( - 'resize', - this.nativeWindowResize, - false - ); + // window.addEventListener( + // 'resize', + // this.nativeWindowResize, + // false + // ); - window.addEventListener( - "orientationchangeend", - this.nativeWindowResize, - false - ); + // window.addEventListener( + // "orientationchangeend", + // this.nativeWindowResize, + // false + // ); - GameLib.Event.Emit( - GameLib.Event.WINDOW_RESIZE, - { - width : window.screen.availWidth, - height : window.screen.availHeight - } - ); + // GameLib.Event.Emit( + // GameLib.Event.WINDOW_RESIZE, + // { + // width : window.screen.availWidth, + // height : window.screen.availHeight + // } + // ); this.run(); @@ -97,15 +97,15 @@ GameLib.System.Render.prototype.run = function() { }; -GameLib.System.Render.prototype.nativeWindowResize = function() { - GameLib.Event.Emit( - GameLib.Event.WINDOW_RESIZE, - { - width : window.screen.availWidth, - height : window.screen.availHeight - } - ); -}; +// GameLib.System.Render.prototype.nativeWindowResize = function() { +// GameLib.Event.Emit( +// GameLib.Event.WINDOW_RESIZE, +// { +// width : window.screen.availWidth, +// height : window.screen.availHeight +// } +// ); +// }; GameLib.System.Render.prototype.getOffset = function (el) { var rect = el.getBoundingClientRect(), @@ -116,6 +116,11 @@ GameLib.System.Render.prototype.getOffset = function (el) { GameLib.System.Render.prototype.windowResize = function(data) { + GameLib.Event.Emit( + GameLib.Event.BEFORE_WINDOW_RESIZE, + data + ); + var renderers = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RENDERER); renderers.map( @@ -129,11 +134,8 @@ GameLib.System.Render.prototype.windowResize = function(data) { ); GameLib.Event.Emit( - GameLib.Event.CUSTOM_CODE_WINDOW_RESIZE, - { - width : data.width, - height : data.height - } + GameLib.Event.AFTER_WINDOW_RESIZE, + data ); }; @@ -272,7 +274,7 @@ GameLib.System.Render.prototype.render = function(data) { trueHeight ); - var aspect = trueWidth / trueHeight; + //var aspect = trueWidth / trueHeight; renderer.scenes.map( function (scene) { @@ -325,10 +327,41 @@ GameLib.System.Render.prototype.render = function(data) { camera.instance ); } else if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_EDIT) { - renderer.instance.render( - scene.instance, - camera.instance - ) + + if (camera instanceof GameLib.D3.Camera.Stereo) { + + var size = renderer.instance.getSize(); + + scene.instance.updateMatrixWorld(); + + camera.instance.updateMatrixWorld(); + + camera.instance.update(camera.main.instance); + + renderer.instance.clear(); + + renderer.instance.setScissorTest(true); + + renderer.instance.setScissor(0, 0, size.width / 2, size.height); + renderer.instance.setViewport(0, 0, size.width / 2, size.height); + renderer.instance.render(scene.instance, camera.instance.cameraL); + + renderer.instance.setScissor(size.width / 2, 0, size.width / 2, size.height); + renderer.instance.setViewport(size.width / 2, 0, size.width / 2, size.height); + renderer.instance.render(scene.instance, camera.instance.cameraR); + + renderer.instance.setScissorTest(false); + + } else { + + renderer.instance.render( + scene.instance, + camera.instance + ) + + } + + } else { console.warn('unknown render mode:' + renderer.renderMode); } @@ -368,11 +401,17 @@ GameLib.System.Render.prototype.stop = function() { this.renderSubscription.remove(); - window.removeEventListener( - 'resize', - this.nativeWindowResize, - false - ); + // window.removeEventListener( + // 'resize', + // this.nativeWindowResize, + // false + // ); + + // window.removeEventListener( + // 'orientationchangeend', + // this.nativeWindowResize, + // false + // ); this.windowResizeSubscription.remove();