Text archives Help
- From: "Solomon Boulos" <boulos@cs.utah.edu>
- To: manta@sci.utah.edu
- Subject: [Manta] r2033 - trunk/scenes
- Date: Tue, 5 Feb 2008 21:05:00 -0700 (MST)
Author: boulos
Date: Tue Feb 5 21:04:59 2008
New Revision: 2033
Modified:
trunk/scenes/triangleSceneViewer.cc
Log:
scenes/triangleSceneViewer.cc
Refactoring the model loading in triangleSceneViewer so that a single
mesh is no longer an "animation" of only 1 frame.
Modified: trunk/scenes/triangleSceneViewer.cc
==============================================================================
--- trunk/scenes/triangleSceneViewer.cc (original)
+++ trunk/scenes/triangleSceneViewer.cc Tue Feb 5 21:04:59 2008
@@ -52,6 +52,31 @@
throw IllegalArgument("scene primtest", i, args);
}
+Mesh* LoadModel(std::string modelName, MeshTriangle::TriangleType
triangleType, bool useFaceNormals, bool interpolateNormals ) {
+ Mesh* frame = NULL;
+ if (!strncmp(modelName.c_str()+modelName.length()-4, ".ply", 4)) {
+ frame = new Mesh;
+ if (!readPlyFile(modelName, AffineTransform::createIdentity(), frame, 0,
triangleType))
+ printf("error loading or reading ply file: %s\n", modelName.c_str());
+ }
+ else if (!strncmp(modelName.c_str()+modelName.length()-4, ".obj", 4)) {
+ frame = new ObjGroup(modelName.c_str(), NULL, triangleType);
+ }
+
+ // NOTE(boulos): This code seems a bit strange, but what it's doing
+ // is if you ask it to use the face normals it discards them from
+ // the mesh and then if you ask it to build smooth normals, it does
+ // so (but only if they're not there already). It seems like we
+ // should throw some errors for some of these combinations...
+ if (useFaceNormals) {
+ frame->discardVertexNormals();
+
+ if (interpolateNormals && !frame->hasVertexNormals())
+ frame->interpolateNormals();
+ }
+ return frame;
+}
+
MANTA_PLUGINEXPORT
Scene* make_scene(const ReadContext&, const vector<string>& args)
{
@@ -117,13 +142,6 @@
Group* group = new Group();
- KeyFrameAnimation *animation = new KeyFrameAnimation();
- if (smoothAnimation)
- animation->setInterpolation(KeyFrameAnimation::linear);
-
- group->add(animation);
- animation->useAccelerationStructure(as);
-
string modelName = fileNames[0];
if (!strncmp(modelName.c_str()+modelName.length()-5, ".anim", 5)) {
fileNames.clear();
@@ -135,31 +153,30 @@
}
}
- Mesh *frame = NULL;
- for (size_t i=0; i < fileNames.size(); ++i) {
- modelName = fileNames[i];
- cout << "loading " << modelName <<endl;
-
- if (!strncmp(modelName.c_str()+modelName.length()-4, ".ply", 4)) {
- frame = new Mesh;
- if (!readPlyFile(modelName, AffineTransform::createIdentity(), frame,
0, triangleType))
- printf("error loading or reading ply file: %s\n", modelName.c_str());
+ if (fileNames.size() > 1) {
+ KeyFrameAnimation *animation = new KeyFrameAnimation();
+ if (smoothAnimation)
+ animation->setInterpolation(KeyFrameAnimation::linear);
+
+ group->add(animation);
+ animation->useAccelerationStructure(as);
+
+ for (size_t i=0; i < fileNames.size(); ++i) {
+ modelName = fileNames[i];
+ cout << "loading " << modelName <<endl;
+ Mesh* frame = LoadModel(modelName, triangleType, useFaceNormals,
interpolateNormals);
+ animation->push_back(frame);
}
- else if (!strncmp(modelName.c_str()+modelName.length()-4, ".obj", 4)) {
- frame = new ObjGroup(modelName.c_str(), NULL, triangleType);
- }
- if (useFaceNormals) {
- frame->discardVertexNormals();
-
- if (interpolateNormals && !frame->hasVertexNormals())
- frame->interpolateNormals();
- }
- animation->push_back(frame);
+ animation->setDuration(animationLength);
+ animation->startAnimation();
+ } else {
+ // If we're just a single mesh, load it directly instead of using
+ // the animation class.
+ Mesh* singleFrame = LoadModel(fileNames[0], triangleType,
useFaceNormals, interpolateNormals);
+ as->setGroup(singleFrame);
+ group->add(as);
}
-
- animation->setDuration(animationLength);
- animation->startAnimation();
Scene* scene = new Scene();
// scene->setBackground(new LinearBackground(Color(RGB(0.2, 0.4, 0.9)),
- [Manta] r2033 - trunk/scenes, Solomon Boulos, 02/05/2008
Archive powered by MHonArc 2.6.16.