107 lines
2.8 KiB
JavaScript
107 lines
2.8 KiB
JavaScript
|
/**
|
||
|
* R3.D3.API.Geometry
|
||
|
* @param apiComponent
|
||
|
*
|
||
|
* @property boundingBox
|
||
|
* @property boundingSphere
|
||
|
* @property indexed
|
||
|
* @property vertices
|
||
|
* @property faces
|
||
|
*
|
||
|
* @constructor
|
||
|
*/
|
||
|
R3.D3.API.Geometry = function(
|
||
|
apiComponent
|
||
|
) {
|
||
|
|
||
|
__API_COMPONENT__;
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(apiComponent.boundingBox)) {
|
||
|
apiComponent.boundingBox = new R3.API.Box3(
|
||
|
{
|
||
|
parent : this
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
this.boundingBox = apiComponent.boundingBox;
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(apiComponent.boundingSphere)) {
|
||
|
apiComponent.boundingSphere = new R3.API.Sphere(
|
||
|
{
|
||
|
parent : this
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
this.boundingSphere = apiComponent.boundingSphere;
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(apiComponent.indexed)) {
|
||
|
apiComponent.indexed = false;
|
||
|
}
|
||
|
this.indexed = apiComponent.indexed;
|
||
|
|
||
|
/**
|
||
|
* We need to initialize the vertices before we initialize the faces, so we can pass vertex information to the
|
||
|
* face and calculate the face normal if required
|
||
|
*/
|
||
|
if (R3.Utils.UndefinedOrNull(apiComponent.vertices)) {
|
||
|
apiComponent.vertices = [
|
||
|
new R3.API.Vertex(
|
||
|
{
|
||
|
parent : this,
|
||
|
register : true
|
||
|
}
|
||
|
),
|
||
|
new R3.API.Vertex(
|
||
|
{
|
||
|
parent : this,
|
||
|
register : true
|
||
|
}
|
||
|
),
|
||
|
new R3.API.Vertex(
|
||
|
{
|
||
|
parent : this,
|
||
|
register : true
|
||
|
}
|
||
|
)
|
||
|
];
|
||
|
}
|
||
|
this.vertices = apiComponent.vertices;
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(apiComponent.faces)) {
|
||
|
apiComponent.faces = [
|
||
|
new R3.D3.API.Face.Graphics(
|
||
|
{
|
||
|
parent : this,
|
||
|
register : true,
|
||
|
vertexIndices : [
|
||
|
0,
|
||
|
1,
|
||
|
2
|
||
|
],
|
||
|
vertices : [
|
||
|
this.vertices[0],
|
||
|
this.vertices[1],
|
||
|
this.vertices[2]
|
||
|
]
|
||
|
}
|
||
|
)
|
||
|
];
|
||
|
}
|
||
|
this.faces = apiComponent.faces;
|
||
|
|
||
|
this.faces = R3.Utils.SortFacesByMaterialIndex(this.faces);
|
||
|
|
||
|
|
||
|
};
|
||
|
|
||
|
R3.D3.API.Geometry.prototype = Object.create(R3.API.Component.prototype);
|
||
|
R3.D3.API.Geometry.prototype.constructor = R3.D3.API.Geometry;
|
||
|
|
||
|
R3.D3.API.Geometry.prototype.updateNormals = function() {
|
||
|
throw new Error('Override R3.D3.API.Geometry.prototype.updateNormals in child class');
|
||
|
};
|
||
|
|
||
|
R3.D3.API.Geometry.prototype.updatePositions = function() {
|
||
|
throw new Error('Override R3.D3.API.Geometry.prototype.updateNormals in child class');
|
||
|
};
|