summaryrefslogtreecommitdiffstats
path: root/o3d/collada_edge
diff options
context:
space:
mode:
authorapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 19:56:24 +0000
committerapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-12 19:56:24 +0000
commitccf02ac9bd67d4d49ad8264ae7fc6098e361ff4b (patch)
treefc6e4a0552431c7297798fad46f57fb76c35a3b3 /o3d/collada_edge
parentdfe9d1d2de7fd8d244599b79a22898cce8df7c81 (diff)
downloadchromium_src-ccf02ac9bd67d4d49ad8264ae7fc6098e361ff4b.zip
chromium_src-ccf02ac9bd67d4d49ad8264ae7fc6098e361ff4b.tar.gz
chromium_src-ccf02ac9bd67d4d49ad8264ae7fc6098e361ff4b.tar.bz2
Made all line endings consistently LF and added svn:eol-style=LF property to files with these names / extensions.
c cc h mm txt idl py js html css gyp gypi xml shader json htm README DEPS git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31811 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/collada_edge')
-rw-r--r--o3d/collada_edge/cross/collada_edge.cpp174
-rw-r--r--o3d/collada_edge/cross/conditioner.cpp738
-rw-r--r--o3d/collada_edge/cross/conditioner.h238
-rw-r--r--o3d/collada_edge/cross/precompile.h104
-rw-r--r--o3d/collada_edge/cross/utility.h86
5 files changed, 670 insertions, 670 deletions
diff --git a/o3d/collada_edge/cross/collada_edge.cpp b/o3d/collada_edge/cross/collada_edge.cpp
index d989476..81bb477 100644
--- a/o3d/collada_edge/cross/collada_edge.cpp
+++ b/o3d/collada_edge/cross/collada_edge.cpp
@@ -1,87 +1,87 @@
-/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-// collada_edge.cpp : Defines the entry point for the console application.
-#include "precompile.h"
-#include "conditioner.h"
-#include <cstdio>
-
-static const char *usage =
-"\nUsage: ColladaEdgeConditioner <infile.dae> <outifle.dae> [ options ]\n\n\
-Options:\n\
- -sharpEdgeThreshold t : sharp edge threshold defined by dihedral \n\
- angle. Edges with a angle smaller than t\n\
- will be defined as a sharp edge.\n\
- -sharpEdgeColor r,g,b : color of addtional edges.\n\
- default value is 1,0,0 .(no space)\n\n\
-ColladaEdgeConditioner checks all polygon edges in <infile.dae> and add\n\
-addtional edges to the model if normal angle of certain edge is larger\n\
-than the pre-defined threshold.\n";
-
-int wmain(int argc, wchar_t **argv) {
- wchar_t* input_file = NULL;
- wchar_t* output_file = NULL;
- Options options;
-
- if (argc < 3) {
- printf("%s", usage);
- return -1;
- }
- int file_count = 0;
- for (int i = 1; i < argc; i++) {
- if (wcscmp(argv[i], L"-sharpEdgeThreshold") == 0) {
- if (++i < argc) {
- options.enable_soften_edge = true;
- options.soften_edge_threshold = static_cast<float>(_wtof(argv[i]));
- }
- } else if (wcscmp(argv[i], L"-sharpEdgeColor") == 0) {
- if (++i < argc) {
- int r, g, b;
- if (swscanf_s(argv[i], L"%d,%d,%d", &r, &g, &b) != 3) {
- printf("Invalid -sharpEdgeColor. Should be -sharpEdgeColor=x,y,z\n");
- return -1;
- }
- options.sharp_edge_color = Vector3(static_cast<float>(r),
- static_cast<float>(g),
- static_cast<float>(b));
- }
- } else if (file_count < 2) {
- ++file_count;
- if (file_count == 1)
- input_file = argv[i];
- else
- output_file = argv[i];
- }
- }
-
- bool result = Condition(input_file, output_file, options);
- return 0;
-}
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// collada_edge.cpp : Defines the entry point for the console application.
+#include "precompile.h"
+#include "conditioner.h"
+#include <cstdio>
+
+static const char *usage =
+"\nUsage: ColladaEdgeConditioner <infile.dae> <outifle.dae> [ options ]\n\n\
+Options:\n\
+ -sharpEdgeThreshold t : sharp edge threshold defined by dihedral \n\
+ angle. Edges with a angle smaller than t\n\
+ will be defined as a sharp edge.\n\
+ -sharpEdgeColor r,g,b : color of addtional edges.\n\
+ default value is 1,0,0 .(no space)\n\n\
+ColladaEdgeConditioner checks all polygon edges in <infile.dae> and add\n\
+addtional edges to the model if normal angle of certain edge is larger\n\
+than the pre-defined threshold.\n";
+
+int wmain(int argc, wchar_t **argv) {
+ wchar_t* input_file = NULL;
+ wchar_t* output_file = NULL;
+ Options options;
+
+ if (argc < 3) {
+ printf("%s", usage);
+ return -1;
+ }
+ int file_count = 0;
+ for (int i = 1; i < argc; i++) {
+ if (wcscmp(argv[i], L"-sharpEdgeThreshold") == 0) {
+ if (++i < argc) {
+ options.enable_soften_edge = true;
+ options.soften_edge_threshold = static_cast<float>(_wtof(argv[i]));
+ }
+ } else if (wcscmp(argv[i], L"-sharpEdgeColor") == 0) {
+ if (++i < argc) {
+ int r, g, b;
+ if (swscanf_s(argv[i], L"%d,%d,%d", &r, &g, &b) != 3) {
+ printf("Invalid -sharpEdgeColor. Should be -sharpEdgeColor=x,y,z\n");
+ return -1;
+ }
+ options.sharp_edge_color = Vector3(static_cast<float>(r),
+ static_cast<float>(g),
+ static_cast<float>(b));
+ }
+ } else if (file_count < 2) {
+ ++file_count;
+ if (file_count == 1)
+ input_file = argv[i];
+ else
+ output_file = argv[i];
+ }
+ }
+
+ bool result = Condition(input_file, output_file, options);
+ return 0;
+}
diff --git a/o3d/collada_edge/cross/conditioner.cpp b/o3d/collada_edge/cross/conditioner.cpp
index 6f8580a..e1592b4 100644
--- a/o3d/collada_edge/cross/conditioner.cpp
+++ b/o3d/collada_edge/cross/conditioner.cpp
@@ -1,370 +1,370 @@
-/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#include "precompile.h"
-
-#include "conditioner.h"
-
-#include <cstdio>
-#include <map>
-#include <vector>
-
-const float kEpsilon = 0.001f;
-static const float kPi = 3.14159265358979f;
-FCDMaterial* edge_material = NULL;
-FCDEffect* edge_effect = NULL;
-
-// Constructor, make sure points order is unique. If x-coordinate is
-// the same, compare y-coordinate. If y value is also the same, compare z.
-Edge::Edge(Point3 p1, Point3 p2, uint32 i1, uint32 i2) {
- bool isRightOrder = false;
- if (fabs(p1.getX() - p2.getX()) < kEpsilon) {
- if (fabs(p1.getY() - p2.getY()) < kEpsilon) {
- if (p1.getZ() < p2.getZ())
- isRightOrder = true;
- } else {
- if (p1.getY() < p2.getY())
- isRightOrder = true;
- }
- } else {
- if (p1.getX() < p2.getX())
- isRightOrder = true;
- }
- if (isRightOrder) {
- pts.push_back(p1);
- pts.push_back(p2);
- indices.push_back(i1);
- indices.push_back(i2);
- } else {
- pts.push_back(p2);
- pts.push_back(p1);
- indices.push_back(i2);
- indices.push_back(i1);
- }
-}
-
-// less than operator overload, necessary function for edge-triangle map.
-bool operator<(const Edge& left, const Edge& right) {
- // compare two edges by their actually coordinates.
- if (dist(left.pts[0], right.pts[0]) < kEpsilon) {
- if (fabs(left.pts[1].getX() - right.pts[1].getX()) < kEpsilon) {
- if (fabs(left.pts[1].getY() - right.pts[1].getY()) < kEpsilon) {
- return left.pts[1].getZ() < right.pts[1].getZ();
- }
- return left.pts[1].getY() < right.pts[1].getY();
- }
- return left.pts[1].getX() < right.pts[1].getX();
- } else {
- if (fabs(left.pts[0].getX() - right.pts[0].getX()) < kEpsilon) {
- if (fabs(left.pts[0].getY() - right.pts[0].getY()) < kEpsilon) {
- return left.pts[0].getZ() < right.pts[0].getZ();
- }
- return left.pts[0].getY() < right.pts[0].getY();
- }
- return left.pts[0].getX() < right.pts[0].getX();
- }
-}
-
-// go through triangles who share this edge. And check whether
-// the max normal angle is larger than the threshold.
-void CheckSharpEdge(const Edge& shared_edge,
- const std::vector<Triangle>& triangle_list,
- std::vector<Edge>* sharp_edges, float threshold) {
- for (size_t i = 0; i < triangle_list.size(); i++)
- for (size_t j = i + 1; j < triangle_list.size(); j++) {
- Triangle t1 = triangle_list[i];
- Triangle t2 = triangle_list[j];
- int same_vertices_count = 0;
- // Same triangle might be stored twice to represent inner and
- // outer faces. Check the order of indices of vertices to not
- // mix inner and outer faces togeter.
- std::vector<int> same_vertices_pos;
- for (int k = 0; k < 3; k++)
- for (int l = 0; l < 3; l++) {
- if (dist(t1.pts[k], t2.pts[l]) < kEpsilon) {
- same_vertices_count++;
- same_vertices_pos.push_back(k);
- same_vertices_pos.push_back(l);
- }
- }
- if (same_vertices_count != 2)
- continue;
- // check the order of positions to make sure triangles are on
- // the same face.
- int i1 = same_vertices_pos[2] - same_vertices_pos[0];
- int i2 = same_vertices_pos[3] - same_vertices_pos[1];
- // if triangles are on different faces.
- if (!(i1 * i2 == -1 || i1 * i2 == 2 || i1 * i2 == -4))
- continue;
-
- Vector3 v12 = t1.pts[1] - t1.pts[0];
- Vector3 v13 = t1.pts[2] - t1.pts[0];
- Vector3 n1 = cross(v12, v13);
- Vector3 v22 = t2.pts[1] - t2.pts[0];
- Vector3 v23 = t2.pts[2] - t2.pts[0];
- Vector3 n2 = cross(v22, v23);
- float iAngle = acos(dot(n1, n2) / (length(n1) * length(n2)));
- iAngle = iAngle * 180 / kPi;
- if (iAngle >= threshold) {
- sharp_edges->push_back(shared_edge);
- return;
- }
- }
-}
-
-// insert edge-triangle pair to edge triangle map.
-void InsertEdgeTrianglePair(const Edge& edge, const Triangle& triangle,
- std::map<Edge, std::vector<Triangle>>* et_map) {
- std::map<Edge, std::vector<Triangle>>::iterator iter1 =
- et_map->find(edge);
- if (iter1 == et_map->end()) {
- std::vector<Triangle> same_edge_triangle_list;
- same_edge_triangle_list.push_back(triangle);
- et_map->insert(make_pair(edge, same_edge_triangle_list));
- } else {
- iter1->second.push_back(triangle);
- }
-}
-
-NodeInstance* CreateInstanceTree(FCDSceneNode *node) {
- NodeInstance *instance = new NodeInstance(node);
- NodeInstance::NodeInstanceList &children = instance->children();
- for (size_t i = 0; i < node->GetChildrenCount(); ++i) {
- FCDSceneNode *child_node = node->GetChild(i);
- NodeInstance *child_instance = CreateInstanceTree(child_node);
- children.push_back(child_instance);
- }
- return instance;
-}
-
-// go through all polygons in geom_instance, and add all sharp edges
-// as a new polygon in geom. And also, add material and effect based
-// on the given sharpEdgeColor option.
-void BuildSharpEdge(FCDocument* doc, FCDGeometryInstance* geom_instance,
- const Options& options) {
- FCDGeometry* geom = static_cast<FCDGeometry*>(geom_instance->GetEntity());
- if (!(geom && geom->IsMesh()))
- return;
- FCDGeometryMesh* mesh = geom->GetMesh();
- FCDGeometryPolygonsTools::Triangulate(mesh);
- FCDGeometryPolygonsTools::GenerateUniqueIndices(mesh, NULL, NULL);
-
- size_t num_polygons = mesh->GetPolygonsCount();
- size_t num_indices = mesh->GetFaceVertexCount();
- if (num_polygons <= 0 || num_indices <= 0) return;
- FCDGeometrySource* pos_source =
- mesh->FindSourceByType(FUDaeGeometryInput::POSITION);
- if (pos_source == NULL) return;
- size_t num_vertices = pos_source->GetValueCount();
- float* pos_source_data = pos_source->GetData();
- std::vector<Point3> point_list;
- for (size_t i = 0; i + 2 < num_vertices * 3; i += 3) {
- Point3 point(pos_source_data[i + 0],
- pos_source_data[i + 1],
- pos_source_data[i + 2]);
- point_list.push_back(point);
- }
-
- for (size_t p = 0; p < num_polygons; ++p) {
- FCDGeometryPolygons* polys = mesh->GetPolygons(p);
-
- if (polys->GetPrimitiveType() != FCDGeometryPolygons::POLYGONS)
- continue;
- FCDGeometryPolygonsInput* input = polys->GetInput(0);
- size_t size = input->GetIndexCount();
- if (size == 0) continue;
- // meshed triangle list.
- size_t vertices_per_primitive = 3;
- if (size % vertices_per_primitive != 0) {
- continue;
- }
- uint32* indices = input->GetIndices();
- size_t indexCount = input->GetIndexCount();
- // create triangle list.
- std::vector<Triangle> triangle_list;
- for (size_t i = 0; i + 2 < indexCount; i += 3) {
- Triangle triangle(point_list[indices[i + 0]],
- point_list[indices[i + 1]],
- point_list[indices[i + 2]],
- indices[i + 0],
- indices[i + 1],
- indices[i + 2]);
- triangle_list.push_back(triangle);
- }
- std::map<Edge, std::vector<Triangle>> edge_triangle_map;
- for (size_t i = 0; i < triangle_list.size(); i++) {
- Triangle triangle = triangle_list[i];
- Edge e1(triangle.pts[0], triangle.pts[1],
- triangle.indices[0], triangle.indices[1]);
- Edge e2(triangle.pts[1], triangle.pts[2],
- triangle.indices[1], triangle.indices[2]);
- Edge e3(triangle.pts[0], triangle.pts[2],
- triangle.indices[0], triangle.indices[2]);
- InsertEdgeTrianglePair(e1, triangle, &edge_triangle_map);
- InsertEdgeTrianglePair(e2, triangle, &edge_triangle_map);
- InsertEdgeTrianglePair(e3, triangle, &edge_triangle_map);
- }
- // go through the edge-triangle map.
- std::map<Edge, std::vector<Triangle>>::iterator iter;
- std::vector<Edge> sharp_edges;
- for (iter = edge_triangle_map.begin();
- iter != edge_triangle_map.end(); iter++) {
- if (iter->second.size() < 2)
- continue;
- CheckSharpEdge(iter->first, iter->second, &sharp_edges,
- options.soften_edge_threshold);
- }
- if (sharp_edges.size() > 0) {
- FCDGeometryPolygons* edge_polys = mesh->AddPolygons();
- edge_polys->AddFaceVertexCount(sharp_edges.size() * 2);
- edge_polys->SetPrimitiveType(FCDGeometryPolygons::LINES);
- FCDGeometrySource* vertex_source = mesh->GetVertexSource(0);
- FCDGeometryPolygonsInput* edge_input =
- edge_polys->AddInput(vertex_source, 0);
- FUDaeGeometryInput::Semantic semantic = edge_input->GetSemantic();
- if (edge_input == NULL)
- return;
- FCDGeometrySource* edge_source = edge_input->GetSource();
- if (edge_source == NULL)
- return;
- for (size_t i = 0; i < sharp_edges.size(); i++) {
- edge_input->AddIndex(sharp_edges[i].indices[0]);
- edge_input->AddIndex(sharp_edges[i].indices[1]);
- }
- edge_input->SetIndexCount(sharp_edges.size() * 2);
- edge_input->SetOffset(0);
-
- if (edge_material == NULL) {
- // add material to material lib.
- FCDMaterialLibrary* material_library = doc->GetMaterialLibrary();
- FCDEffectLibrary* effect_library = doc->GetEffectLibrary();
- edge_material =
- static_cast<FCDMaterial*>(material_library->AddEntity());
- edge_material->SetDaeId("o3d_hard_edge_materialID");
- edge_material->SetName(L"o3d_hard_edge_material");
- edge_effect = static_cast<FCDEffect*>(effect_library->AddEntity());
- edge_effect->SetDaeId("o3d_hard_edge_effectID");
- edge_effect->SetName(L"o3d_hard_edge_effect");
- if (edge_effect == NULL || edge_material == NULL)
- return;
- edge_material->SetEffect(edge_effect);
- FCDEffectStandard* edge_effect_profile =
- static_cast<FCDEffectStandard*>(edge_effect->AddProfile(
- FUDaeProfileType::COMMON));
- edge_effect_profile->SetLightingType(FCDEffectStandard::LAMBERT);
- edge_effect_profile->
- SetEmissionColor(FMVector4(options.sharp_edge_color.getX(),
- options.sharp_edge_color.getY(),
- options.sharp_edge_color.getZ(), 1));
- }
- // add material instance to visual scenes lib.
- FCDMaterialInstance* edge_material_instance =
- geom_instance->AddMaterialInstance(edge_material, edge_polys);
- edge_material_instance->SetSemantic(L"o3d_hard_edge_material");
- edge_polys->SetMaterialSemantic(L"o3d_hard_edge_material");
- }
- }
-}
-
-// go through the collada tree and import instance. if found a
-// geometry instance, call BuildSharpEdge function.
-bool ImportTreeInstances(FCDocument* doc,
- NodeInstance *node_instance,
- const Options& options) {
- FCDSceneNode *node = node_instance->node();
- // recursively import the rest of the nodes in the tree
- const NodeInstance::NodeInstanceList &children = node_instance->children();
- for (size_t i = 0; i < children.size(); ++i) {
- if (!ImportTreeInstances(doc, children[i], options)) {
- return false;
- }
- }
- for (size_t i = 0; i < node->GetInstanceCount(); ++i) {
- FCDEntityInstance* instance = node->GetInstance(i);
- FCDCamera* camera(NULL);
- FCDGeometryInstance* geom_instance(NULL);
- FCDMaterialInstance* mat_instance(NULL);
- // Import each node based on what kind of entity it is
- switch (instance->GetEntityType()) {
- case FCDEntity::GEOMETRY: {
- // geometry entity
- geom_instance = static_cast<FCDGeometryInstance*>(instance);
- BuildSharpEdge(doc, geom_instance, options);
- break;
- }
- case FCDEntity::CAMERA:
- case FCDEntity::CONTROLLER:
- default: break;
- }
- }
- return true;
-}
-
-bool ConditionDoc(FCDocument* doc, const Options& options) {
- // The root of the instance node tree.
- NodeInstance* instance_root_;
- bool status = false;
- // Import the scene objects, starting at the root.
- FCDSceneNode* scene = doc->GetVisualSceneInstance();
- if (scene) {
- instance_root_ = CreateInstanceTree(scene);
- if (ImportTreeInstances(doc, instance_root_, options)) {
- status = true;
- }
- delete instance_root_;
- }
- return status;
-}
-
-bool Condition(const wchar_t* in_filename, const wchar_t* out_filename,
- const Options& options) {
- FCollada::Initialize();
- FCDocument* doc = FCollada::NewTopDocument();
- bool retval = false;
- if (doc) {
- // Load and parse the COLLADA file.
- if (FCollada::LoadDocumentFromFile(doc, in_filename)) {
- doc->SetFileUrl(out_filename);
-
- // condition it.
- retval = ConditionDoc(doc, options);
- if (retval) {
- FCollada::SaveDocument(doc, out_filename);
- }
- } else {
- printf("Error: couldn't open the input file.\n");
- }
- doc->Release();
- } else {
- printf("Internal error: Couldn't create FCollada document.\n");
- }
- FCollada::Release();
- return retval;
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "precompile.h"
+
+#include "conditioner.h"
+
+#include <cstdio>
+#include <map>
+#include <vector>
+
+const float kEpsilon = 0.001f;
+static const float kPi = 3.14159265358979f;
+FCDMaterial* edge_material = NULL;
+FCDEffect* edge_effect = NULL;
+
+// Constructor, make sure points order is unique. If x-coordinate is
+// the same, compare y-coordinate. If y value is also the same, compare z.
+Edge::Edge(Point3 p1, Point3 p2, uint32 i1, uint32 i2) {
+ bool isRightOrder = false;
+ if (fabs(p1.getX() - p2.getX()) < kEpsilon) {
+ if (fabs(p1.getY() - p2.getY()) < kEpsilon) {
+ if (p1.getZ() < p2.getZ())
+ isRightOrder = true;
+ } else {
+ if (p1.getY() < p2.getY())
+ isRightOrder = true;
+ }
+ } else {
+ if (p1.getX() < p2.getX())
+ isRightOrder = true;
+ }
+ if (isRightOrder) {
+ pts.push_back(p1);
+ pts.push_back(p2);
+ indices.push_back(i1);
+ indices.push_back(i2);
+ } else {
+ pts.push_back(p2);
+ pts.push_back(p1);
+ indices.push_back(i2);
+ indices.push_back(i1);
+ }
+}
+
+// less than operator overload, necessary function for edge-triangle map.
+bool operator<(const Edge& left, const Edge& right) {
+ // compare two edges by their actually coordinates.
+ if (dist(left.pts[0], right.pts[0]) < kEpsilon) {
+ if (fabs(left.pts[1].getX() - right.pts[1].getX()) < kEpsilon) {
+ if (fabs(left.pts[1].getY() - right.pts[1].getY()) < kEpsilon) {
+ return left.pts[1].getZ() < right.pts[1].getZ();
+ }
+ return left.pts[1].getY() < right.pts[1].getY();
+ }
+ return left.pts[1].getX() < right.pts[1].getX();
+ } else {
+ if (fabs(left.pts[0].getX() - right.pts[0].getX()) < kEpsilon) {
+ if (fabs(left.pts[0].getY() - right.pts[0].getY()) < kEpsilon) {
+ return left.pts[0].getZ() < right.pts[0].getZ();
+ }
+ return left.pts[0].getY() < right.pts[0].getY();
+ }
+ return left.pts[0].getX() < right.pts[0].getX();
+ }
+}
+
+// go through triangles who share this edge. And check whether
+// the max normal angle is larger than the threshold.
+void CheckSharpEdge(const Edge& shared_edge,
+ const std::vector<Triangle>& triangle_list,
+ std::vector<Edge>* sharp_edges, float threshold) {
+ for (size_t i = 0; i < triangle_list.size(); i++)
+ for (size_t j = i + 1; j < triangle_list.size(); j++) {
+ Triangle t1 = triangle_list[i];
+ Triangle t2 = triangle_list[j];
+ int same_vertices_count = 0;
+ // Same triangle might be stored twice to represent inner and
+ // outer faces. Check the order of indices of vertices to not
+ // mix inner and outer faces togeter.
+ std::vector<int> same_vertices_pos;
+ for (int k = 0; k < 3; k++)
+ for (int l = 0; l < 3; l++) {
+ if (dist(t1.pts[k], t2.pts[l]) < kEpsilon) {
+ same_vertices_count++;
+ same_vertices_pos.push_back(k);
+ same_vertices_pos.push_back(l);
+ }
+ }
+ if (same_vertices_count != 2)
+ continue;
+ // check the order of positions to make sure triangles are on
+ // the same face.
+ int i1 = same_vertices_pos[2] - same_vertices_pos[0];
+ int i2 = same_vertices_pos[3] - same_vertices_pos[1];
+ // if triangles are on different faces.
+ if (!(i1 * i2 == -1 || i1 * i2 == 2 || i1 * i2 == -4))
+ continue;
+
+ Vector3 v12 = t1.pts[1] - t1.pts[0];
+ Vector3 v13 = t1.pts[2] - t1.pts[0];
+ Vector3 n1 = cross(v12, v13);
+ Vector3 v22 = t2.pts[1] - t2.pts[0];
+ Vector3 v23 = t2.pts[2] - t2.pts[0];
+ Vector3 n2 = cross(v22, v23);
+ float iAngle = acos(dot(n1, n2) / (length(n1) * length(n2)));
+ iAngle = iAngle * 180 / kPi;
+ if (iAngle >= threshold) {
+ sharp_edges->push_back(shared_edge);
+ return;
+ }
+ }
+}
+
+// insert edge-triangle pair to edge triangle map.
+void InsertEdgeTrianglePair(const Edge& edge, const Triangle& triangle,
+ std::map<Edge, std::vector<Triangle>>* et_map) {
+ std::map<Edge, std::vector<Triangle>>::iterator iter1 =
+ et_map->find(edge);
+ if (iter1 == et_map->end()) {
+ std::vector<Triangle> same_edge_triangle_list;
+ same_edge_triangle_list.push_back(triangle);
+ et_map->insert(make_pair(edge, same_edge_triangle_list));
+ } else {
+ iter1->second.push_back(triangle);
+ }
+}
+
+NodeInstance* CreateInstanceTree(FCDSceneNode *node) {
+ NodeInstance *instance = new NodeInstance(node);
+ NodeInstance::NodeInstanceList &children = instance->children();
+ for (size_t i = 0; i < node->GetChildrenCount(); ++i) {
+ FCDSceneNode *child_node = node->GetChild(i);
+ NodeInstance *child_instance = CreateInstanceTree(child_node);
+ children.push_back(child_instance);
+ }
+ return instance;
+}
+
+// go through all polygons in geom_instance, and add all sharp edges
+// as a new polygon in geom. And also, add material and effect based
+// on the given sharpEdgeColor option.
+void BuildSharpEdge(FCDocument* doc, FCDGeometryInstance* geom_instance,
+ const Options& options) {
+ FCDGeometry* geom = static_cast<FCDGeometry*>(geom_instance->GetEntity());
+ if (!(geom && geom->IsMesh()))
+ return;
+ FCDGeometryMesh* mesh = geom->GetMesh();
+ FCDGeometryPolygonsTools::Triangulate(mesh);
+ FCDGeometryPolygonsTools::GenerateUniqueIndices(mesh, NULL, NULL);
+
+ size_t num_polygons = mesh->GetPolygonsCount();
+ size_t num_indices = mesh->GetFaceVertexCount();
+ if (num_polygons <= 0 || num_indices <= 0) return;
+ FCDGeometrySource* pos_source =
+ mesh->FindSourceByType(FUDaeGeometryInput::POSITION);
+ if (pos_source == NULL) return;
+ size_t num_vertices = pos_source->GetValueCount();
+ float* pos_source_data = pos_source->GetData();
+ std::vector<Point3> point_list;
+ for (size_t i = 0; i + 2 < num_vertices * 3; i += 3) {
+ Point3 point(pos_source_data[i + 0],
+ pos_source_data[i + 1],
+ pos_source_data[i + 2]);
+ point_list.push_back(point);
+ }
+
+ for (size_t p = 0; p < num_polygons; ++p) {
+ FCDGeometryPolygons* polys = mesh->GetPolygons(p);
+
+ if (polys->GetPrimitiveType() != FCDGeometryPolygons::POLYGONS)
+ continue;
+ FCDGeometryPolygonsInput* input = polys->GetInput(0);
+ size_t size = input->GetIndexCount();
+ if (size == 0) continue;
+ // meshed triangle list.
+ size_t vertices_per_primitive = 3;
+ if (size % vertices_per_primitive != 0) {
+ continue;
+ }
+ uint32* indices = input->GetIndices();
+ size_t indexCount = input->GetIndexCount();
+ // create triangle list.
+ std::vector<Triangle> triangle_list;
+ for (size_t i = 0; i + 2 < indexCount; i += 3) {
+ Triangle triangle(point_list[indices[i + 0]],
+ point_list[indices[i + 1]],
+ point_list[indices[i + 2]],
+ indices[i + 0],
+ indices[i + 1],
+ indices[i + 2]);
+ triangle_list.push_back(triangle);
+ }
+ std::map<Edge, std::vector<Triangle>> edge_triangle_map;
+ for (size_t i = 0; i < triangle_list.size(); i++) {
+ Triangle triangle = triangle_list[i];
+ Edge e1(triangle.pts[0], triangle.pts[1],
+ triangle.indices[0], triangle.indices[1]);
+ Edge e2(triangle.pts[1], triangle.pts[2],
+ triangle.indices[1], triangle.indices[2]);
+ Edge e3(triangle.pts[0], triangle.pts[2],
+ triangle.indices[0], triangle.indices[2]);
+ InsertEdgeTrianglePair(e1, triangle, &edge_triangle_map);
+ InsertEdgeTrianglePair(e2, triangle, &edge_triangle_map);
+ InsertEdgeTrianglePair(e3, triangle, &edge_triangle_map);
+ }
+ // go through the edge-triangle map.
+ std::map<Edge, std::vector<Triangle>>::iterator iter;
+ std::vector<Edge> sharp_edges;
+ for (iter = edge_triangle_map.begin();
+ iter != edge_triangle_map.end(); iter++) {
+ if (iter->second.size() < 2)
+ continue;
+ CheckSharpEdge(iter->first, iter->second, &sharp_edges,
+ options.soften_edge_threshold);
+ }
+ if (sharp_edges.size() > 0) {
+ FCDGeometryPolygons* edge_polys = mesh->AddPolygons();
+ edge_polys->AddFaceVertexCount(sharp_edges.size() * 2);
+ edge_polys->SetPrimitiveType(FCDGeometryPolygons::LINES);
+ FCDGeometrySource* vertex_source = mesh->GetVertexSource(0);
+ FCDGeometryPolygonsInput* edge_input =
+ edge_polys->AddInput(vertex_source, 0);
+ FUDaeGeometryInput::Semantic semantic = edge_input->GetSemantic();
+ if (edge_input == NULL)
+ return;
+ FCDGeometrySource* edge_source = edge_input->GetSource();
+ if (edge_source == NULL)
+ return;
+ for (size_t i = 0; i < sharp_edges.size(); i++) {
+ edge_input->AddIndex(sharp_edges[i].indices[0]);
+ edge_input->AddIndex(sharp_edges[i].indices[1]);
+ }
+ edge_input->SetIndexCount(sharp_edges.size() * 2);
+ edge_input->SetOffset(0);
+
+ if (edge_material == NULL) {
+ // add material to material lib.
+ FCDMaterialLibrary* material_library = doc->GetMaterialLibrary();
+ FCDEffectLibrary* effect_library = doc->GetEffectLibrary();
+ edge_material =
+ static_cast<FCDMaterial*>(material_library->AddEntity());
+ edge_material->SetDaeId("o3d_hard_edge_materialID");
+ edge_material->SetName(L"o3d_hard_edge_material");
+ edge_effect = static_cast<FCDEffect*>(effect_library->AddEntity());
+ edge_effect->SetDaeId("o3d_hard_edge_effectID");
+ edge_effect->SetName(L"o3d_hard_edge_effect");
+ if (edge_effect == NULL || edge_material == NULL)
+ return;
+ edge_material->SetEffect(edge_effect);
+ FCDEffectStandard* edge_effect_profile =
+ static_cast<FCDEffectStandard*>(edge_effect->AddProfile(
+ FUDaeProfileType::COMMON));
+ edge_effect_profile->SetLightingType(FCDEffectStandard::LAMBERT);
+ edge_effect_profile->
+ SetEmissionColor(FMVector4(options.sharp_edge_color.getX(),
+ options.sharp_edge_color.getY(),
+ options.sharp_edge_color.getZ(), 1));
+ }
+ // add material instance to visual scenes lib.
+ FCDMaterialInstance* edge_material_instance =
+ geom_instance->AddMaterialInstance(edge_material, edge_polys);
+ edge_material_instance->SetSemantic(L"o3d_hard_edge_material");
+ edge_polys->SetMaterialSemantic(L"o3d_hard_edge_material");
+ }
+ }
+}
+
+// go through the collada tree and import instance. if found a
+// geometry instance, call BuildSharpEdge function.
+bool ImportTreeInstances(FCDocument* doc,
+ NodeInstance *node_instance,
+ const Options& options) {
+ FCDSceneNode *node = node_instance->node();
+ // recursively import the rest of the nodes in the tree
+ const NodeInstance::NodeInstanceList &children = node_instance->children();
+ for (size_t i = 0; i < children.size(); ++i) {
+ if (!ImportTreeInstances(doc, children[i], options)) {
+ return false;
+ }
+ }
+ for (size_t i = 0; i < node->GetInstanceCount(); ++i) {
+ FCDEntityInstance* instance = node->GetInstance(i);
+ FCDCamera* camera(NULL);
+ FCDGeometryInstance* geom_instance(NULL);
+ FCDMaterialInstance* mat_instance(NULL);
+ // Import each node based on what kind of entity it is
+ switch (instance->GetEntityType()) {
+ case FCDEntity::GEOMETRY: {
+ // geometry entity
+ geom_instance = static_cast<FCDGeometryInstance*>(instance);
+ BuildSharpEdge(doc, geom_instance, options);
+ break;
+ }
+ case FCDEntity::CAMERA:
+ case FCDEntity::CONTROLLER:
+ default: break;
+ }
+ }
+ return true;
+}
+
+bool ConditionDoc(FCDocument* doc, const Options& options) {
+ // The root of the instance node tree.
+ NodeInstance* instance_root_;
+ bool status = false;
+ // Import the scene objects, starting at the root.
+ FCDSceneNode* scene = doc->GetVisualSceneInstance();
+ if (scene) {
+ instance_root_ = CreateInstanceTree(scene);
+ if (ImportTreeInstances(doc, instance_root_, options)) {
+ status = true;
+ }
+ delete instance_root_;
+ }
+ return status;
+}
+
+bool Condition(const wchar_t* in_filename, const wchar_t* out_filename,
+ const Options& options) {
+ FCollada::Initialize();
+ FCDocument* doc = FCollada::NewTopDocument();
+ bool retval = false;
+ if (doc) {
+ // Load and parse the COLLADA file.
+ if (FCollada::LoadDocumentFromFile(doc, in_filename)) {
+ doc->SetFileUrl(out_filename);
+
+ // condition it.
+ retval = ConditionDoc(doc, options);
+ if (retval) {
+ FCollada::SaveDocument(doc, out_filename);
+ }
+ } else {
+ printf("Error: couldn't open the input file.\n");
+ }
+ doc->Release();
+ } else {
+ printf("Internal error: Couldn't create FCollada document.\n");
+ }
+ FCollada::Release();
+ return retval;
} \ No newline at end of file
diff --git a/o3d/collada_edge/cross/conditioner.h b/o3d/collada_edge/cross/conditioner.h
index b622610..57c61fabee 100644
--- a/o3d/collada_edge/cross/conditioner.h
+++ b/o3d/collada_edge/cross/conditioner.h
@@ -1,121 +1,121 @@
-/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
#ifndef O3D_COLLADA_EDGE_CONDITIONER_H_
-#define O3D_COLLADA_EDGE_CONDITIONER_H_
-
-#include <vector>
-#include "utility.h"
-
-struct Options {
- // default constructor.
- Options()
- : enable_soften_edge(false),
- soften_edge_threshold(0),
- sharp_edge_color(1, 0, 0) {}
-
- // Add edges with dihedral angle larger than soften_edge_threshold.
- bool enable_soften_edge;
-
- // The threshold of normal angle of edges, if angle of certain
- // edge is larger than this threshold, it will be added into
- // the output file.
- float soften_edge_threshold;
-
- // Color of extra edges.
- Vector3 sharp_edge_color;
-};
-
-// This takes ownership of its children NodeInstances.
-class NodeInstance {
- public:
- typedef std::vector<NodeInstance *> NodeInstanceList;
-
- explicit NodeInstance(FCDSceneNode *node) : node_(node) {}
- ~NodeInstance() {
- for (unsigned int i = 0; i < children_.size(); ++i) {
- delete children_[i];
- }
- }
-
- // Gets the Collada node associated with this node instance.
- FCDSceneNode *node() const { return node_; }
-
- // Gets the list of this node instance's children.
- NodeInstanceList &children() { return children_; }
-
- // Finds the NodeInstance representing a scene node in the direct
- // children of this NodeInstance.
- NodeInstance *FindNodeShallow(FCDSceneNode *node) {
- for (unsigned int i = 0; i < children_.size(); ++i) {
- NodeInstance *child = children_[i];
- if (child->node() == node) return child;
- }
- return NULL;
- }
-
- // Finds the NodeInstance representing a scene node in the sub-tree
- // starting at this NodeInstance.
- NodeInstance *FindNodeInTree(FCDSceneNode *node);
-
- private:
- FCDSceneNode *node_;
- std::vector<NodeInstance *> children_;
-};
-
-// Edge class is used in detect sharp edge process. It stores two points
-// in a specific order, and it serves as key class in edge-triangle map.
-struct Edge {
- Edge(Point3 p1, Point3 p2, uint32 i1, uint32 i2);
- std::vector<Point3> pts;
- std::vector<uint32> indices;
-};
-
-// Triangle class is used in detect sharp edge process.
-struct Triangle {
- Triangle(Point3 p1, Point3 p2, Point3 p3,
- uint32 i1, uint32 i2, uint32 i3) {
- pts.push_back(p1);
- pts.push_back(p2);
- pts.push_back(p3);
- indices.push_back(i1);
- indices.push_back(i2);
- indices.push_back(i3);
- }
- std::vector<Point3> pts;
- std::vector<uint32> indices;
-};
-
-// Conditions the given file to emphasize the sharp edges.
-// Returns false on failure, and writes the relevant erros to stderr.
-bool Condition(const wchar_t* in_filename, const wchar_t* out_filename,
- const Options& options);
-
+#define O3D_COLLADA_EDGE_CONDITIONER_H_
+
+#include <vector>
+#include "utility.h"
+
+struct Options {
+ // default constructor.
+ Options()
+ : enable_soften_edge(false),
+ soften_edge_threshold(0),
+ sharp_edge_color(1, 0, 0) {}
+
+ // Add edges with dihedral angle larger than soften_edge_threshold.
+ bool enable_soften_edge;
+
+ // The threshold of normal angle of edges, if angle of certain
+ // edge is larger than this threshold, it will be added into
+ // the output file.
+ float soften_edge_threshold;
+
+ // Color of extra edges.
+ Vector3 sharp_edge_color;
+};
+
+// This takes ownership of its children NodeInstances.
+class NodeInstance {
+ public:
+ typedef std::vector<NodeInstance *> NodeInstanceList;
+
+ explicit NodeInstance(FCDSceneNode *node) : node_(node) {}
+ ~NodeInstance() {
+ for (unsigned int i = 0; i < children_.size(); ++i) {
+ delete children_[i];
+ }
+ }
+
+ // Gets the Collada node associated with this node instance.
+ FCDSceneNode *node() const { return node_; }
+
+ // Gets the list of this node instance's children.
+ NodeInstanceList &children() { return children_; }
+
+ // Finds the NodeInstance representing a scene node in the direct
+ // children of this NodeInstance.
+ NodeInstance *FindNodeShallow(FCDSceneNode *node) {
+ for (unsigned int i = 0; i < children_.size(); ++i) {
+ NodeInstance *child = children_[i];
+ if (child->node() == node) return child;
+ }
+ return NULL;
+ }
+
+ // Finds the NodeInstance representing a scene node in the sub-tree
+ // starting at this NodeInstance.
+ NodeInstance *FindNodeInTree(FCDSceneNode *node);
+
+ private:
+ FCDSceneNode *node_;
+ std::vector<NodeInstance *> children_;
+};
+
+// Edge class is used in detect sharp edge process. It stores two points
+// in a specific order, and it serves as key class in edge-triangle map.
+struct Edge {
+ Edge(Point3 p1, Point3 p2, uint32 i1, uint32 i2);
+ std::vector<Point3> pts;
+ std::vector<uint32> indices;
+};
+
+// Triangle class is used in detect sharp edge process.
+struct Triangle {
+ Triangle(Point3 p1, Point3 p2, Point3 p3,
+ uint32 i1, uint32 i2, uint32 i3) {
+ pts.push_back(p1);
+ pts.push_back(p2);
+ pts.push_back(p3);
+ indices.push_back(i1);
+ indices.push_back(i2);
+ indices.push_back(i3);
+ }
+ std::vector<Point3> pts;
+ std::vector<uint32> indices;
+};
+
+// Conditions the given file to emphasize the sharp edges.
+// Returns false on failure, and writes the relevant erros to stderr.
+bool Condition(const wchar_t* in_filename, const wchar_t* out_filename,
+ const Options& options);
+
#endif \ No newline at end of file
diff --git a/o3d/collada_edge/cross/precompile.h b/o3d/collada_edge/cross/precompile.h
index e5d1b51..e062271 100644
--- a/o3d/collada_edge/cross/precompile.h
+++ b/o3d/collada_edge/cross/precompile.h
@@ -1,54 +1,54 @@
-/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
#ifndef O3D_COLLADA_EDGE_PRECOMPILE_H_
-#define O3D_COLLADA_EDGE_PRECOMPILE_H_
-
-#include <stdio.h>
-#include <tchar.h>
-
-#include "FCollada.h"
-#include "FCDocument/FCDocument.h"
-#include "FCDocument/FCDEffect.h"
-#include "FCDocument/FCDEffectStandard.h"
-#include "FCDocument/FCDSceneNode.h"
-#include "FCDocument/FCDGeometry.h"
-#include "FCDocument/FCDGeometryInstance.h"
-#include "FCDocument/FCDGeometryMesh.h"
-#include "FCDocument/FCDGeometryPolygons.h"
-#include "FCDocument/FCDGeometryPolygonsInput.h"
-#include "FCDocument/FCDGeometryPolygonsTools.h"
-#include "FCDocument/FCDGeometrySource.h"
-#include "FCDocument/FCDLibrary.h"
-#include "FCDocument/FCDMaterial.h"
-#include "FCDocument/FCDMaterialInstance.h"
-
+#define O3D_COLLADA_EDGE_PRECOMPILE_H_
+
+#include <stdio.h>
+#include <tchar.h>
+
+#include "FCollada.h"
+#include "FCDocument/FCDocument.h"
+#include "FCDocument/FCDEffect.h"
+#include "FCDocument/FCDEffectStandard.h"
+#include "FCDocument/FCDSceneNode.h"
+#include "FCDocument/FCDGeometry.h"
+#include "FCDocument/FCDGeometryInstance.h"
+#include "FCDocument/FCDGeometryMesh.h"
+#include "FCDocument/FCDGeometryPolygons.h"
+#include "FCDocument/FCDGeometryPolygonsInput.h"
+#include "FCDocument/FCDGeometryPolygonsTools.h"
+#include "FCDocument/FCDGeometrySource.h"
+#include "FCDocument/FCDLibrary.h"
+#include "FCDocument/FCDMaterial.h"
+#include "FCDocument/FCDMaterialInstance.h"
+
#endif \ No newline at end of file
diff --git a/o3d/collada_edge/cross/utility.h b/o3d/collada_edge/cross/utility.h
index 2345338..6fe1bc7 100644
--- a/o3d/collada_edge/cross/utility.h
+++ b/o3d/collada_edge/cross/utility.h
@@ -1,45 +1,45 @@
-/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
#ifndef O3D_COLLADA_EDGE_UTILITY_H_
-#define O3D_COLLADA_EDGE_UTILITY_H_
-
-#include "..\vectormath\vectormathlibrary\include\vectormath\scalar\cpp\vectormath_aos.h" // NOLINT"
-
-// Point
-//
-typedef Vectormath::Aos::Point3 Point3;
-
-// 3d-vector
-//
-typedef Vectormath::Aos::Vector3 Vector3;
-
+#define O3D_COLLADA_EDGE_UTILITY_H_
+
+#include "..\vectormath\vectormathlibrary\include\vectormath\scalar\cpp\vectormath_aos.h" // NOLINT"
+
+// Point
+//
+typedef Vectormath::Aos::Point3 Point3;
+
+// 3d-vector
+//
+typedef Vectormath::Aos::Vector3 Vector3;
+
#endif \ No newline at end of file