mesh plane streamline

beta.r3js.org
-=yb4f310 2017-12-30 12:43:58 +01:00
parent 806abb380f
commit 5236d0965c
3 changed files with 73 additions and 93 deletions

View File

@ -9,7 +9,7 @@
* @param heightMapScale * @param heightMapScale
* @param isHeightMap * @param isHeightMap
* @param isDotMap * @param isDotMap
* @param distanceFromOrigin * @param dotObject
*/ */
GameLib.D3.API.Mesh.Plane = function( GameLib.D3.API.Mesh.Plane = function(
apiMesh, apiMesh,
@ -20,18 +20,15 @@ GameLib.D3.API.Mesh.Plane = function(
heightMapScale, heightMapScale,
isHeightMap, isHeightMap,
isDotMap, isDotMap,
distanceFromOrigin dotObject
) { ) {
if (GameLib.Utils.UndefinedOrNull(apiMesh)) { if (GameLib.Utils.UndefinedOrNull(apiMesh)) {
apiMesh = {}; apiMesh = {
meshType : GameLib.D3.API.Mesh.MESH_TYPE_PLANE
};
} }
GameLib.D3.API.Mesh.call(
this,
apiMesh
);
if (GameLib.Utils.UndefinedOrNull(width)) { if (GameLib.Utils.UndefinedOrNull(width)) {
width = 1; width = 1;
} }
@ -43,12 +40,12 @@ GameLib.D3.API.Mesh.Plane = function(
this.height = height; this.height = height;
if (GameLib.Utils.UndefinedOrNull(widthSegments)) { if (GameLib.Utils.UndefinedOrNull(widthSegments)) {
widthSegments = 1; widthSegments = 5;
} }
this.widthSegments = widthSegments; this.widthSegments = widthSegments;
if (GameLib.Utils.UndefinedOrNull(heightSegments)) { if (GameLib.Utils.UndefinedOrNull(heightSegments)) {
heightSegments = 1 heightSegments = 5;
} }
this.heightSegments = heightSegments; this.heightSegments = heightSegments;
@ -67,14 +64,35 @@ GameLib.D3.API.Mesh.Plane = function(
} }
this.isDotMap = isDotMap; this.isDotMap = isDotMap;
if (GameLib.Utils.UndefinedOrNull(distanceFromOrigin)) { if (GameLib.Utils.UndefinedOrNull(dotObject)) {
distanceFromOrigin = 0; dotObject = null;
} }
this.distanceFromOrigin = distanceFromOrigin; this.dotObject = dotObject;
GameLib.API.Component.call( GameLib.D3.API.Mesh.call(
this, this,
GameLib.Component.SOCKET_CAST apiMesh.id,
apiMesh.meshType,
apiMesh.name,
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.parentEntity
); );
}; };
@ -88,11 +106,8 @@ GameLib.D3.API.Mesh.Plane.prototype.constructor = GameLib.D3.API.Mesh.Plane;
*/ */
GameLib.D3.API.Mesh.Plane.FromObject = function (objectMesh){ GameLib.D3.API.Mesh.Plane.FromObject = function (objectMesh){
var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh);
return new GameLib.D3.API.Mesh.Plane( return new GameLib.D3.API.Mesh.Plane(
apiMesh, GameLib.D3.API.Mesh.FromObject(objectMesh),
objectMesh.width, objectMesh.width,
objectMesh.height, objectMesh.height,
objectMesh.widthSegments, objectMesh.widthSegments,
@ -100,7 +115,7 @@ GameLib.D3.API.Mesh.Plane.FromObject = function (objectMesh){
objectMesh.heightMapScale, objectMesh.heightMapScale,
objectMesh.isHeightMap, objectMesh.isHeightMap,
objectMesh.isDotMap, objectMesh.isDotMap,
objectMesh.distanceFromOrigin GameLib.Utils.IdOrNull(objectMesh.dotObject)
); );
}; };

View File

@ -138,6 +138,10 @@ GameLib.D3.Mesh = function (
'skeleton' : GameLib.D3.Skeleton 'skeleton' : GameLib.D3.Skeleton
}; };
if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_PLANE) {
linkedObjects.dotObject = GameLib.D3.Mesh;
}
if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_TEXT) { if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_TEXT) {
linkedObjects.font = GameLib.D3.Font; linkedObjects.font = GameLib.D3.Font;
} }

View File

