just before introducing geometry base
parent
c0d8a4e8c6
commit
123b89cf26
|
@ -38,6 +38,31 @@ GameLib.Utils.BuildVectorSource = function(result, name, dimension) {
|
||||||
console.warn('unknown dimension : ' + dimension);
|
console.warn('unknown dimension : ' + dimension);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all 'instances' of the array, or null if an 'instance' is undefined
|
||||||
|
* @constructor
|
||||||
|
* @param array
|
||||||
|
*/
|
||||||
|
GameLib.Utils.GetArrayInstances = function(array) {
|
||||||
|
return array.reduce(
|
||||||
|
function(result, object) {
|
||||||
|
|
||||||
|
if (result === null) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(object.instance)) {
|
||||||
|
result = null;
|
||||||
|
} else {
|
||||||
|
result.push(object.instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
GameLib.Utils.SortFacesByMaterialIndex = function(faces) {
|
GameLib.Utils.SortFacesByMaterialIndex = function(faces) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,252 @@
|
||||||
|
/**
|
||||||
|
* GameLib.D3.API.GeometryBase
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
|
* @param geometryType
|
||||||
|
* @param parentEntity
|
||||||
|
* @param boundingBox
|
||||||
|
* @param boundingSphere
|
||||||
|
* @param faces
|
||||||
|
* @param vertices
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.GeometryBase = function(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
geometryType,
|
||||||
|
parentEntity,
|
||||||
|
boundingBox,
|
||||||
|
boundingSphere,
|
||||||
|
faces,
|
||||||
|
vertices
|
||||||
|
) {
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(geometryType)) {
|
||||||
|
geometryType = GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_BASE;
|
||||||
|
}
|
||||||
|
this.geometryType = geometryType;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
|
||||||
|
switch (this.geometryType) {
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_NORMAL :
|
||||||
|
name = 'Geometry';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_BOX :
|
||||||
|
name = 'Geometry Box';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_CIRCLE :
|
||||||
|
name = 'Geometry Circle';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_CONE :
|
||||||
|
name = 'Geometry Cone';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_CYLINDER :
|
||||||
|
name = 'Geometry Cylinder';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_DODECAHEDRON :
|
||||||
|
name = 'Geometry Dodecahedron';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_EDGES :
|
||||||
|
name = 'Geometry Edges';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_EXTRUDE :
|
||||||
|
name = 'Geometry Extrude';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_ICOSAHEDRON :
|
||||||
|
name = 'Geometry Icosahedron';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_LATHE :
|
||||||
|
name = 'Geometry Lathe';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_OCTAHEDRON :
|
||||||
|
name = 'Geometry Octahedron';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_PARAMETRIC :
|
||||||
|
name = 'Geometry Parametric';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_PLANE :
|
||||||
|
name = 'Geometry Plane';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_POLYHEDRON :
|
||||||
|
name = 'Geometry Polyhedron';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_RING :
|
||||||
|
name = 'Geometry Ring';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_SHAPE :
|
||||||
|
name = 'Geometry Shape';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_SPHERE :
|
||||||
|
name = 'Geometry Sphere';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TETRAHEDRON :
|
||||||
|
name = 'Geometry Tetrahedron';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TEXT :
|
||||||
|
name = 'Geometry Text';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TORUS :
|
||||||
|
name = 'Geometry Torus';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TORUS_KNOT :
|
||||||
|
name = 'Geometry Torus Knot';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TUBE :
|
||||||
|
name = 'Geometry Tube';
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_WIREFRAME :
|
||||||
|
name = 'Geometry Wireframe';
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
console.warn('no nice name for geometry');
|
||||||
|
name = 'Geometry';
|
||||||
|
}
|
||||||
|
|
||||||
|
name += ' (' + id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(boundingBox)) {
|
||||||
|
boundingBox = new GameLib.API.Box3();
|
||||||
|
}
|
||||||
|
this.boundingBox = boundingBox;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(boundingSphere)) {
|
||||||
|
boundingSphere = new GameLib.API.Sphere();
|
||||||
|
}
|
||||||
|
this.boundingSphere = boundingSphere;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(faces)) {
|
||||||
|
faces = [];
|
||||||
|
}
|
||||||
|
this.faces = faces;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(vertices)) {
|
||||||
|
vertices = [];
|
||||||
|
}
|
||||||
|
this.vertices = vertices;
|
||||||
|
|
||||||
|
GameLib.API.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.D3.API.Geometry.GetComponentType(this.geometryType),
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.API.GeometryBase.prototype = Object.create(GameLib.API.Component.prototype);
|
||||||
|
GameLib.D3.API.GeometryBase.prototype.constructor = GameLib.D3.API.GeometryBase;
|
||||||
|
|
||||||
|
GameLib.D3.API.GeometryBase.GetComponentType = function(geometryType) {
|
||||||
|
|
||||||
|
var componentType = null;
|
||||||
|
|
||||||
|
switch (geometryType) {
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_NORMAL :
|
||||||
|
componentType = GameLib.Component.GEOMETRY;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_BOX :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_BOX;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_CIRCLE :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_CIRCLE;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_CONE :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_CONE;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_CYLINDER :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_CYLINDER;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_DODECAHEDRON :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_DODECAHEDRON;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_EDGES :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_EDGES;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_EXTRUDE :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_EXTRUDE;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_ICOSAHEDRON :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_ICOSAHEDRON;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_LATHE :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_LATHE;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_OCTAHEDRON :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_OCTAHEDRON;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_PARAMETRIC :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_PARAMETRIC;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_PLANE :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_PLANE;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_POLYHEDRON :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_POLYHEDRON;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_RING :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_RING;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_SHAPE :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_SHAPE;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_SPHERE :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_SPHERE;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TETRAHEDRON :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_TETRAHEDRON;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TEXT :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_TEXT;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TORUS :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_TORUS;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TORUS_KNOT :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_TORUS_KNOT;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TUBE :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_TUBE;
|
||||||
|
break;
|
||||||
|
case GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_WIREFRAME :
|
||||||
|
componentType = GameLib.Component.GEOMETRY_WIREFRAME;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error('unhandled geometry type: ' + geometryType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return componentType;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GeometryBase Type
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_BASE = 0x0;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_NORMAL = 0x1;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_BOX = 0x2;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_CIRCLE = 0x3;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_CONE = 0x4;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_CYLINDER = 0x5;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_DODECAHEDRON = 0x6;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_EDGES = 0x7;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_EXTRUDE = 0x8;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_ICOSAHEDRON = 0x9;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_LATHE = 0xa;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_OCTAHEDRON = 0xb;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_PARAMETRIC = 0xc;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_PLANE = 0xd;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_POLYHEDRON = 0xe;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_RING = 0xf;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_SHAPE = 0x10;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_SPHERE = 0x11;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TETRAHEDRON = 0x12;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TEXT = 0x13;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TORUS = 0x14;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TORUS_KNOT = 0x15;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_TUBE = 0x16;
|
||||||
|
GameLib.D3.API.GeometryBase.GEOMETRY_TYPE_WIREFRAME = 0x17;
|
|
@ -4,10 +4,11 @@
|
||||||
* @param name
|
* @param name
|
||||||
* @param meshType
|
* @param meshType
|
||||||
* @param parentEntity
|
* @param parentEntity
|
||||||
* @param excludeFromEnvironment
|
* @param geometry
|
||||||
* @param materials
|
* @param materials
|
||||||
* @param parentMesh
|
* @param parentMesh
|
||||||
* @param parentScene
|
* @param parentScene
|
||||||
|
* @param excludeFromEnvironment
|
||||||
* @param skeleton
|
* @param skeleton
|
||||||
* @param position
|
* @param position
|
||||||
* @param quaternion
|
* @param quaternion
|
||||||
|
@ -19,6 +20,9 @@
|
||||||
* @param visible
|
* @param visible
|
||||||
* @param castShadow
|
* @param castShadow
|
||||||
* @param receiveShadow
|
* @param receiveShadow
|
||||||
|
* @param drawMode
|
||||||
|
* @param morphTargetInfluences
|
||||||
|
* @param morphTargetDictionary
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Mesh = function(
|
GameLib.D3.API.Mesh = function(
|
||||||
|
@ -26,10 +30,11 @@ GameLib.D3.API.Mesh = function(
|
||||||
name,
|
name,
|
||||||
meshType,
|
meshType,
|
||||||
parentEntity,
|
parentEntity,
|
||||||
excludeFromEnvironment,
|
geometry,
|
||||||
materials,
|
materials,
|
||||||
parentMesh,
|
parentMesh,
|
||||||
parentScene,
|
parentScene,
|
||||||
|
excludeFromEnvironment,
|
||||||
skeleton,
|
skeleton,
|
||||||
position,
|
position,
|
||||||
quaternion,
|
quaternion,
|
||||||
|
@ -40,7 +45,10 @@ GameLib.D3.API.Mesh = function(
|
||||||
useQuaternion,
|
useQuaternion,
|
||||||
visible,
|
visible,
|
||||||
castShadow,
|
castShadow,
|
||||||
receiveShadow
|
receiveShadow,
|
||||||
|
drawMode,
|
||||||
|
morphTargetInfluences,
|
||||||
|
morphTargetDictionary
|
||||||
) {
|
) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.Utils.RandomId();
|
id = GameLib.Utils.RandomId();
|
||||||
|
@ -88,20 +96,17 @@ GameLib.D3.API.Mesh = function(
|
||||||
}
|
}
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(excludeFromEnvironment)) {
|
if (GameLib.Utils.UndefinedOrNull(geometry)) {
|
||||||
excludeFromEnvironment = false;
|
geometry = null;
|
||||||
}
|
}
|
||||||
this.excludeFromEnvironment = excludeFromEnvironment;
|
this.geometry = geometry;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(vertices)) {
|
if (GameLib.Utils.UndefinedOrNull(materials)) {
|
||||||
vertices = [];
|
materials = [
|
||||||
|
new GameLib.D3.API.Material.Phong()
|
||||||
|
];
|
||||||
}
|
}
|
||||||
this.vertices = vertices;
|
this.materials = materials;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(faces)) {
|
|
||||||
faces = [];
|
|
||||||
}
|
|
||||||
this.faces = faces;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(parentMesh)) {
|
if (GameLib.Utils.UndefinedOrNull(parentMesh)) {
|
||||||
parentMesh = null;
|
parentMesh = null;
|
||||||
|
@ -113,28 +118,16 @@ GameLib.D3.API.Mesh = function(
|
||||||
}
|
}
|
||||||
this.parentScene = parentScene;
|
this.parentScene = parentScene;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(excludeFromEnvironment)) {
|
||||||
|
excludeFromEnvironment = false;
|
||||||
|
}
|
||||||
|
this.excludeFromEnvironment = excludeFromEnvironment;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(skeleton)) {
|
if (GameLib.Utils.UndefinedOrNull(skeleton)) {
|
||||||
skeleton = null;
|
skeleton = null;
|
||||||
}
|
}
|
||||||
this.skeleton = skeleton;
|
this.skeleton = skeleton;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(skinIndices)) {
|
|
||||||
skinIndices = [];
|
|
||||||
}
|
|
||||||
this.skinIndices = skinIndices;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(skinWeights)) {
|
|
||||||
skinWeights = [];
|
|
||||||
}
|
|
||||||
this.skinWeights = skinWeights;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(materials) || (materials instanceof Array && materials.length === 0)) {
|
|
||||||
materials = [
|
|
||||||
new GameLib.D3.API.Material.Basic()
|
|
||||||
];
|
|
||||||
}
|
|
||||||
this.materials = materials;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(position)) {
|
if (GameLib.Utils.UndefinedOrNull(position)) {
|
||||||
position = new GameLib.API.Vector3(0,0,0);
|
position = new GameLib.API.Vector3(0,0,0);
|
||||||
}
|
}
|
||||||
|
@ -160,21 +153,11 @@ GameLib.D3.API.Mesh = function(
|
||||||
}
|
}
|
||||||
this.up = up;
|
this.up = up;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(modelMatrix)) {
|
|
||||||
modelMatrix = new GameLib.API.Matrix4();
|
|
||||||
}
|
|
||||||
this.modelMatrix = modelMatrix;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(renderOrder)) {
|
if (GameLib.Utils.UndefinedOrNull(renderOrder)) {
|
||||||
renderOrder = 0;
|
renderOrder = 0;
|
||||||
}
|
}
|
||||||
this.renderOrder = renderOrder;
|
this.renderOrder = renderOrder;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(isBufferMesh)) {
|
|
||||||
isBufferMesh = false;
|
|
||||||
}
|
|
||||||
this.isBufferMesh = isBufferMesh;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(useQuaternion)) {
|
if (GameLib.Utils.UndefinedOrNull(useQuaternion)) {
|
||||||
useQuaternion = true;
|
useQuaternion = true;
|
||||||
}
|
}
|
||||||
|
@ -195,6 +178,21 @@ GameLib.D3.API.Mesh = function(
|
||||||
}
|
}
|
||||||
this.receiveShadow = receiveShadow;
|
this.receiveShadow = receiveShadow;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(drawMode)) {
|
||||||
|
drawMode = GameLib.D3.API.Mesh.DRAW_MODE_TRIANGLES;
|
||||||
|
}
|
||||||
|
this.drawMode = drawMode;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(morphTargetInfluences)) {
|
||||||
|
morphTargetInfluences = [];
|
||||||
|
}
|
||||||
|
this.morphTargetInfluences = morphTargetInfluences;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(morphTargetDictionary)) {
|
||||||
|
morphTargetDictionary = null;
|
||||||
|
}
|
||||||
|
this.morphTargetDictionary = morphTargetDictionary;
|
||||||
|
|
||||||
var componentType = GameLib.Component.MESH;
|
var componentType = GameLib.Component.MESH;
|
||||||
|
|
||||||
if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_PLANE) {
|
if (this.meshType === GameLib.D3.API.Mesh.MESH_TYPE_PLANE) {
|
||||||
|
@ -245,3 +243,11 @@ GameLib.D3.API.Mesh.MESH_TYPE_BOX = 0x5;
|
||||||
GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER = 0x6;
|
GameLib.D3.API.Mesh.MESH_TYPE_CYLINDER = 0x6;
|
||||||
GameLib.D3.API.Mesh.MESH_TYPE_TEXT = 0x7;
|
GameLib.D3.API.Mesh.MESH_TYPE_TEXT = 0x7;
|
||||||
GameLib.D3.API.Mesh.MESH_TYPE_LINE = 0x8;
|
GameLib.D3.API.Mesh.MESH_TYPE_LINE = 0x8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw Modes
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
GameLib.D3.API.Mesh.DRAW_MODE_TRIANGLES = 0;
|
||||||
|
GameLib.D3.API.Mesh.DRAW_MODE_TRIANGLE_STRIP = 1;
|
||||||
|
GameLib.D3.API.Mesh.DRAW_MODE_TRIANGLE_FAN = 2;
|
||||||
|
|
|
@ -80,6 +80,16 @@ GameLib.D3.BufferGeometry.prototype.constructor = GameLib.D3.BufferGeometry;
|
||||||
|
|
||||||
GameLib.D3.BufferGeometry.prototype.createInstance = function() {
|
GameLib.D3.BufferGeometry.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
if (GameLib.Utils.Defined(this.instance)) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We already have our object - just call our parent and return
|
||||||
|
*/
|
||||||
|
GameLib.Component.prototype.createInstance.call(this);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Then we convert to the new BufferGeometry type
|
* Then we convert to the new BufferGeometry type
|
||||||
*/
|
*/
|
||||||
|
@ -229,12 +239,14 @@ GameLib.D3.BufferGeometry.prototype.createInstance = function() {
|
||||||
|
|
||||||
groupIndexCounts.reduce(
|
groupIndexCounts.reduce(
|
||||||
function(start, group) {
|
function(start, group) {
|
||||||
geometry.addGroup(start, group.count, group.index);
|
this.instance.addGroup(start, group.count, group.index);
|
||||||
return start + group.count;
|
return start + group.count;
|
||||||
},
|
}.bind(this),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
GameLib.Component.prototype.createInstance.call(this);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.BufferGeometry.prototype.updateInstance = function(property) {
|
GameLib.D3.BufferGeometry.prototype.updateInstance = function(property) {
|
||||||
|
@ -346,3 +358,137 @@ GameLib.D3.BufferGeometry.prototype.toApiObject = function() {
|
||||||
return apiBufferGeometry;
|
return apiBufferGeometry;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update GameLib.D3.BufferGeometry from instance
|
||||||
|
*/
|
||||||
|
GameLib.D3.BufferGeometry.prototype.updateFromInstance = function() {
|
||||||
|
|
||||||
|
var vertices = this.instance.getAttribute('position').array;
|
||||||
|
|
||||||
|
var uvs = this.instance.getAttribute('uv').array;
|
||||||
|
|
||||||
|
this.instance.groups.map(function(group){
|
||||||
|
|
||||||
|
var materialIndex = group.materialIndex;
|
||||||
|
|
||||||
|
var start = group.start;
|
||||||
|
|
||||||
|
var count = group.count;
|
||||||
|
|
||||||
|
var faceIndexes = [];
|
||||||
|
|
||||||
|
var indexedUvs = [];
|
||||||
|
|
||||||
|
for (var i = start; i < count; i ++) {
|
||||||
|
|
||||||
|
var vertex = new GameLib.D3.Vertex(
|
||||||
|
this.graphics,
|
||||||
|
new GameLib.D3.API.Vertex(
|
||||||
|
new GameLib.Vector3(
|
||||||
|
this.graphics,
|
||||||
|
new GameLib.API.Vector3(
|
||||||
|
vertices[i*3],
|
||||||
|
vertices[i*3 + 1],
|
||||||
|
vertices[i*3 + 2]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
var uv = new GameLib.Vector2(
|
||||||
|
this.graphics,
|
||||||
|
new GameLib.API.Vector2(
|
||||||
|
uvs[i*2],
|
||||||
|
uvs[i*2 + 1]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
indexedUvs.push(uv);
|
||||||
|
|
||||||
|
var vertexIndex = this.vertices.reduce(
|
||||||
|
function(result, indexedVertex, currentIndex){
|
||||||
|
if (indexedVertex.position.equals(vertex.position)) {
|
||||||
|
result = currentIndex;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
-1
|
||||||
|
);
|
||||||
|
|
||||||
|
var faceIndex = vertexIndex;
|
||||||
|
|
||||||
|
if (vertexIndex === -1) {
|
||||||
|
this.vertices.push(vertex);
|
||||||
|
faceIndex = this.vertices.length - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
faceIndexes.push(faceIndex);
|
||||||
|
|
||||||
|
if (faceIndexes.length === 3) {
|
||||||
|
|
||||||
|
this.faces.push(
|
||||||
|
new GameLib.D3.Face(
|
||||||
|
this.graphics,
|
||||||
|
new GameLib.D3.API.Face(
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
faceIndexes[0],
|
||||||
|
faceIndexes[1],
|
||||||
|
faceIndexes[2],
|
||||||
|
materialIndex,
|
||||||
|
[[indexedUvs[0], indexedUvs[1], indexedUvs[2]]]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
indexedUvs = [];
|
||||||
|
faceIndexes = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all groups
|
||||||
|
*/
|
||||||
|
GameLib.D3.BufferGeometry.prototype.clearGroups = function() {
|
||||||
|
this.instance.clearGroups();
|
||||||
|
this.groups = this.instance.groups;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all groups
|
||||||
|
*/
|
||||||
|
GameLib.D3.BufferGeometry.prototype.singleMaterial = function() {
|
||||||
|
|
||||||
|
this.instance.clearGroups();
|
||||||
|
|
||||||
|
this.instance.addGroup(
|
||||||
|
0,
|
||||||
|
this.instance.index.count,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
this.groups = this.instance.groups;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute Vertex Normals
|
||||||
|
*/
|
||||||
|
GameLib.D3.BufferGeometry.prototype.computeVertexNormals = function() {
|
||||||
|
|
||||||
|
this.instance.computeVertexNormals();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute Vertex Normals
|
||||||
|
*/
|
||||||
|
GameLib.D3.BufferGeometry.prototype.toNonIndexed = function() {
|
||||||
|
|
||||||
|
this.instance.toNonIndexed();
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,103 @@
|
||||||
|
/**
|
||||||
|
* GameLib.D3.BufferGeometry.Box
|
||||||
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
|
* @param apiBoxBufferGeometry
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.D3.BufferGeometry.Box = function(
|
||||||
|
graphics,
|
||||||
|
apiBoxBufferGeometry
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.graphics = graphics;
|
||||||
|
this.graphics.isNotThreeThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiBoxBufferGeometry)) {
|
||||||
|
apiBoxBufferGeometry = {
|
||||||
|
bufferGeometryType : GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_BOX
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.API.BufferGeometry.Box.call(
|
||||||
|
this,
|
||||||
|
apiBoxBufferGeometry,
|
||||||
|
apiBoxBufferGeometry.width,
|
||||||
|
apiBoxBufferGeometry.height,
|
||||||
|
apiBoxBufferGeometry.depth,
|
||||||
|
apiBoxBufferGeometry.widthSegments,
|
||||||
|
apiBoxBufferGeometry.heightSegments,
|
||||||
|
apiBoxBufferGeometry.depthSegments
|
||||||
|
);
|
||||||
|
|
||||||
|
GameLib.D3.BufferGeometry.call(
|
||||||
|
this,
|
||||||
|
this.graphics,
|
||||||
|
apiBoxBufferGeometry
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.D3.BufferGeometry.Box.prototype = Object.create(GameLib.D3.BufferGeometry.prototype);
|
||||||
|
GameLib.D3.BufferGeometry.Box.prototype.constructor = GameLib.D3.BufferGeometry.Box;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a light instance
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
GameLib.D3.BufferGeometry.Box.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
this.instance = new THREE.BoxBufferGeometry(
|
||||||
|
this.width,
|
||||||
|
this.height,
|
||||||
|
this.depth,
|
||||||
|
this.widthSegments,
|
||||||
|
this.heightSegments,
|
||||||
|
this.depthSegments
|
||||||
|
);
|
||||||
|
|
||||||
|
GameLib.D3.BufferGeometry.prototype.createInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.D3.BufferGeometry.Box.prototype.updateInstance = function(property, oldTarget) {
|
||||||
|
|
||||||
|
if (
|
||||||
|
property === 'width' ||
|
||||||
|
property === 'height' ||
|
||||||
|
property === 'depth' ||
|
||||||
|
property === 'widthSegments' ||
|
||||||
|
property === 'heightSegments' ||
|
||||||
|
property === 'depthSegments'
|
||||||
|
) {
|
||||||
|
console.warn('todo: check if i can update this without creating a new instance');
|
||||||
|
//this.createInstance();
|
||||||
|
this.instance.width = this.width;
|
||||||
|
this.instance.attributes.position.needsUpdate = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.D3.BufferGeometry.prototype.updateInstance.call(this, property);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.D3.BufferGeometry to a GameLib.D3.API.BufferGeometry
|
||||||
|
* @returns {GameLib.D3.API.BufferGeometry}
|
||||||
|
*/
|
||||||
|
GameLib.D3.BufferGeometry.Box.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
var apiBufferGeometry = GameLib.D3.BufferGeometry.prototype.toApiObject.call(this);
|
||||||
|
|
||||||
|
var apiBoxBufferGeometry = new GameLib.D3.API.BufferGeometry.Box(
|
||||||
|
apiBufferGeometry,
|
||||||
|
this.width,
|
||||||
|
this.height,
|
||||||
|
this.depth,
|
||||||
|
this.widthSegments,
|
||||||
|
this.heightSegments,
|
||||||
|
this.depthSegments
|
||||||
|
);
|
||||||
|
|
||||||
|
return apiBoxBufferGeometry;
|
||||||
|
};
|
|
@ -456,3 +456,113 @@ GameLib.D3.Geometry.prototype.toApiObject = function() {
|
||||||
return apiGeometry;
|
return apiGeometry;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update GameLib.D3.Geometry from instance
|
||||||
|
*/
|
||||||
|
GameLib.D3.Geometry.prototype.updateFromInstance = function() {
|
||||||
|
|
||||||
|
var processed = 0;
|
||||||
|
|
||||||
|
this.instance.faces.map(function(face, faceIndex){
|
||||||
|
|
||||||
|
processed++;
|
||||||
|
|
||||||
|
if (processed % 100 === 0) {
|
||||||
|
console.log('processed ' + processed + ' faces');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.faces.push(
|
||||||
|
new GameLib.D3.Face(
|
||||||
|
this.graphics,
|
||||||
|
new GameLib.D3.API.Face(
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
face.a,
|
||||||
|
face.b,
|
||||||
|
face.c,
|
||||||
|
face.materialIndex,
|
||||||
|
[[
|
||||||
|
new GameLib.API.Vector2(
|
||||||
|
this.instance.faceVertexUvs[0][faceIndex][0].x,
|
||||||
|
this.instance.faceVertexUvs[0][faceIndex][0].y
|
||||||
|
),
|
||||||
|
new GameLib.API.Vector2(
|
||||||
|
this.instance.faceVertexUvs[0][faceIndex][1].x,
|
||||||
|
this.instance.faceVertexUvs[0][faceIndex][1].y
|
||||||
|
),
|
||||||
|
new GameLib.API.Vector2(
|
||||||
|
this.instance.faceVertexUvs[0][faceIndex][2].x,
|
||||||
|
this.instance.faceVertexUvs[0][faceIndex][2].y
|
||||||
|
)
|
||||||
|
]],
|
||||||
|
new GameLib.Color(
|
||||||
|
this.graphics,
|
||||||
|
new GameLib.API.Color(
|
||||||
|
face.color.r,
|
||||||
|
face.color.g,
|
||||||
|
face.color.b
|
||||||
|
)
|
||||||
|
),
|
||||||
|
face.vertexColors.map(function(vertexColor){
|
||||||
|
return new GameLib.Color(
|
||||||
|
this.graphics,
|
||||||
|
new GameLib.API.Color(
|
||||||
|
vertexColor.r,
|
||||||
|
vertexColor.g,
|
||||||
|
vertexColor.b
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}.bind(this)),
|
||||||
|
face.vertexNormals.map(function(vertexNormal){
|
||||||
|
return new GameLib.Vector3(
|
||||||
|
this.graphics,
|
||||||
|
new GameLib.API.Vector3(
|
||||||
|
vertexNormal.x,
|
||||||
|
vertexNormal.y,
|
||||||
|
vertexNormal.z
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}.bind(this)),
|
||||||
|
new GameLib.Vector3(
|
||||||
|
this.graphics,
|
||||||
|
new GameLib.API.Vector3(
|
||||||
|
face.normal.x,
|
||||||
|
face.normal.y,
|
||||||
|
face.normal.z
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
|
processed = 0;
|
||||||
|
|
||||||
|
this.instance.vertices.map(function(vertex){
|
||||||
|
|
||||||
|
processed++;
|
||||||
|
|
||||||
|
if (processed % 100 === 0) {
|
||||||
|
console.log('processed ' + processed + ' vertices');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.vertices.push(
|
||||||
|
new GameLib.D3.Vertex(
|
||||||
|
this.graphics,
|
||||||
|
new GameLib.D3.API.Vertex(
|
||||||
|
new GameLib.Vector3(
|
||||||
|
this.graphics,
|
||||||
|
new GameLib.API.Vector3(
|
||||||
|
vertex.x,
|
||||||
|
vertex.y,
|
||||||
|
vertex.z
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
|
};
|
|
@ -1,258 +0,0 @@
|
||||||
/**
|
|
||||||
* GameLib.D3.Geometry.Buffer
|
|
||||||
* @param graphics
|
|
||||||
* @param apiGeometry
|
|
||||||
* @property geometryType
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.D3.BufferGeometry = function(
|
|
||||||
graphics,
|
|
||||||
apiGeometry
|
|
||||||
) {
|
|
||||||
|
|
||||||
this.graphics = graphics;
|
|
||||||
this.graphics.isNotThreeThrow();
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(apiGeometry)) {
|
|
||||||
apiGeometry = {
|
|
||||||
geometryType : GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
GameLib.D3.Geometry.call(
|
|
||||||
this,
|
|
||||||
apiGeometry
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Geometry.Buffer.prototype = Object.create(GameLib.D3.Geometry.prototype);
|
|
||||||
GameLib.D3.Geometry.Buffer.prototype.constructor = GameLib.D3.Geometry.Buffer;
|
|
||||||
|
|
||||||
GameLib.D3.Geometry.Buffer.prototype.createInstance = function() {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* First we try it this way - we setup things the old-school way
|
|
||||||
*/
|
|
||||||
GameLib.D3.Geometry.prototype.createInstance.call(this);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Then we convert to the new BufferGeometry type
|
|
||||||
*/
|
|
||||||
this.instance = new THREE.BufferGeometry().fromGeometry(this.instance);
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Setup mesh vertices positions
|
|
||||||
// * @type {Float32Array}
|
|
||||||
// */
|
|
||||||
// var vertices = new Float32Array(
|
|
||||||
//
|
|
||||||
// this.faces.reduce(
|
|
||||||
// function(result, face){
|
|
||||||
// result.push(this.vertices[face.v0index].position.x);
|
|
||||||
// result.push(this.vertices[face.v0index].position.y);
|
|
||||||
// result.push(this.vertices[face.v0index].position.z);
|
|
||||||
// result.push(this.vertices[face.v1index].position.x);
|
|
||||||
// result.push(this.vertices[face.v1index].position.y);
|
|
||||||
// result.push(this.vertices[face.v1index].position.z);
|
|
||||||
// result.push(this.vertices[face.v2index].position.x);
|
|
||||||
// result.push(this.vertices[face.v2index].position.y);
|
|
||||||
// result.push(this.vertices[face.v2index].position.z);
|
|
||||||
// return result;
|
|
||||||
// }.bind(this),
|
|
||||||
// []
|
|
||||||
// )
|
|
||||||
//
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// this.instance.addAttribute('position', new THREE.BufferAttribute(vertices, 3));
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Setyp mesh vertices colors
|
|
||||||
// */
|
|
||||||
// var colors = new Float32Array(
|
|
||||||
// this.faces.reduce(
|
|
||||||
// function(result, face){
|
|
||||||
// result.push(1,1,1,1,1,1,1,1,1);
|
|
||||||
// // result.push(face.color.r);
|
|
||||||
// // result.push(face.color.g);
|
|
||||||
// // result.push(face.color.b);
|
|
||||||
// // result.push(face.color.r);
|
|
||||||
// // result.push(face.color.g);
|
|
||||||
// // result.push(face.color.b);
|
|
||||||
// // result.push(face.color.r);
|
|
||||||
// // result.push(face.color.g);
|
|
||||||
// // result.push(face.color.b);
|
|
||||||
// return result;
|
|
||||||
// }.bind(this),
|
|
||||||
// []
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3, true));
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Setup face UVs
|
|
||||||
// */
|
|
||||||
// var uvs = new Float32Array(
|
|
||||||
// this.faces.reduce(
|
|
||||||
// function(result, face) {
|
|
||||||
//
|
|
||||||
// face.uvs[0].map(
|
|
||||||
// function(uv) {
|
|
||||||
// result.push(uv.x);
|
|
||||||
// result.push(uv.y);
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// return result;
|
|
||||||
// },
|
|
||||||
// []
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// geometry.addAttribute('uv', new THREE.BufferAttribute(uvs, 2));
|
|
||||||
//
|
|
||||||
// var normals = new Float32Array(
|
|
||||||
// this.faces.reduce(
|
|
||||||
// function(result, face) {
|
|
||||||
//
|
|
||||||
// result.push(
|
|
||||||
// face.normal.x,
|
|
||||||
// face.normal.y,
|
|
||||||
// face.normal.z
|
|
||||||
// );
|
|
||||||
// result.push(
|
|
||||||
// face.normal.x,
|
|
||||||
// face.normal.y,
|
|
||||||
// face.normal.z
|
|
||||||
// );
|
|
||||||
// result.push(
|
|
||||||
// face.normal.x,
|
|
||||||
// face.normal.y,
|
|
||||||
// face.normal.z
|
|
||||||
// );
|
|
||||||
// return result;
|
|
||||||
// },
|
|
||||||
// []
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// geometry.addAttribute('normal', new THREE.BufferAttribute( normals, 3 ));
|
|
||||||
//
|
|
||||||
// geometry.computeVertexNormals();
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Setup material groups - this means creating a new group for each material index change
|
|
||||||
// * We know faces are sorted according to material index
|
|
||||||
// */
|
|
||||||
// var groupIndexCounts = this.faces.reduce(
|
|
||||||
// function(result, face) {
|
|
||||||
//
|
|
||||||
// var currentGroup = result.pop();
|
|
||||||
//
|
|
||||||
// if (currentGroup.index !== face.materialIndex) {
|
|
||||||
// /**
|
|
||||||
// * We have a new group
|
|
||||||
// */
|
|
||||||
// result.push(currentGroup);
|
|
||||||
// result.push({
|
|
||||||
// index: face.materialIndex,
|
|
||||||
// count: 3
|
|
||||||
// })
|
|
||||||
// } else {
|
|
||||||
// currentGroup.count += 3;
|
|
||||||
// result.push(currentGroup);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return result;
|
|
||||||
// },
|
|
||||||
// [
|
|
||||||
// {
|
|
||||||
// index : 0,
|
|
||||||
// count : 0
|
|
||||||
// }
|
|
||||||
// ]
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// groupIndexCounts.reduce(
|
|
||||||
// function(start, group) {
|
|
||||||
// geometry.addGroup(start, group.count, group.index);
|
|
||||||
// return start + group.count;
|
|
||||||
// },
|
|
||||||
// 0
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// } else {
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Geometry.Buffer.prototype.updateInstance = function(property) {
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
|
||||||
console.warn('no geometry instance');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GameLib.D3.Geometry.prototype.updateInstance.call(this, property);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a GameLib.D3.Geometry to a GameLib.D3.API.Geometry
|
|
||||||
* @returns {GameLib.D3.API.Geometry}
|
|
||||||
*/
|
|
||||||
GameLib.D3.Geometry.Buffer.prototype.toApiObject = function() {
|
|
||||||
|
|
||||||
var apiGeometry = new GameLib.D3.API.Geometry(
|
|
||||||
this.id,
|
|
||||||
this.name,
|
|
||||||
this.geometryType,
|
|
||||||
this.isBufferGeometry,
|
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity),
|
|
||||||
this.boundingBox.toApiObject(),
|
|
||||||
this.boundingSphere.toApiObject(),
|
|
||||||
this.colors.map(
|
|
||||||
function(color) {
|
|
||||||
return color.toApiObject();
|
|
||||||
}
|
|
||||||
),
|
|
||||||
this.faces.map(
|
|
||||||
function(face) {
|
|
||||||
return face.toApiObject();
|
|
||||||
}
|
|
||||||
),
|
|
||||||
this.lineDistances,
|
|
||||||
this.morphTargets,
|
|
||||||
this.morphNormals,
|
|
||||||
this.skinWeights.map(
|
|
||||||
function(skinWeight) {
|
|
||||||
return skinWeight.toApiObject();
|
|
||||||
}
|
|
||||||
),
|
|
||||||
this.skinIndices.map(
|
|
||||||
function(skinIndex) {
|
|
||||||
return skinIndex.toApiObject();
|
|
||||||
}
|
|
||||||
),
|
|
||||||
this.vertices.map(
|
|
||||||
function (vertex) {
|
|
||||||
return vertex.toApiObject();
|
|
||||||
}
|
|
||||||
),
|
|
||||||
this.verticesNeedsUpdate,
|
|
||||||
this.elementsNeedUpdate,
|
|
||||||
this.uvsNeedUpdate,
|
|
||||||
this.normalsNeedUpdate,
|
|
||||||
this.colorsNeedUpdate,
|
|
||||||
this.groupsNeedUpdate,
|
|
||||||
this.lineDistancesNeedUpdate
|
|
||||||
);
|
|
||||||
|
|
||||||
return apiGeometry;
|
|
||||||
|
|
||||||
};
|
|
|
@ -2,6 +2,7 @@
|
||||||
* GameLib.D3.Mesh
|
* GameLib.D3.Mesh
|
||||||
* @param graphics GameLib.GraphicsRuntime
|
* @param graphics GameLib.GraphicsRuntime
|
||||||
* @param apiMesh GameLib.D3.API.Mesh
|
* @param apiMesh GameLib.D3.API.Mesh
|
||||||
|
* @property geometry
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Mesh = function (
|
GameLib.D3.Mesh = function (
|
||||||
|
@ -22,51 +23,42 @@ GameLib.D3.Mesh = function (
|
||||||
apiMesh.id,
|
apiMesh.id,
|
||||||
apiMesh.name,
|
apiMesh.name,
|
||||||
apiMesh.meshType,
|
apiMesh.meshType,
|
||||||
apiMesh.excludeFromEnvironment,
|
apiMesh.parentEntity,
|
||||||
apiMesh.vertices,
|
apiMesh.geometry,
|
||||||
apiMesh.faces,
|
|
||||||
apiMesh.materials,
|
apiMesh.materials,
|
||||||
apiMesh.parentMesh,
|
apiMesh.parentMesh,
|
||||||
apiMesh.parentScene,
|
apiMesh.parentScene,
|
||||||
|
apiMesh.excludeFromEnvironment,
|
||||||
apiMesh.skeleton,
|
apiMesh.skeleton,
|
||||||
apiMesh.skinIndices,
|
|
||||||
apiMesh.skinWeights,
|
|
||||||
apiMesh.position,
|
apiMesh.position,
|
||||||
apiMesh.quaternion,
|
apiMesh.quaternion,
|
||||||
apiMesh.rotation,
|
apiMesh.rotation,
|
||||||
apiMesh.scale,
|
apiMesh.scale,
|
||||||
apiMesh.up,
|
apiMesh.up,
|
||||||
apiMesh.modelMatrix,
|
|
||||||
apiMesh.renderOrder,
|
apiMesh.renderOrder,
|
||||||
apiMesh.isBufferMesh,
|
|
||||||
apiMesh.useQuaternion,
|
apiMesh.useQuaternion,
|
||||||
apiMesh.visible,
|
apiMesh.visible,
|
||||||
apiMesh.castShadow,
|
apiMesh.castShadow,
|
||||||
apiMesh.receiveShadow,
|
apiMesh.receiveShadow,
|
||||||
apiMesh.parentEntity
|
apiMesh.drawMode,
|
||||||
|
apiMesh.morphTargetInfluences,
|
||||||
|
apiMesh.morphTargetDictionary
|
||||||
);
|
);
|
||||||
|
|
||||||
this.faces = this.faces.map(
|
if (
|
||||||
function(face) {
|
GameLib.Utils.Defined(this.geometry) &&
|
||||||
return new GameLib.D3.Face(
|
GameLib.Utils.Defined(this.geometry.componentType)
|
||||||
this.graphics,
|
) {
|
||||||
face
|
this.geometry = GameLib.Component.ConstructFromObject(this.geometry);
|
||||||
)
|
}
|
||||||
}.bind(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.materials = this.materials.map(
|
this.materials = this.materials.map(
|
||||||
function(material) {
|
function(material) {
|
||||||
|
|
||||||
if (typeof material === 'string') {
|
if (GameLib.Utils.Defined(material.componentType)) {
|
||||||
return material;
|
return GameLib.Component.ConstructFromObject(material);
|
||||||
}
|
|
||||||
|
|
||||||
var info = GameLib.Component.GetComponentInfo(material.componentType);
|
|
||||||
if (material instanceof info.apiConstructor) {
|
|
||||||
return new info.constructor(this.graphics, material);
|
|
||||||
} else {
|
} else {
|
||||||
console.warn('unhandled component type');
|
return material;
|
||||||
}
|
}
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
|
@ -79,15 +71,6 @@ GameLib.D3.Mesh = function (
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.vertices = this.vertices.map(
|
|
||||||
function (vertex) {
|
|
||||||
return new GameLib.D3.Vertex(
|
|
||||||
this.graphics,
|
|
||||||
vertex
|
|
||||||
);
|
|
||||||
}.bind(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
this.position,
|
this.position,
|
||||||
|
@ -118,22 +101,11 @@ GameLib.D3.Mesh = function (
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.modelMatrix = new GameLib.Matrix4(
|
|
||||||
this.graphics,
|
|
||||||
this.modelMatrix,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
|
|
||||||
this.dimensions = new GameLib.Vector3(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.API.Vector3(),
|
|
||||||
this
|
|
||||||
);
|
|
||||||
|
|
||||||
var linkedObjects = {
|
var linkedObjects = {
|
||||||
'parentMesh' : GameLib.D3.Mesh,
|
'parentMesh' : GameLib.D3.Mesh,
|
||||||
'parentScene' : GameLib.D3.Scene,
|
'parentScene' : GameLib.D3.Scene,
|
||||||
'materials' : [GameLib.D3.Material],
|
'materials' : [GameLib.D3.Material],
|
||||||
|
'geometry' : GameLib.D3.BufferGeometry,
|
||||||
'skeleton' : GameLib.D3.Skeleton
|
'skeleton' : GameLib.D3.Skeleton
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -162,92 +134,65 @@ GameLib.D3.Mesh = function (
|
||||||
GameLib.D3.Mesh.prototype = Object.create(GameLib.Component.prototype);
|
GameLib.D3.Mesh.prototype = Object.create(GameLib.Component.prototype);
|
||||||
GameLib.D3.Mesh.prototype.constructor = GameLib.D3.Mesh;
|
GameLib.D3.Mesh.prototype.constructor = GameLib.D3.Mesh;
|
||||||
|
|
||||||
GameLib.D3.Mesh.prototype.lookAt = function(vector) {
|
|
||||||
|
|
||||||
this.instance.lookAt(
|
|
||||||
new THREE.Vector3(
|
|
||||||
vector.x,
|
|
||||||
vector.y,
|
|
||||||
vector.z
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.rotation.x = this.instance.rotation.x;
|
|
||||||
this.rotation.y = this.instance.rotation.y;
|
|
||||||
this.rotation.z = this.instance.rotation.z;
|
|
||||||
|
|
||||||
this.quaternion.x = this.instance.quaternion.x;
|
|
||||||
this.quaternion.y = this.instance.quaternion.y;
|
|
||||||
this.quaternion.z = this.instance.quaternion.z;
|
|
||||||
this.quaternion.w = this.instance.quaternion.w;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Mesh.prototype.createInstanceGeometry = function(instanceGeometry) {
|
|
||||||
|
|
||||||
if (instanceGeometry instanceof THREE.Geometry) {
|
|
||||||
|
|
||||||
if (this.isBufferMesh) {
|
|
||||||
return new THREE.BufferGeometry().fromGeometry(instanceGeometry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return geometry;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a mesh instance or updates it
|
* Creates a mesh instance or updates it
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Mesh.prototype.createInstance = function() {
|
GameLib.D3.Mesh.prototype.createInstance = function() {
|
||||||
|
|
||||||
var geometry = this.createInstanceGeometry();
|
if (
|
||||||
|
GameLib.Utils.UndefinedOrNull(this.geometry) ||
|
||||||
|
GameLib.Utils.UndefinedOrNull(this.geometry.instance)
|
||||||
|
) {
|
||||||
|
console.warn('geometry not ready for this mesh ' + this.name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.skeleton) {
|
var materialInstances = GameLib.Utils.GetArrayInstances(this.materials);
|
||||||
|
|
||||||
if (this.materials.length === 1) {
|
if (
|
||||||
this.instance = new THREE.SkinnedMesh(
|
GameLib.Utils.UndefinedOrNull(materialInstances)
|
||||||
geometry,
|
) {
|
||||||
this.materials[0].instance
|
console.warn('materials not ready for this mesh ' + this.name);
|
||||||
)
|
return;
|
||||||
} else {
|
}
|
||||||
this.instance = new THREE.SkinnedMesh(
|
|
||||||
geometry,
|
if (this.skeleton) {
|
||||||
this.materials.map(
|
|
||||||
function(material) {
|
this.instance = new THREE.SkinnedMesh(
|
||||||
return material.instance;
|
this.geometry.instance,
|
||||||
}
|
materialInstances
|
||||||
)
|
);
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.instance.add(this.skeleton.rootBoneInstance);
|
this.instance.add(this.skeleton.rootBoneInstance);
|
||||||
this.instance.bind(this.skeleton.instance);
|
this.instance.bind(this.skeleton.instance);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (this.materials.length === 1) {
|
this.instance = new THREE.Mesh(
|
||||||
this.instance = new THREE.Mesh(
|
this.geometry.instance,
|
||||||
geometry,
|
materialInstances
|
||||||
this.materials[0].instance
|
);
|
||||||
)
|
}
|
||||||
} else {
|
|
||||||
this.instance = new THREE.Mesh(
|
|
||||||
geometry,
|
|
||||||
this.materials.map(
|
|
||||||
function(material) {
|
|
||||||
return material.instance;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.instance.name = this.name;
|
this.instance.name = this.name;
|
||||||
|
|
||||||
if (this.parentMesh && this.parentMesh.instance) {
|
if (GameLib.Utils.Defined(this.parentMesh)) {
|
||||||
this.parentMesh.add(this.instance, this);
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(this.parentMesh.instance)) {
|
||||||
|
console.warn('parent mesh not linked at time of create instance');
|
||||||
|
} else {
|
||||||
|
this.parentMesh.add(this.instance, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.Defined(this.parentScene)) {
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(this.parentScene.instance)) {
|
||||||
|
console.warn('parent scene not linked at time of create instance');
|
||||||
|
} else {
|
||||||
|
this.parentScene.add(this.instance, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.instance.position.x = this.position.x;
|
this.instance.position.x = this.position.x;
|
||||||
|
@ -289,6 +234,16 @@ GameLib.D3.Mesh.prototype.createInstance = function() {
|
||||||
|
|
||||||
this.instance.receiveShadow = this.receiveShadow;
|
this.instance.receiveShadow = this.receiveShadow;
|
||||||
|
|
||||||
|
this.instance.drawMode = this.drawMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rest we update from the instance
|
||||||
|
*/
|
||||||
|
this.morphTargetInfluences = this.instance.morphTargetInfluences;
|
||||||
|
this.morphTargetDictionary = this.instance.morphTargetDictionary;
|
||||||
|
|
||||||
|
console.log('mesh instance created: ' + this.name);
|
||||||
|
|
||||||
GameLib.Component.prototype.createInstance.call(this);
|
GameLib.Component.prototype.createInstance.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -301,6 +256,72 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
|
||||||
console.warn('unknown mesh property update');
|
console.warn('unknown mesh property update');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (property === 'geometry') {
|
||||||
|
|
||||||
|
if (GameLib.Utils.Defined(this.geometry)) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(this.geometry.instance)) {
|
||||||
|
console.warn('the geometry is not linked or constructed properly');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
||||||
|
this.createInstance();
|
||||||
|
} else {
|
||||||
|
this.instance.geometry = this.geometry.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'materials') {
|
||||||
|
|
||||||
|
var materialInstances = GameLib.Utils.GetArrayInstances(this.materials);
|
||||||
|
|
||||||
|
if (materialInstances) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
||||||
|
this.createInstance();
|
||||||
|
} else {
|
||||||
|
this.instance.material = materialInstances;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.warn('materials not ready for this mesh ' + this.name);
|
||||||
|
return;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
||||||
|
/**
|
||||||
|
* Do nothing
|
||||||
|
*/
|
||||||
|
} else {
|
||||||
|
|
||||||
|
console.warn('warning - assigning no material to this mesh instance');
|
||||||
|
/**
|
||||||
|
* Assign no material to this mesh - ok - I guess you know what you are doing.
|
||||||
|
* @type {null}
|
||||||
|
*/
|
||||||
|
this.instance.material = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(this.instance)) {
|
||||||
|
console.warn('mesh instance not ready - needs a material and geometry');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'name') {
|
||||||
|
this.instance.name = this.name;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (property === 'excludeFromEnvironment') {
|
if (property === 'excludeFromEnvironment') {
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.EXCLUDE_FROM_ENVIRONMENT,
|
GameLib.Event.EXCLUDE_FROM_ENVIRONMENT,
|
||||||
|
@ -310,23 +331,17 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'isBufferMesh') {
|
|
||||||
if (( this.isBufferMesh && !(this.instance.geometry instanceof THREE.BufferGeometry)) ||
|
|
||||||
( !this.isBufferMesh && (this.instance.geometry instanceof THREE.BufferGeometry)))
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The buffer geometry needs updating
|
|
||||||
*/
|
|
||||||
this.instance.geometry = this.createInstanceGeometry(this.instance.geometry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
property === 'rotation' ||
|
property === 'rotation' ||
|
||||||
property === 'quaternion' ||
|
property === 'quaternion' ||
|
||||||
property === 'useQuaternion'
|
property === 'useQuaternion'
|
||||||
) {
|
) {
|
||||||
this.updateInstanceRotation();
|
this.updateInstanceRotation();
|
||||||
|
if (this.helper) {
|
||||||
|
this.removeHelper();
|
||||||
|
this.createHelper();
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'parentMesh') {
|
if (property === 'parentMesh') {
|
||||||
|
@ -335,14 +350,29 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
|
||||||
this.instance.parent = this.parentMesh.instance;
|
this.instance.parent = this.parentMesh.instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.helper) {
|
||||||
|
this.removeHelper();
|
||||||
|
this.createHelper();
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'scale') {
|
if (property === 'scale') {
|
||||||
this.updateInstanceScale();
|
this.updateInstanceScale();
|
||||||
|
if (this.helper) {
|
||||||
|
this.removeHelper();
|
||||||
|
this.createHelper();
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'position') {
|
if (property === 'position') {
|
||||||
this.updateInstancePosition();
|
this.updateInstancePosition();
|
||||||
|
if (this.helper) {
|
||||||
|
this.removeHelper();
|
||||||
|
this.createHelper();
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'up') {
|
if (property === 'up') {
|
||||||
|
@ -352,30 +382,6 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property === 'name') {
|
|
||||||
this.instance.name = this.name;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property === 'materials') {
|
|
||||||
if (this.materials.length === 1 && this.materials[0].instance) {
|
|
||||||
this.instance.material = this.materials[0].instance;
|
|
||||||
} else {
|
|
||||||
|
|
||||||
var materialInstances = this.materials.map(
|
|
||||||
function(material) {
|
|
||||||
|
|
||||||
var materialInstance = material.instance;
|
|
||||||
|
|
||||||
return materialInstance;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.instance.material = materialInstances;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property === 'renderOrder') {
|
if (property === 'renderOrder') {
|
||||||
this.instance.renderOrder = this.renderOrder;
|
this.instance.renderOrder = this.renderOrder;
|
||||||
return;
|
return;
|
||||||
|
@ -396,10 +402,10 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.helper) {
|
if (property === 'drawMode') {
|
||||||
this.removeHelper();
|
this.instance.drawMode = this.drawMode;
|
||||||
this.createHelper();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 'parentScene' is handled by LinkingSystem
|
* 'parentScene' is handled by LinkingSystem
|
||||||
|
@ -407,6 +413,28 @@ GameLib.D3.Mesh.prototype.updateInstance = function(property) {
|
||||||
GameLib.Component.prototype.updateInstance.call(this, property);
|
GameLib.Component.prototype.updateInstance.call(this, property);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
GameLib.D3.Mesh.prototype.lookAt = function(vector) {
|
||||||
|
|
||||||
|
this.instance.lookAt(
|
||||||
|
new THREE.Vector3(
|
||||||
|
vector.x,
|
||||||
|
vector.y,
|
||||||
|
vector.z
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.rotation.x = this.instance.rotation.x;
|
||||||
|
this.rotation.y = this.instance.rotation.y;
|
||||||
|
this.rotation.z = this.instance.rotation.z;
|
||||||
|
|
||||||
|
this.quaternion.x = this.instance.quaternion.x;
|
||||||
|
this.quaternion.y = this.instance.quaternion.y;
|
||||||
|
this.quaternion.z = this.instance.quaternion.z;
|
||||||
|
this.quaternion.w = this.instance.quaternion.w;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
GameLib.D3.Mesh.prototype.invertWindingOrder = function() {
|
GameLib.D3.Mesh.prototype.invertWindingOrder = function() {
|
||||||
|
|
||||||
this.faces.forEach(
|
this.faces.forEach(
|
||||||
|
@ -431,216 +459,6 @@ GameLib.D3.Mesh.prototype.invertWindingOrder = function() {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply geometry data to our GameLib object from the geometry instance (reverse of applyVertexData)
|
|
||||||
* @param geometryInstance
|
|
||||||
*/
|
|
||||||
GameLib.D3.Mesh.prototype.updateVerticesFromGeometryInstance = function(geometryInstance) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setup vertices
|
|
||||||
*/
|
|
||||||
this.vertices = [];
|
|
||||||
|
|
||||||
this.faces = [];
|
|
||||||
|
|
||||||
if (geometryInstance instanceof THREE.BufferGeometry) {
|
|
||||||
|
|
||||||
var vertices = geometryInstance.getAttribute('position').array;
|
|
||||||
|
|
||||||
var uvs = geometryInstance.getAttribute('uv').array;
|
|
||||||
|
|
||||||
geometryInstance.groups.map(function(group){
|
|
||||||
|
|
||||||
var materialIndex = group.materialIndex;
|
|
||||||
|
|
||||||
var start = group.start;
|
|
||||||
|
|
||||||
var count = group.count;
|
|
||||||
|
|
||||||
var faceIndexes = [];
|
|
||||||
|
|
||||||
var indexedUvs = [];
|
|
||||||
|
|
||||||
for (var i = start; i < count; i ++) {
|
|
||||||
|
|
||||||
var vertex = new GameLib.D3.Vertex(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.D3.API.Vertex(
|
|
||||||
new GameLib.Vector3(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
vertices[i*3],
|
|
||||||
vertices[i*3 + 1],
|
|
||||||
vertices[i*3 + 2]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
var uv = new GameLib.Vector2(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.API.Vector2(
|
|
||||||
uvs[i*2],
|
|
||||||
uvs[i*2 + 1]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
indexedUvs.push(uv);
|
|
||||||
|
|
||||||
var vertexIndex = this.vertices.reduce(
|
|
||||||
function(result, indexedVertex, currentIndex){
|
|
||||||
if (indexedVertex.position.equals(vertex.position)) {
|
|
||||||
result = currentIndex;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
-1
|
|
||||||
);
|
|
||||||
|
|
||||||
var faceIndex = vertexIndex;
|
|
||||||
|
|
||||||
if (vertexIndex === -1) {
|
|
||||||
this.vertices.push(vertex);
|
|
||||||
faceIndex = this.vertices.length - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
faceIndexes.push(faceIndex);
|
|
||||||
|
|
||||||
if (faceIndexes.length === 3) {
|
|
||||||
|
|
||||||
this.faces.push(
|
|
||||||
new GameLib.D3.Face(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.D3.API.Face(
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
faceIndexes[0],
|
|
||||||
faceIndexes[1],
|
|
||||||
faceIndexes[2],
|
|
||||||
materialIndex,
|
|
||||||
[[indexedUvs[0], indexedUvs[1], indexedUvs[2]]]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
indexedUvs = [];
|
|
||||||
faceIndexes = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
console.log('todo : update vertices from buffer geometry');
|
|
||||||
} else {
|
|
||||||
|
|
||||||
var processed = 0;
|
|
||||||
|
|
||||||
geometryInstance.faces.map(function(face, faceIndex){
|
|
||||||
|
|
||||||
processed++;
|
|
||||||
|
|
||||||
if (processed % 100 === 0) {
|
|
||||||
console.log('processed ' + processed + ' faces');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.faces.push(
|
|
||||||
new GameLib.D3.Face(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.D3.API.Face(
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
face.a,
|
|
||||||
face.b,
|
|
||||||
face.c,
|
|
||||||
face.materialIndex,
|
|
||||||
[[
|
|
||||||
new GameLib.API.Vector2(
|
|
||||||
geometryInstance.faceVertexUvs[0][faceIndex][0].x,
|
|
||||||
geometryInstance.faceVertexUvs[0][faceIndex][0].y
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector2(
|
|
||||||
geometryInstance.faceVertexUvs[0][faceIndex][1].x,
|
|
||||||
geometryInstance.faceVertexUvs[0][faceIndex][1].y
|
|
||||||
),
|
|
||||||
new GameLib.API.Vector2(
|
|
||||||
geometryInstance.faceVertexUvs[0][faceIndex][2].x,
|
|
||||||
geometryInstance.faceVertexUvs[0][faceIndex][2].y
|
|
||||||
)
|
|
||||||
]],
|
|
||||||
new GameLib.Color(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.API.Color(
|
|
||||||
face.color.r,
|
|
||||||
face.color.g,
|
|
||||||
face.color.b
|
|
||||||
)
|
|
||||||
),
|
|
||||||
face.vertexColors.map(function(vertexColor){
|
|
||||||
return new GameLib.Color(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.API.Color(
|
|
||||||
vertexColor.r,
|
|
||||||
vertexColor.g,
|
|
||||||
vertexColor.b
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}.bind(this)),
|
|
||||||
face.vertexNormals.map(function(vertexNormal){
|
|
||||||
return new GameLib.Vector3(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
vertexNormal.x,
|
|
||||||
vertexNormal.y,
|
|
||||||
vertexNormal.z
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}.bind(this)),
|
|
||||||
new GameLib.Vector3(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
face.normal.x,
|
|
||||||
face.normal.y,
|
|
||||||
face.normal.z
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
processed = 0;
|
|
||||||
|
|
||||||
geometryInstance.vertices.map(function(vertex){
|
|
||||||
|
|
||||||
processed++;
|
|
||||||
|
|
||||||
if (processed % 100 === 0) {
|
|
||||||
console.log('processed ' + processed + ' vertices');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.vertices.push(
|
|
||||||
new GameLib.D3.Vertex(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.D3.API.Vertex(
|
|
||||||
new GameLib.Vector3(
|
|
||||||
this.graphics,
|
|
||||||
new GameLib.API.Vector3(
|
|
||||||
vertex.x,
|
|
||||||
vertex.y,
|
|
||||||
vertex.z
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}.bind(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.D3.Mesh.prototype.applyBones = function(geometry) {
|
GameLib.D3.Mesh.prototype.applyBones = function(geometry) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -812,40 +630,30 @@ GameLib.D3.Mesh.prototype.toApiObject = function() {
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
this.meshType,
|
this.meshType,
|
||||||
this.excludeFromEnvironment,
|
GameLib.Utils.IdOrNull(this.parentEntity),
|
||||||
this.vertices.map(
|
GameLib.Utils.IdOrNull(this.geometry),
|
||||||
function (vertex) {
|
|
||||||
return vertex.toApiObject();
|
|
||||||
}
|
|
||||||
),
|
|
||||||
this.faces.map(
|
|
||||||
function(face){
|
|
||||||
return face.toApiObject();
|
|
||||||
}
|
|
||||||
),
|
|
||||||
this.materials.map(
|
this.materials.map(
|
||||||
function(material) {
|
function(material) {
|
||||||
return GameLib.Utils.IdOrNull(material);
|
return GameLib.Utils.IdOrNull(material)
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
GameLib.Utils.IdOrNull(this.parentMesh),
|
GameLib.Utils.IdOrNull(this.parentMesh),
|
||||||
GameLib.Utils.IdOrNull(this.parentScene),
|
GameLib.Utils.IdOrNull(this.parentScene),
|
||||||
|
this.excludeFromEnvironment,
|
||||||
GameLib.Utils.IdOrNull(this.skeleton),
|
GameLib.Utils.IdOrNull(this.skeleton),
|
||||||
this.skinIndices,
|
|
||||||
this.skinWeights,
|
|
||||||
this.position.toApiObject(),
|
this.position.toApiObject(),
|
||||||
this.quaternion.toApiObject(),
|
this.quaternion.toApiObject(),
|
||||||
this.rotation.toApiObject(),
|
this.rotation.toApiObject(),
|
||||||
this.scale.toApiObject(),
|
this.scale.toApiObject(),
|
||||||
this.up.toApiObject(),
|
this.up.toApiObject(),
|
||||||
this.modelMatrix.toApiObject(),
|
|
||||||
this.renderOrder,
|
this.renderOrder,
|
||||||
this.isBufferMesh,
|
|
||||||
this.useQuaternion,
|
this.useQuaternion,
|
||||||
this.visible,
|
this.visible,
|
||||||
this.castShadow,
|
this.castShadow,
|
||||||
this.receiveShadow,
|
this.receiveShadow,
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
this.drawMode
|
||||||
|
// this.morphTargetInfluences,
|
||||||
|
// this.morphTargetDictionary
|
||||||
);
|
);
|
||||||
|
|
||||||
return apiMesh;
|
return apiMesh;
|
||||||
|
@ -1101,6 +909,19 @@ GameLib.D3.Mesh.prototype.getChildrenComponents = function() {
|
||||||
|
|
||||||
var components = [];
|
var components = [];
|
||||||
|
|
||||||
|
this.buildIdToObject();
|
||||||
|
|
||||||
|
Object.keys(this.idToObject).map(
|
||||||
|
function(objectId) {
|
||||||
|
if (this.id !== objectId) {
|
||||||
|
components.push(this.idToObject[objectId]);
|
||||||
|
}
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
|
return components;
|
||||||
|
/*
|
||||||
|
|
||||||
this.materials.map(
|
this.materials.map(
|
||||||
function (material) {
|
function (material) {
|
||||||
|
|
||||||
|
@ -1142,11 +963,11 @@ GameLib.D3.Mesh.prototype.getChildrenComponents = function() {
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
/**
|
/**
|
||||||
* Push RigidBodies
|
* Push RigidBodies
|
||||||
*/
|
*/
|
||||||
var rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RIGID_BODY);
|
/* var rigidBodies = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.RIGID_BODY);
|
||||||
rigidBodies.map(
|
rigidBodies.map(
|
||||||
function(rigidBody) {
|
function(rigidBody) {
|
||||||
|
|
||||||
|
@ -1156,11 +977,11 @@ GameLib.D3.Mesh.prototype.getChildrenComponents = function() {
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
/**
|
/**
|
||||||
* Push Shapes
|
* Push Shapes
|
||||||
*/
|
*/
|
||||||
var shapes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SHAPE);
|
/* var shapes = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SHAPE);
|
||||||
shapes.map(
|
shapes.map(
|
||||||
function(shape) {
|
function(shape) {
|
||||||
|
|
||||||
|
@ -1170,8 +991,8 @@ GameLib.D3.Mesh.prototype.getChildrenComponents = function() {
|
||||||
|
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
return components;
|
// return components;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -181,7 +181,7 @@ GameLib.D3.Raycaster.prototype.getIntersectedObjects = function(meshes) {
|
||||||
{
|
{
|
||||||
mesh: mesh,
|
mesh: mesh,
|
||||||
distance : intersects[0].distance,
|
distance : intersects[0].distance,
|
||||||
face: mesh.faces[intersects[0].faceIndex],
|
face: mesh.geometry.faces[intersects[0].faceIndex],
|
||||||
faceIndex: intersects[0].faceIndex
|
faceIndex: intersects[0].faceIndex
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -988,6 +988,18 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
} else if (property === 'drawMode') {
|
||||||
|
controllers.push(
|
||||||
|
folder.add(
|
||||||
|
object,
|
||||||
|
property,
|
||||||
|
{
|
||||||
|
'triangles' : GameLib.D3.API.Mesh.DRAW_MODE_TRIANGLES,
|
||||||
|
'triangle strip' : GameLib.D3.API.Mesh.DRAW_MODE_TRIANGLE_STRIP,
|
||||||
|
'triangle fan' : GameLib.D3.API.Mesh.DRAW_MODE_TRIANGLE_FAN
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
} else if (property === 'shadowType') {
|
} else if (property === 'shadowType') {
|
||||||
controllers.push(
|
controllers.push(
|
||||||
folder.add(
|
folder.add(
|
||||||
|
|
Loading…
Reference in New Issue