Text archives Help
- From: thiago@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1475 - in trunk: Model/Groups scenes
- Date: Mon, 16 Jul 2007 00:47:18 -0600 (MDT)
Author: thiago
Date: Mon Jul 16 00:47:17 2007
New Revision: 1475
Added:
trunk/scenes/triangleSceneViewer.cc
Modified:
trunk/Model/Groups/ObjGroup.cc
trunk/scenes/CMakeLists.txt
Log:
Model/Groups/ObjGroup.cc:
More interesting to use lambertian instead of flat shading for the
default. That way shadows work.
scenes/triangleSceneViewer.cc
scenes/CMakeLists.txt:
Added a new scene that loads triangle type data files. Currently it
does obj and ply files. If you pass it multiple files it will create
an animation of it. You can also create a .anim file which contains a
list of all the files to load.
Take a look at the source or just run the scene with bogus
parameters/no parameters to see what the options are.
I would like this to remove the need for objviewer. If there's
something in objviewer that you'd like that isn't here, could you port
it over so we can delete it?
Here's an example of how it's run:
bin/manta -imagetraverser "tiled (-square )" -scene
"lib/libscene_triangleSceneViewer.dylib(-model
/Users/thiago/data/models/quake/massive_short.anim -interpolateNormals
-DynBVH -animationLength 3.5)" -np 2
Modified: trunk/Model/Groups/ObjGroup.cc
==============================================================================
--- trunk/Model/Groups/ObjGroup.cc (original)
+++ trunk/Model/Groups/ObjGroup.cc Mon Jul 16 00:47:17 2007
@@ -85,7 +85,7 @@
//////////////////////////////////////////////////////////////////////
// Copy out material attributes.
string mtl_name(model->materials[i].name);
- std::cerr << "Name ("<<mtl_name<<") ";
+// std::cerr << "Name ("<<mtl_name<<") ";
// Color ambient (RGB( model->materials[i].ambient[0],
// model->materials[i].ambient[1],
@@ -192,7 +192,8 @@
// model->facetnorms[i*3+1],
// model->facetnorms[i*3+2]));
- Material *default_material = new Flat( new NormalTexture() );
+// Material *default_material = new Flat( new NormalTexture() );
+ Material *default_material = new Lambertian( new NormalTexture() );
materials.push_back(default_material);
for (unsigned int i=0; i < model->nummaterials; ++i)
materials.push_back(material_array[i]);
Modified: trunk/scenes/CMakeLists.txt
==============================================================================
--- trunk/scenes/CMakeLists.txt (original)
+++ trunk/scenes/CMakeLists.txt Mon Jul 16 00:47:17 2007
@@ -94,6 +94,14 @@
TARGET_LINK_LIBRARIES(scene_iwviewer ${MANTA_SCENE_LINK})
ENDIF(SCENE_IWVIEWER)
+# triangle scene viewer loads obj, ply, and animations made of those files.
+SET(SCENE_TRIANGLESCENEVIEWER 0 CACHE BOOL "triangle scene viewer (ply, obj,
animations...)")
+IF(SCENE_TRIANGLESCENEVIEWER)
+ ADD_LIBRARY(scene_triangleSceneViewer triangleSceneViewer.cc)
+ TARGET_LINK_LIBRARIES(scene_triangleSceneViewer ${MANTA_SCENE_LINK})
+ENDIF(SCENE_TRIANGLESCENEVIEWER)
+
+
SET(SCENE_PERF 0 CACHE BOOL "Perf Test Scene.")
IF(SCENE_PERF)
ADD_LIBRARY(scene_perf perf.cc)
Added: trunk/scenes/triangleSceneViewer.cc
==============================================================================
--- (empty file)
+++ trunk/scenes/triangleSceneViewer.cc Mon Jul 16 00:47:17 2007
@@ -0,0 +1,149 @@
+#include <Core/Exceptions/IllegalArgument.h>
+#include <Core/Util/Args.h>
+#include <Core/Color/ColorDB.h>
+#include <Core/Exceptions/UnknownColor.h>
+#include <Interface/LightSet.h>
+#include <Interface/Scene.h>
+#include <Model/AmbientLights/ArcAmbient.h>
+#include <Model/Backgrounds/LinearBackground.h>
+#include <Model/Backgrounds/ConstantBackground.h>
+#include <Model/MiscObjects/KeyFrameAnimation.h>
+#include <Model/Groups/Group.h>
+#include <Model/Groups/ObjGroup.h>
+#include <Model/Groups/DynBVH.h>
+#include <Model/Lights/PointLight.h>
+#include <Model/Textures/Constant.h>
+#include <Model/Readers/PlyReader.h>
+#include <Core/Math/MinMax.h>
+#include <string>
+#include <vector>
+#include <iostream>
+#include <fstream>
+
+
+#include "UsePrivateCode.h"
+#ifdef USE_PRIVATE_CODE
+#include <Model/Groups/private/CGT.h>
+#endif
+
+
+using namespace Manta;
+using namespace std;
+
+extern "C"
+Scene* make_scene(const ReadContext&, const vector<string>& args)
+{
+ std::cout << "Make_scene args: " << args.size() << std::endl;
+
+ vector<string> fileNames;
+ AccelerationStructure *as = new DynBVH();
+ bool interpolateNormals = false;
+ bool smoothAnimation = false;
+ float animationLength = 5; //in seconds
+
+ bool setModel = false;
+
+ int argc = static_cast<int>(args.size());
+ for(int i=0;i<argc;i++){
+ string arg = args[i];
+ if(arg == "-model"){
+ fileNames.push_back("");
+ if(!getStringArg(i, args, fileNames.back()))
+ throw IllegalArgument("scene MeshLoader -model", i, args);
+ setModel = true;
+ } else if (arg == "-DynBVH") {
+ delete as;
+ as = new DynBVH;
+ } else if (arg == "-CGT") {
+#ifdef USE_PRIVATE_CODE
+ delete as;
+ as = new Grid;
+#else
+ throw IllegalArgument("CGT is not available to you.", i, args);
+#endif
+ } else if (arg == "-animationLength") {
+ if(!getArg<float>(i, args, animationLength))
+ throw IllegalArgument("scene MeshLoader -animationLength", i, args);
+ } else if (arg == "-interpolateNormals") {
+ interpolateNormals = true;
+ } else if (arg == "-smoothAnimation") {
+ smoothAnimation = true;
+ }
+ else {
+ if(arg[0] == '-' || !setModel) {
+ cerr << "Valid options for scene meshViewer:\n";
+ cerr << " -DynBVH - use DynBVH acceleration structure\n";
+#ifdef USE_PRIVATE_CODE
+ cerr << " -CGT - use Coherent Grid Traversal acceleration
structure\n";
+#endif
+ cerr << " -model - The file to load (obj or ply file)\n";
+ cerr << " Can call this multiple times to load an
animation.\n";
+ cerr << " -animationLength - Number of seconds animation takes\n";
+ cerr << " -interpolateNormals - creates vertex normals if the data
does"
+ << " not already contain vertex normals.\n";
+ cerr << " -smoothAnimation - interpolates between keyframes.\n";
+ throw IllegalArgument("scene primtest", i, args);
+ }
+ }
+ }
+
+ 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();
+ //read in data from modelName and
+ ifstream in(modelName.c_str());
+ while (in) {
+ in >> modelName;
+ fileNames.push_back(modelName);
+ }
+ }
+
+ 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;
+ AffineTransform t;
+ t.initWithScale(Vector(1, 1, 1));
+ if (!readPlyFile(modelName, t, frame, NULL))
+ 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());
+ }
+ if (interpolateNormals && !frame->hasVertexNormals())
+ frame->interpolateNormals();
+ animation->push_back(frame);
+ }
+
+ animation->setDuration(animationLength);
+ animation->startAnimation();
+
+ Scene* scene = new Scene();
+// scene->setBackground(new LinearBackground(Color(RGB(0.2, 0.4, 0.9)),
+// Color(RGB(0.0,0.0,0.0)),
+// Vector(0,1,0)));
+ scene->setBackground(new ConstantBackground(Color(RGB(0.1, 0.1, 0.1))));
+
+ scene->setObject(group);
+
+ LightSet* lights = new LightSet();
+ lights->add(new PointLight(Vector(900,400,100), Color(RGB(1,1,1))*1));
+ Color cup(RGB(0.3, 0.3, 0.3));
+ Color cdown(RGB(0.62, 0.62, 0.62));
+ Vector up(0,1,0);
+ lights->setAmbientLight(new ArcAmbient(cup, cdown, up));
+ scene->setLights(lights);
+ return scene;
+}
- [MANTA] r1475 - in trunk: Model/Groups scenes, thiago, 07/16/2007
Archive powered by MHonArc 2.6.16.