bad clipping plane implementation

beta.r3js.org
-=yb4f310 2017-09-20 15:24:15 +02:00
parent 988e7b5165
commit 6f9dc88a78
5 changed files with 113 additions and 6 deletions

View File

@ -86,6 +86,7 @@ GameLib.Event.ANIMATION_COMPILE_SUCCESS = 0x44;
GameLib.Event.ANIMATION_COMPILE_FAILED = 0x45;
GameLib.Event.CUSTOM_CODE_SYSTEM_STARTED = 0x46;
GameLib.Event.GAME_OVER = 0x47;
GameLib.Event.GAME_START = 0x48;
/**
* Returns string name of event ID
@ -167,6 +168,7 @@ GameLib.Event.GetEventName = function(number) {
case 0x45 : return 'animation_compile_failed';
case 0x46 : return 'custom_code_system_started';
case 0x47 : return 'game_over';
case 0x48 : return 'game_start';
break;
}

View File

@ -13,6 +13,7 @@
* @param viewports
* @param parentEntity
* @param preserveDrawingBuffer
* @param clippingPlanes
* @constructor
*/
GameLib.D3.API.Renderer = function (
@ -28,6 +29,7 @@ GameLib.D3.API.Renderer = function (
camera,
scenes,
viewports,
clippingPlanes,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
@ -47,6 +49,10 @@ GameLib.D3.API.Renderer = function (
if (GameLib.Utils.UndefinedOrNull(localClipping)) {
localClipping = false;
if (clippingPlanes && clippingPlanes.length > 0) {
localClipping = true;
}
}
this.localClipping = localClipping;
@ -90,6 +96,11 @@ GameLib.D3.API.Renderer = function (
}
this.viewports = viewports;
if (GameLib.Utils.UndefinedOrNull(clippingPlanes)) {
clippingPlanes = [];
}
this.clippingPlanes = clippingPlanes;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
@ -119,6 +130,7 @@ GameLib.D3.API.Renderer.FromObject = function(objectComponent) {
objectComponent.camera,
objectComponent.scenes,
objectComponent.viewports,
objectComponent.clippingPlanes,
objectComponent.parentEntity
);
};

View File

@ -1001,6 +1001,10 @@ GameLib.D3.Mesh.prototype.updateInstancePosition = function() {
this.position.instance.y = this.position.y;
this.position.instance.z = this.position.z;
this.instance.position.copy(this.position.instance);
if (this.helper) {
this.removeHelper();
this.createHelper();
}
};

View File

@ -8,6 +8,8 @@
* @param heightSegments
* @param heightMapScale
* @param isHeightMap
* @param isClippingPlane
* @param distanceFromOrigin
* @constructor
*/
GameLib.D3.Mesh.Plane = function (
@ -18,7 +20,9 @@ GameLib.D3.Mesh.Plane = function (
widthSegments,
heightSegments,
heightMapScale,
isHeightMap
isHeightMap,
isClippingPlane,
distanceFromOrigin
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
@ -53,7 +57,17 @@ GameLib.D3.Mesh.Plane = function (
}
this.isHeightMap = isHeightMap;
GameLib.D3.Mesh.call(
if (GameLib.Utils.UndefinedOrNull(isClippingPlane)) {
isClippingPlane = false;
}
this.isClippingPlane = isClippingPlane;
if (GameLib.Utils.UndefinedOrNull(distanceFromOrigin)) {
distanceFromOrigin = 0;
}
this.distanceFromOrigin = distanceFromOrigin;
GameLib.D3.Mesh.call(
this,
this.graphics,
apiMesh
@ -104,6 +118,17 @@ GameLib.D3.Mesh.Plane.prototype.createInstance = function() {
instance.userData.heightSegments = this.heightSegments;
instance.userData.heightMapScale = this.heightMapScale;
instance.userData.isHeightMap = this.isHeightMap;
instance.userData.isClippingPlane = this.isClippingPlane;
instance.userData.distanceFromOrigin = this.distanceFromOrigin;
if (this.isClippingPlane) {
instance.clipping = new THREE.Plane(
geometry.faces[0].normal,
this.distanceFromOrigin
);
}
return instance;
};
@ -121,7 +146,9 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function() {
this.instance.userData.widthSegments !== this.widthSegments ||
this.instance.userData.heightSegments !== this.heightSegments ||
this.instance.userData.isHeightMap !== this.isHeightMap ||
this.instance.userData.heightMapScale !== this.heightMapScale
this.instance.userData.heightMapScale !== this.heightMapScale ||
this.instance.userData.isClippingPlane !== this.isClippingPlane ||
this.instance.userData.distanceFromOrigin !== this.distanceFromOrigin
) {
this.instance.userData.width = this.width;
this.instance.userData.height = this.height;
@ -129,6 +156,8 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function() {
this.instance.userData.heightSegments = this.heightSegments;
this.instance.userData.isHeightMap = this.isHeightMap;
this.instance.userData.heightMapScale = this.heightMapScale;
this.instance.userData.isClippingPlane = this.isClippingPlane;
this.instance.userData.distanceFromOrigin = this.distanceFromOrigin;
geometry = new THREE.PlaneGeometry(
this.width,
@ -146,7 +175,14 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function() {
geometry = this.createInstanceGeometry();
this.instance.geometry = geometry;
}
if (this.isClippingPlane) {
this.instance.clipping = new THREE.Plane(
geometry.faces[0].normal,
this.distanceFromOrigin
)
}
}
GameLib.D3.Mesh.prototype.updateInstance.call(this);
};
@ -165,6 +201,8 @@ GameLib.D3.Mesh.Plane.prototype.toApiObject = function() {
apiMesh.heightSegments = this.heightSegments;
apiMesh.heightMapScale = this.heightMapScale;
apiMesh.isHeightMap = this.isHeightMap;
apiMesh.isClippingPlane = this.isClippingPlane;
apiMesh.distanceFromOrigin = this.distanceFromOrigin;
return apiMesh;
};
@ -188,7 +226,9 @@ GameLib.D3.Mesh.Plane.FromObject = function(graphics, objectMesh) {
objectMesh.widthSegments,
objectMesh.heightSegments,
objectMesh.heightMapScale,
objectMesh.isHeightMap
objectMesh.isHeightMap,
objectMesh.isClippingPlane,
objectMesh.distanceFromOrigin
);
};

View File

@ -36,6 +36,7 @@ GameLib.D3.Renderer = function (
apiRenderer.camera,
apiRenderer.scenes,
apiRenderer.viewports,
apiRenderer.clippingPlanes,
apiRenderer.parentEntity
);
@ -80,6 +81,25 @@ GameLib.D3.Renderer = function (
}
}.bind(this));
this.clippingPlanes = this.clippingPlanes.map(function(clippingPlane){
if (clippingPlane instanceof GameLib.D3.API.Mesh) {
return new GameLib.D3.Mesh.Plane(
this.graphics,
clippingPlane,
clippingPlane.width,
clippingPlane.height,
clippingPlane.widthSegments,
clippingPlane.heightSegments,
clippingPlane.heightMapScale,
clippingPlane.isHeightMap,
clippingPlane.isClippingPlane,
clippingPlane.distanceFromOrigin
);
} else {
return clippingPlane;
}
}.bind(this));
/**
* Only runtime Renderer Components have runtime statistics
*/
@ -99,7 +119,8 @@ GameLib.D3.Renderer = function (
'domElement' : GameLib.DomElement,
'camera' : GameLib.D3.Camera,
'scenes' : [GameLib.D3.Scene],
'viewports' : [GameLib.D3.Viewport]
'viewports' : [GameLib.D3.Viewport],
'clippingPlanes': [GameLib.D3.Mesh.Plane]
}
);
@ -118,6 +139,19 @@ GameLib.D3.Renderer.prototype.createInstance = function() {
canvas : this.domElement.instance
});
if (this.clippingPlanes.length > 0) {
instance.clippingPlanes = this.clippingPlanes.map(
function(clippingPlane) {
if (!clippingPlane.isClippingPlane || !clippingPlane.instance || !clippingPlane.instance.clipping) {
throw new Error('is not a clipping plane or no clipping plane instance');
}
return clippingPlane.instance.clipping;
}
)
}
instance.localClippingEnabled = this.localClipping;
instance.setSize(
@ -169,6 +203,21 @@ GameLib.D3.Renderer.prototype.updateInstance = function() {
this.instance.autoClear = this.autoClear;
this.instance.preserveDrawingBuffer = this.preserveDrawingBuffer;
if (this.clippingPlanes.length > 0) {
this.instance.clippingPlanes = this.clippingPlanes.map(
function(clippingPlane) {
if (!clippingPlane.isClippingPlane || !clippingPlane.instance || !clippingPlane.instance.clipping) {
throw new Error('is not a clipping plane or no clipping plane instance');
}
return clippingPlane.instance.clipping;
}
)
} else {
this.instance.clippingPlanes = [];
}
};
/**