@ -9,7 +9,6 @@ GameLib.D3.Mesh.Plane = function (
apiMeshPlane apiMeshPlane
) { ) {
this.graphics = graphics; this.graphics = graphics;
this.graphics.isNotThreeThrow(); this.graphics.isNotThreeThrow();
@ -19,10 +18,6 @@ GameLib.D3.Mesh.Plane = function (
}; };
} }
if (apiMeshPlane instanceof GameLib.D3.Mesh.Plane) {
return apiMeshPlane;
}
GameLib.D3.API.Mesh.Plane.call( GameLib.D3.API.Mesh.Plane.call(
this, this,
apiMeshPlane, apiMeshPlane,
@ -33,7 +28,7 @@ GameLib.D3.Mesh.Plane = function (
apiMeshPlane.heightMapScale, apiMeshPlane.heightMapScale,
apiMeshPlane.isHeightMap, apiMeshPlane.isHeightMap,
apiMeshPlane.isDotMap, apiMeshPlane.isDotMap,
apiMeshPlane.distanceFromOrigin apiMeshPlane.dotObject
); );
GameLib.D3.Mesh.call( GameLib.D3.Mesh.call(
@ -47,7 +42,6 @@ GameLib.D3.Mesh.Plane = function (
GameLib.D3.Mesh.Plane.prototype = Object.create(GameLib.D3.Mesh.prototype); GameLib.D3.Mesh.Plane.prototype = Object.create(GameLib.D3.Mesh.prototype);
GameLib.D3.Mesh.Plane.prototype.constructor = GameLib.D3.Mesh.Plane; GameLib.D3.Mesh.Plane.prototype.constructor = GameLib.D3.Mesh.Plane;
GameLib.D3.Mesh.Plane.prototype.createInstance = function() { GameLib.D3.Mesh.Plane.prototype.createInstance = function() {
var geometry = null; var geometry = null;
@ -79,23 +73,8 @@ GameLib.D3.Mesh.Plane.prototype.createInstance = function() {
*/ */
GameLib.D3.Mesh.prototype.createInstance.call(this); GameLib.D3.Mesh.prototype.createInstance.call(this);
/** if (this.isDotMap && this.dotObject) {
* Apply some plane specific data to the instance console.log('todo: construct dotmap here')
*/
this.instance.userData.width = this.width;
this.instance.userData.height = this.height;
this.instance.userData.widthSegments = this.widthSegments;
this.instance.userData.heightSegments = this.heightSegments;
this.instance.userData.heightMapScale = this.heightMapScale;
this.instance.userData.isHeightMap = this.isHeightMap;
this.instance.userData.isClippingPlane = this.isClippingPlane;
this.instance.userData.distanceFromOrigin = this.distanceFromOrigin;
if (this.isClippingPlane) {
this.instance.clipping = new THREE.Plane(
geometry.faces[0].normal,
this.distanceFromOrigin
);
} }
}; };
@ -106,26 +85,16 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
var geometry = null; var geometry = null;
if ( if (
this.instance.userData.width !== this.width || property === 'width' ||
this.instance.userData.height !== this.height || property === 'height' ||
this.instance.userData.widthSegments !== this.widthSegments || property === 'widthSegments' ||
this.instance.userData.heightSegments !== this.heightSegments || property === 'heightSegments' ||
this.instance.userData.isHeightMap !== this.isHeightMap || property === 'isHeightMap' ||
this.instance.userData.heightMapScale !== this.heightMapScale || property === '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;
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.isClippingPlane = this.isClippingPlane;
this.instance.userData.distanceFromOrigin = this.distanceFromOrigin;
geometry = new THREE.PlaneGeometry( geometry = new THREE.PlaneGeometry(
this.width, this.width,
this.height, this.height,
this.widthSegments, this.widthSegments,
@ -135,19 +104,19 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
this.updateVerticesFromGeometryInstance(geometry); this.updateVerticesFromGeometryInstance(geometry);
if (this.isHeightMap) { if (this.isHeightMap) {
this.generateHeightMapFromBumpMap(); this.generateHeightMapFromBumpMap();
} }
geometry = this.createInstanceGeometry(); geometry = this.createInstanceGeometry();
this.instance.geometry = geometry; this.instance.geometry = geometry;
}
if (this.isClippingPlane) { if (
this.instance.clipping = new THREE.Plane( property === 'isDotMap' ||
geometry.faces[0].normal, property === 'dotObject'
this.distanceFromOrigin ) {
) console.log('todo: implement dotmap');
}
} }
GameLib.D3.Mesh.prototype.updateInstance.call(this, property); GameLib.D3.Mesh.prototype.updateInstance.call(this, property);
@ -159,22 +128,22 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
*/ */
GameLib.D3.Mesh.Plane.prototype.toApiObject = function() { GameLib.D3.Mesh.Plane.prototype.toApiObject = function() {
var apiMesh = GameLib.D3.Mesh.prototype.toApiObject.call(this); var apiMeshPlane = new GameLib.D3.API.Mesh.Plane(
GameLib.D3.API.Mesh.prototype.toApiObject.call(this),
this.width,
this.height,
this.widthSegments,
this.heightSegments,
this.heightMapScale,
this.isHeightMap,
this.isDotMap,
this.dotObject
);
apiMesh.width = this.width; return apiMeshPlane;
apiMesh.height = this.height;
apiMesh.widthSegments = this.widthSegments;
apiMesh.heightSegments = this.heightSegments;
apiMesh.heightMapScale = this.heightMapScale;
apiMesh.isHeightMap = this.isHeightMap;
apiMesh.isClippingPlane = this.isClippingPlane;
apiMesh.distanceFromOrigin = this.distanceFromOrigin;
return apiMesh;
}; };
/** /**
* TODO fix all this weird loading shit
* Converts a standard object mesh to a GameLib.D3.Mesh * Converts a standard object mesh to a GameLib.D3.Mesh
* @param graphics GameLib.GraphicsRuntime * @param graphics GameLib.GraphicsRuntime
* @param objectMesh {Object} * @param objectMesh {Object}
@ -182,19 +151,11 @@ GameLib.D3.Mesh.Plane.prototype.toApiObject = function() {
*/ */
GameLib.D3.Mesh.Plane.FromObject = function(graphics, objectMesh) { GameLib.D3.Mesh.Plane.FromObject = function(graphics, objectMesh) {
var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh); var apiMeshPlane = GameLib.D3.API.Mesh.Plane.FromObject(objectMesh);
return new GameLib.D3.Mesh.Plane( return new GameLib.D3.Mesh.Plane(
graphics, graphics,
apiMesh, apiMeshPlane
objectMesh.width,
objectMesh.height,
objectMesh.widthSegments,
objectMesh.heightSegments,
objectMesh.heightMapScale,
objectMesh.isHeightMap,
objectMesh.isClippingPlane,
objectMesh.distanceFromOrigin
); );
}; };