Revert "Add transformation for mesh objects."
This reverts commit d75ff6464c.
This commit is contained in:
parent
d75ff6464c
commit
79cd5189dc
@ -73,6 +73,22 @@ OV.ImporterO3dv = class extends OV.ImporterBase
|
|||||||
genParams.SetMaterial (meshContent.material);
|
genParams.SetMaterial (meshContent.material);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (meshContent.transformation !== undefined) {
|
||||||
|
let translation = new OV.Coord3D (0.0, 0.0, 0.0);
|
||||||
|
let rotation = new OV.Quaternion (0.0, 0.0, 0.0, 1.0);
|
||||||
|
let scale = new OV.Coord3D (1.0, 1.0, 1.0);
|
||||||
|
if (meshContent.transformation.translation !== undefined) {
|
||||||
|
translation = OV.ArrayToCoord3D (meshContent.transformation.translation);
|
||||||
|
}
|
||||||
|
if (meshContent.transformation.rotation !== undefined) {
|
||||||
|
rotation = OV.ArrayToQuaternion (meshContent.transformation.rotation);
|
||||||
|
}
|
||||||
|
if (meshContent.transformation.scale !== undefined) {
|
||||||
|
scale = OV.ArrayToCoord3D (meshContent.transformation.scale);
|
||||||
|
}
|
||||||
|
genParams.SetTransformation (translation, rotation, scale);
|
||||||
|
}
|
||||||
|
|
||||||
let parameters = meshContent.parameters;
|
let parameters = meshContent.parameters;
|
||||||
if (parameters === undefined) {
|
if (parameters === undefined) {
|
||||||
return;
|
return;
|
||||||
@ -105,30 +121,10 @@ OV.ImporterO3dv = class extends OV.ImporterBase
|
|||||||
let radius = OV.ValueOrDefault (parameters.radius, 1.0);
|
let radius = OV.ValueOrDefault (parameters.radius, 1.0);
|
||||||
mesh = OV.GeneratePlatonicSolid (genParams, parameters.solid_type, radius);
|
mesh = OV.GeneratePlatonicSolid (genParams, parameters.solid_type, radius);
|
||||||
}
|
}
|
||||||
|
if (mesh !== null) {
|
||||||
if (mesh === null) {
|
this.ImportProperties (mesh, meshContent);
|
||||||
return;
|
this.model.AddMesh (mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meshContent.transformation !== undefined) {
|
|
||||||
let translation = new OV.Coord3D (0.0, 0.0, 0.0);
|
|
||||||
let rotation = new OV.Quaternion (0.0, 0.0, 0.0, 1.0);
|
|
||||||
let scale = new OV.Coord3D (1.0, 1.0, 1.0);
|
|
||||||
if (meshContent.transformation.translation !== undefined) {
|
|
||||||
translation = OV.ArrayToCoord3D (meshContent.transformation.translation);
|
|
||||||
}
|
|
||||||
if (meshContent.transformation.rotation !== undefined) {
|
|
||||||
rotation = OV.ArrayToQuaternion (meshContent.transformation.rotation);
|
|
||||||
}
|
|
||||||
if (meshContent.transformation.scale !== undefined) {
|
|
||||||
scale = OV.ArrayToCoord3D (meshContent.transformation.scale);
|
|
||||||
}
|
|
||||||
let matrix = new OV.Matrix ().ComposeTRS (translation, rotation, scale);
|
|
||||||
mesh.SetTransformation (new OV.Transformation (matrix));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.ImportProperties (mesh, meshContent);
|
|
||||||
this.model.AddMesh (mesh);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImportNode (nodeContent, meshNode)
|
ImportNode (nodeContent, meshNode)
|
||||||
|
|||||||
@ -7,7 +7,6 @@ OV.Mesh = class extends OV.ModelObject3D
|
|||||||
this.normals = [];
|
this.normals = [];
|
||||||
this.uvs = [];
|
this.uvs = [];
|
||||||
this.triangles = [];
|
this.triangles = [];
|
||||||
this.transformation = new OV.Transformation ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexCount ()
|
VertexCount ()
|
||||||
@ -89,27 +88,10 @@ OV.Mesh = class extends OV.ModelObject3D
|
|||||||
return this.triangles[index];
|
return this.triangles[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
SetTransformation (transformation)
|
|
||||||
{
|
|
||||||
this.transformation = transformation;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetTransformation ()
|
|
||||||
{
|
|
||||||
return this.transformation;
|
|
||||||
}
|
|
||||||
|
|
||||||
EnumerateVertices (onVertex)
|
EnumerateVertices (onVertex)
|
||||||
{
|
{
|
||||||
if (this.transformation.IsIdentity ()) {
|
for (const vertex of this.vertices) {
|
||||||
for (const vertex of this.vertices) {
|
onVertex (vertex);
|
||||||
onVertex (vertex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (const vertex of this.vertices) {
|
|
||||||
const transformed = this.transformation.TransformCoord3D (vertex);
|
|
||||||
onVertex (transformed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,20 +104,11 @@ OV.Mesh = class extends OV.ModelObject3D
|
|||||||
|
|
||||||
EnumerateTriangleVertices (onTriangleVertices)
|
EnumerateTriangleVertices (onTriangleVertices)
|
||||||
{
|
{
|
||||||
if (this.transformation.IsIdentity ()) {
|
for (const triangle of this.triangles) {
|
||||||
for (const triangle of this.triangles) {
|
let v0 = this.vertices[triangle.v0];
|
||||||
let v0 = this.vertices[triangle.v0];
|
let v1 = this.vertices[triangle.v1];
|
||||||
let v1 = this.vertices[triangle.v1];
|
let v2 = this.vertices[triangle.v2];
|
||||||
let v2 = this.vertices[triangle.v2];
|
onTriangleVertices (v0, v1, v2);
|
||||||
onTriangleVertices (v0, v1, v2);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (const triangle of this.triangles) {
|
|
||||||
const v0Transformed = this.transformation.TransformCoord3D (this.vertices[triangle.v0]);
|
|
||||||
const v1Transformed = this.transformation.TransformCoord3D (this.vertices[triangle.v1]);
|
|
||||||
const v2Transformed = this.transformation.TransformCoord3D (this.vertices[triangle.v2]);
|
|
||||||
onTriangleVertices (v0Transformed, v1Transformed, v2Transformed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -272,10 +272,6 @@ OV.ConvertModelToThreeObject = function (model, params, output, callbacks)
|
|||||||
}
|
}
|
||||||
|
|
||||||
let threeMesh = new THREE.Mesh (threeGeometry, meshThreeMaterials);
|
let threeMesh = new THREE.Mesh (threeGeometry, meshThreeMaterials);
|
||||||
let matrix = mesh.GetTransformation ().GetMatrix ();
|
|
||||||
let threeMatrix = new THREE.Matrix4 ().fromArray (matrix.Get ());
|
|
||||||
threeMesh.applyMatrix4 (threeMatrix);
|
|
||||||
|
|
||||||
threeMesh.userData = {
|
threeMesh.userData = {
|
||||||
originalMeshId : meshInstanceId,
|
originalMeshId : meshInstanceId,
|
||||||
originalMaterials : meshOriginalMaterials,
|
originalMaterials : meshOriginalMaterials,
|
||||||
|
|||||||
@ -78,10 +78,6 @@ describe ('O3dv Importer', function () {
|
|||||||
assert.strictEqual (mesh.GetPropertyGroup (0).PropertyCount (), 5);
|
assert.strictEqual (mesh.GetPropertyGroup (0).PropertyCount (), 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
let boundingBox = OV.GetBoundingBox (model);
|
|
||||||
assert (OV.CoordIsEqual3D (boundingBox.min, new OV.Coord3D (-0.5773502691896258, -1.0, -1.0)));
|
|
||||||
assert (OV.CoordIsEqual3D (boundingBox.max, new OV.Coord3D (6.85065080835204, 1.0, 3.9341723589627158)));
|
|
||||||
|
|
||||||
done ();
|
done ();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -95,35 +95,4 @@ describe ('Mesh', function() {
|
|||||||
assert (OV.CoordIsEqual3D (mesh.GetVertex (2), new OV.Coord3D (0.0, 1.0, 3.0)));
|
assert (OV.CoordIsEqual3D (mesh.GetVertex (2), new OV.Coord3D (0.0, 1.0, 3.0)));
|
||||||
assert (OV.CoordIsEqual3D (mesh.GetNormal (0), new OV.Coord3D (-1.0, 0.0, 0.0)));
|
assert (OV.CoordIsEqual3D (mesh.GetNormal (0), new OV.Coord3D (-1.0, 0.0, 0.0)));
|
||||||
});
|
});
|
||||||
|
|
||||||
it ('Mesh Transformation', function () {
|
|
||||||
var mesh = new OV.Mesh ();
|
|
||||||
mesh.AddVertex (new OV.Coord3D (0.0, 0.0, 0.0));
|
|
||||||
mesh.AddVertex (new OV.Coord3D (1.0, 0.0, 0.0));
|
|
||||||
mesh.AddVertex (new OV.Coord3D (1.0, 1.0, 0.0));
|
|
||||||
mesh.AddNormal (new OV.Coord3D (0.0, 0.0, 1.0));
|
|
||||||
mesh.AddTextureUV (new OV.Coord2D (0.0, 0.0));
|
|
||||||
mesh.AddTextureUV (new OV.Coord2D (1.0, 0.0));
|
|
||||||
mesh.AddTextureUV (new OV.Coord2D (1.0, 1.0));
|
|
||||||
var triangle = new OV.Triangle (0, 1, 2);
|
|
||||||
triangle.SetNormals (0, 0, 0);
|
|
||||||
triangle.SetTextureUVs (0, 1, 2);
|
|
||||||
mesh.AddTriangle (triangle);
|
|
||||||
|
|
||||||
let rotation = OV.QuaternionFromAxisAngle (new OV.Coord3D (0.0, 1.0, 0.0), -Math.PI / 2.0);
|
|
||||||
let transformation = new OV.Transformation ();
|
|
||||||
transformation.AppendMatrix (new OV.Matrix ().CreateScale (2.0, 1.0, 1.0));
|
|
||||||
transformation.AppendMatrix (new OV.Matrix ().CreateRotation (rotation.x, rotation.y, rotation.z, rotation.w));
|
|
||||||
transformation.AppendMatrix (new OV.Matrix ().CreateTranslation (0.0, 0.0, 1.0));
|
|
||||||
mesh.SetTransformation (transformation);
|
|
||||||
|
|
||||||
let transformedVertices = [];
|
|
||||||
mesh.EnumerateVertices ((vertex) => {
|
|
||||||
transformedVertices.push (vertex);
|
|
||||||
})
|
|
||||||
|
|
||||||
assert (OV.CoordIsEqual3D (transformedVertices[0], new OV.Coord3D (0.0, 0.0, 1.0)));
|
|
||||||
assert (OV.CoordIsEqual3D (transformedVertices[1], new OV.Coord3D (0.0, 0.0, 3.0)));
|
|
||||||
assert (OV.CoordIsEqual3D (transformedVertices[2], new OV.Coord3D (0.0, 1.0, 3.0)));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user