mesh plane streamline
parent
806abb380f
commit
5236d0965c
|
@ -9,7 +9,7 @@
|
|||
* @param heightMapScale
|
||||
* @param isHeightMap
|
||||
* @param isDotMap
|
||||
* @param distanceFromOrigin
|
||||
* @param dotObject
|
||||
*/
|
||||
GameLib.D3.API.Mesh.Plane = function(
|
||||
apiMesh,
|
||||
|
@ -20,18 +20,15 @@ GameLib.D3.API.Mesh.Plane = function(
|
|||
heightMapScale,
|
||||
isHeightMap,
|
||||
isDotMap,
|
||||
distanceFromOrigin
|
||||
dotObject
|
||||
) {
|
||||
|
||||
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)) {
|
||||
width = 1;
|
||||
}
|
||||
|
@ -43,12 +40,12 @@ GameLib.D3.API.Mesh.Plane = function(
|
|||
this.height = height;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(widthSegments)) {
|
||||
widthSegments = 1;
|
||||
widthSegments = 5;
|
||||
}
|
||||
this.widthSegments = widthSegments;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(heightSegments)) {
|
||||
heightSegments = 1
|
||||
heightSegments = 5;
|
||||
}
|
||||
this.heightSegments = heightSegments;
|
||||
|
||||
|
@ -67,14 +64,35 @@ GameLib.D3.API.Mesh.Plane = function(
|
|||
}
|
||||
this.isDotMap = isDotMap;
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(distanceFromOrigin)) {
|
||||
distanceFromOrigin = 0;
|
||||
if (GameLib.Utils.UndefinedOrNull(dotObject)) {
|
||||
dotObject = null;
|
||||
}
|
||||
this.distanceFromOrigin = distanceFromOrigin;
|
||||
this.dotObject = dotObject;
|
||||
|
||||
GameLib.API.Component.call(
|
||||
GameLib.D3.API.Mesh.call(
|
||||
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){
|
||||
|
||||
|
||||
var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh);
|
||||
|
||||
return new GameLib.D3.API.Mesh.Plane(
|
||||
apiMesh,
|
||||
GameLib.D3.API.Mesh.FromObject(objectMesh),
|
||||
objectMesh.width,
|
||||
objectMesh.height,
|
||||
objectMesh.widthSegments,
|
||||
|
@ -100,7 +115,7 @@ GameLib.D3.API.Mesh.Plane.FromObject = function (objectMesh){
|
|||
objectMesh.heightMapScale,
|
||||
objectMesh.isHeightMap,
|
||||
objectMesh.isDotMap,
|
||||
objectMesh.distanceFromOrigin
|
||||
GameLib.Utils.IdOrNull(objectMesh.dotObject)
|
||||
);
|
||||
|
||||
};
|
||||
|
|
|
@ -138,6 +138,10 @@ GameLib.D3.Mesh = function (
|
|||
'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) {
|
||||
linkedObjects.font = GameLib.D3.Font;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ GameLib.D3.Mesh.Plane = function (
|
|||
apiMeshPlane
|
||||
) {
|
||||
|
||||
|
||||
this.graphics = graphics;
|
||||
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(
|
||||
this,
|
||||
apiMeshPlane,
|
||||
|
@ -33,7 +28,7 @@ GameLib.D3.Mesh.Plane = function (
|
|||
apiMeshPlane.heightMapScale,
|
||||
apiMeshPlane.isHeightMap,
|
||||
apiMeshPlane.isDotMap,
|
||||
apiMeshPlane.distanceFromOrigin
|
||||
apiMeshPlane.dotObject
|
||||
);
|
||||
|
||||
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.constructor = GameLib.D3.Mesh.Plane;
|
||||
|
||||
|
||||
GameLib.D3.Mesh.Plane.prototype.createInstance = function() {
|
||||
|
||||
var geometry = null;
|
||||
|
@ -79,23 +73,8 @@ GameLib.D3.Mesh.Plane.prototype.createInstance = function() {
|
|||
*/
|
||||
GameLib.D3.Mesh.prototype.createInstance.call(this);
|
||||
|
||||
/**
|
||||
* Apply some plane specific data to the instance
|
||||
*/
|
||||
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
|
||||
);
|
||||
if (this.isDotMap && this.dotObject) {
|
||||
console.log('todo: construct dotmap here')
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -106,26 +85,16 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
|
|||
|
||||
var geometry = null;
|
||||
|
||||
if (
|
||||
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
|
||||
if (
|
||||
property === 'width' ||
|
||||
property === 'height' ||
|
||||
property === 'widthSegments' ||
|
||||
property === 'heightSegments' ||
|
||||
property === 'isHeightMap' ||
|
||||
property === 'heightMapScale'
|
||||
) {
|
||||
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.height,
|
||||
this.widthSegments,
|
||||
|
@ -135,19 +104,19 @@ GameLib.D3.Mesh.Plane.prototype.updateInstance = function(property) {
|
|||
this.updateVerticesFromGeometryInstance(geometry);
|
||||
|
||||
if (this.isHeightMap) {
|
||||
this.generateHeightMapFromBumpMap();
|
||||
}
|
||||
this.generateHeightMapFromBumpMap();
|
||||
}
|
||||
|
||||
geometry = this.createInstanceGeometry();
|
||||
geometry = this.createInstanceGeometry();
|
||||
|
||||
this.instance.geometry = geometry;
|
||||
}
|
||||
|
||||
if (this.isClippingPlane) {
|
||||
this.instance.clipping = new THREE.Plane(
|
||||
geometry.faces[0].normal,
|
||||
this.distanceFromOrigin
|
||||
)
|
||||
}
|
||||
if (
|
||||
property === 'isDotMap' ||
|
||||
property === 'dotObject'
|
||||
) {
|
||||
console.log('todo: implement dotmap');
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
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;
|
||||
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;
|
||||
return apiMeshPlane;
|
||||
};
|
||||
|
||||
/**
|
||||
* TODO fix all this weird loading shit
|
||||
* Converts a standard object mesh to a GameLib.D3.Mesh
|
||||
* @param graphics GameLib.GraphicsRuntime
|
||||
* @param objectMesh {Object}
|
||||
|
@ -182,19 +151,11 @@ GameLib.D3.Mesh.Plane.prototype.toApiObject = function() {
|
|||
*/
|
||||
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(
|
||||
graphics,
|
||||
apiMesh,
|
||||
objectMesh.width,
|
||||
objectMesh.height,
|
||||
objectMesh.widthSegments,
|
||||
objectMesh.heightSegments,
|
||||
objectMesh.heightMapScale,
|
||||
objectMesh.isHeightMap,
|
||||
objectMesh.isClippingPlane,
|
||||
objectMesh.distanceFromOrigin
|
||||
apiMeshPlane
|
||||
);
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue