diff options
| author | click <none@none> | 2010-06-05 00:59:25 +0200 |
|---|---|---|
| committer | click <none@none> | 2010-06-05 00:59:25 +0200 |
| commit | e77716188861d4aa83b227a90e04a66b63baeb1f (patch) | |
| tree | ce72764181a760314ec851f7535052dcf75649db /dep/src/g3dlite/MeshBuilder.cpp | |
| parent | 1426c2970f42a2d065198806f750bf5dd28d580b (diff) | |
HIGHLY EXPERIMENTAL - USE AT YOUR OWN RISK
Implement the use of the new vmap3-format by Lynx3d (mad props to you for this, and thanks for the talks earlier)
+ reduced Vmap size to less than one third, and improve precision
+ indoor/outdoor check which allows automatic unmounting of players
+ additional area information from WMOAreaTable.dbc, removed existing "hacks"
+ WMO liquid information for swimming and fishing correctly in buildings/cities/caves/instances (lava and slime WILL hurt from now on!)
- buildfiles for windows are not properly done, and will need to be sorted out
NOTE: Do NOT annoy Lynx3d about this, any issues with this "port" is entirely our fault !
THIS REVISION IS CONSIDERED UNSTABLE AND CONTAINS WORK IN PROGRESS - USE AT YOUR OWN RISK!
--HG--
branch : trunk
Diffstat (limited to 'dep/src/g3dlite/MeshBuilder.cpp')
| -rw-r--r-- | dep/src/g3dlite/MeshBuilder.cpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/dep/src/g3dlite/MeshBuilder.cpp b/dep/src/g3dlite/MeshBuilder.cpp new file mode 100644 index 00000000000..1bf2bab5d1c --- /dev/null +++ b/dep/src/g3dlite/MeshBuilder.cpp @@ -0,0 +1,113 @@ +/** + @file MeshBuilder.cpp + + @maintainer Morgan McGuire, http://graphics.cs.williams.edu + + @created 2002-02-27 + @edited 2005-02-24 + */ + +#include "G3D/MeshBuilder.h" +#include "G3D/MeshAlg.h" + +namespace G3D { + +void MeshBuilder::setName(const std::string& n) { + name = n; +} + + +void MeshBuilder::commit(std::string& n, Array<int>& indexArray, Array<Vector3>& outvertexArray) { + n = name; + + // Make the data fit in a unit cube + centerTriList(); + + Array<int> toNew, toOld; + + if (close == MeshBuilder::AUTO_WELD) { + Array<int> index; + MeshAlg::createIndexArray(triList.size(), index); + double minEdgeLen, maxEdgeLen, meanEdgeLen, medianEdgeLen; + double minFaceArea, maxFaceArea, meanFaceArea, medianFaceArea; + MeshAlg::computeAreaStatistics(triList, index, + minEdgeLen, meanEdgeLen, medianEdgeLen, maxEdgeLen, + minFaceArea, meanFaceArea, medianFaceArea, maxFaceArea); + close = minEdgeLen * 0.1; + } + + MeshAlg::computeWeld(triList, outvertexArray, toNew, toOld, close); + + // Construct triangles + for (int t = 0; t < triList.size(); t += 3) { + int index[3]; + + for (int i = 0; i < 3; ++i) { + index[i] = toNew[t + i]; + } + + // Throw out zero size triangles + if ((index[0] != index[1]) && + (index[1] != index[2]) && + (index[2] != index[0])) { + indexArray.append(index[0], index[1], index[2]); + } + } +} + + +void MeshBuilder::centerTriList() { + // Compute the range of the vertices + Vector3 vmin, vmax; + + computeBounds(vmin, vmax); + + Vector3 diagonal = vmax - vmin; + double scale = max(max(diagonal.x, diagonal.y), diagonal.z) / 2; + debugAssert(scale > 0); + + Vector3 translation = vmin + diagonal / 2; + + // Center and scale all vertices in the input list + int v; + + //Matrix3 rot90 = Matrix3::fromAxisAngle(Vector3::UNIT_Y, toRadians(180)) * Matrix3::fromAxisAngle(Vector3::UNIT_X, toRadians(90)); + for (v = 0; v < triList.size(); ++v) { + triList[v] = (triList[v] - translation) / scale; + //triList[v] = rot90 * triList[v]; + } +} + + +void MeshBuilder::computeBounds(Vector3& min, Vector3& max) { + min = Vector3::inf(); + max = -min; + + int v; + for (v = 0; v < triList.size(); ++v) { + min = min.min(triList[v]); + max = max.max(triList[v]); + } +} + + +void MeshBuilder::addTriangle(const Vector3& a, const Vector3& b, const Vector3& c) { + triList.append(a, b, c); + + if (_twoSided) { + triList.append(c, b, a); + } +} + + +void MeshBuilder::addQuad(const Vector3& a, const Vector3& b, const Vector3& c, const Vector3& d) { + addTriangle(a, b, c); + addTriangle(a, c, d); +} + + +void MeshBuilder::addTriangle(const Triangle& t) { + addTriangle(t.vertex(0), t.vertex(1), t.vertex(2)); +} + +} // namespace |
