From 430070f9fd690f13140ea179addb4ff54b8998dd Mon Sep 17 00:00:00 2001 From: ponchio Date: Thu, 30 Sep 2004 23:56:33 +0000 Subject: [PATCH] Backup (added strips and normals) --- apps/nexus/nexusmt.cpp | 7 ++-- apps/nexus/nexusmt.h | 4 +-- apps/nexus/nexusview.cpp | 5 +++ apps/nexus/nxsedit.cpp | 73 +++++++++++++++++----------------------- apps/nexus/patch.h | 12 +++++-- apps/nexus/vfile.h | 7 ++-- 6 files changed, 58 insertions(+), 50 deletions(-) diff --git a/apps/nexus/nexusmt.cpp b/apps/nexus/nexusmt.cpp index efe66a28..e2f6150b 100644 --- a/apps/nexus/nexusmt.cpp +++ b/apps/nexus/nexusmt.cpp @@ -84,11 +84,12 @@ void NexusMt::Render() { //TODO textures and data. for(unsigned int i = 0; i < cells.size(); i++) { - Nexus::Entry &entry = index[cells[i]]; + unsigned int cell = cells[i]; + Nexus::Entry &entry = index[cell]; //frustum culling // if(frustum.Outside(entry.sphere.center, entry.sphere.radius)) // continue; - Patch patch = GetPatch(cells[i]); + Patch patch = GetPatch(cell); glVertexPointer(3, GL_FLOAT, 0, patch.VertBegin()); if(use_colors) glColorPointer(4, GL_UNSIGNED_BYTE, 0, patch.ColorBegin()); @@ -97,6 +98,8 @@ void NexusMt::Render() { switch(mode) { case POINTS: glDrawArrays(GL_POINTS, 0, patch.nv); break; + case DEBUG: + glColor3ub((cell * 27)%255, (cell * 37)%255, (cell * 87)%255); case SMOOTH: if(signature & NXS_FACES) glDrawElements(GL_TRIANGLES, patch.nf * 3, diff --git a/apps/nexus/nexusmt.h b/apps/nexus/nexusmt.h index e2b91659..638b9895 100644 --- a/apps/nexus/nexusmt.h +++ b/apps/nexus/nexusmt.h @@ -57,7 +57,8 @@ class NexusMt: public Nexus { XRAY, HIDDEN_LINE, FLAT_WIRE, - FLAT}; + FLAT, + DEBUG }; enum Component { COLOR = 0x1, NORMAL = 0x2, @@ -79,7 +80,6 @@ class NexusMt: public Nexus { bool use_textures; bool use_data; - NexusMt(); bool Load(const std::string &filename); diff --git a/apps/nexus/nexusview.cpp b/apps/nexus/nexusview.cpp index 910f170d..65a7c51d 100644 --- a/apps/nexus/nexusview.cpp +++ b/apps/nexus/nexusview.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.8 2004/09/30 00:27:42 ponchio +Lot of changes. Backup. + Revision 1.7 2004/09/28 10:26:35 ponchio Backup @@ -185,6 +188,7 @@ int main(int argc, char *argv[]) { glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); glEnable(GL_COLOR_MATERIAL); + glEnable(GL_CULL_FACE); int quit = 0; SDL_Event event; int x, y; @@ -268,6 +272,7 @@ int main(int argc, char *argv[]) { Point3f center = sphere.Center(); glTranslatef(-center[0], -center[1], -center[2]); + nexus.SetMode(NexusMt::DEBUG); nexus.SetPolicy(NexusMt::FRUSTUM, error); nexus.SetComponent(NexusMt::COLOR, show_colors); nexus.SetComponent(NexusMt::NORMAL, show_normals); diff --git a/apps/nexus/nxsedit.cpp b/apps/nexus/nxsedit.cpp index f544e5a1..6261169b 100644 --- a/apps/nexus/nxsedit.cpp +++ b/apps/nexus/nxsedit.cpp @@ -1,6 +1,7 @@ #include using namespace std; +#include "nxsalgo.h" #include "nexus.h" using namespace nxs; @@ -238,55 +239,42 @@ int main(int argc, char *argv[]) { Patch src_patch = nexus.GetPatch(patch); Border src_border = nexus.GetBorder(patch); - out.AddPatch(src_entry.nvert, src_entry.nface, src_entry.border_size); + + vector strip; + if(add_strip) { + ComputeTriStrip(src_patch.nf, src_patch.FaceBegin(), strip); + out.AddPatch(src_entry.nvert, strip.size(), src_entry.border_size); + } else + out.AddPatch(src_entry.nvert, src_entry.nface, src_entry.border_size); + Nexus::Entry &dst_entry = out.index[patch]; Patch dst_patch = out.GetPatch(patch); Border dst_border = out.GetBorder(patch); + //copy vertices: //no clustering memcpy(dst_patch.VertBegin(), src_patch.VertBegin(), src_patch.nv * sizeof(Point3f)); //now faces. if(add_strip) { - cerr << "Unsupported strips\n"; - return -1; + memcpy(dst_patch.FaceBegin(), &*strip.begin(), + strip.size() * sizeof(short)); } else { memcpy(dst_patch.FaceBegin(), src_patch.FaceBegin(), src_patch.nf * sizeof(unsigned short) *3); } - if(add_colors) { - //source of color: - cerr << "Unsupported color\n"; - return -1; - } - if(add_normals) { - vector normals; - normals.resize(dst_patch.nv, Point3f(0, 0, 0)); + if((nexus.signature & NXS_COLORS) && (out.signature & NXS_COLORS)) + memcpy(dst_patch.ColorBegin(), src_patch.ColorBegin(), + src_patch.nv * sizeof(unsigned int)); - for(unsigned int i = 0; i < dst_patch.nf; i++) { - unsigned short *f = dst_patch.Face(i); - Point3f &v0 = dst_patch.Vert(f[0]); - Point3f &v1 = dst_patch.Vert(f[1]); - Point3f &v2 = dst_patch.Vert(f[2]); - - Point3f norm = (v1 - v0) ^ (v2 - v0); - normals[f[0]] += norm; - normals[f[1]] += norm; - normals[f[2]] += norm; - } - for(unsigned int i = 0; i < dst_patch.nv; i++) { - Point3f &norm = normals[i]; - norm.Normalize(); - short *n = dst_patch.Norm16(i); - for(int k = 0; k < 3; k++) { - n[k] = (short)(norm[k] * 32766); - } - n[3] = 0; - } - } + if((nexus.signature & NXS_NORMALS_SHORT) && + (out.signature & NXS_NORMALS_SHORT)) + memcpy(dst_patch.Norm16Begin(), src_patch.Norm16Begin(), + src_patch.nv * sizeof(short)*4); + //copying entry information; dst_entry.sphere = src_entry.sphere; @@ -297,17 +285,18 @@ int main(int argc, char *argv[]) { memcpy(dst_border.Start(), src_border.Start(), src_border.Size() * sizeof(Link)); } - - //TODO !!! FIX NORMALS ACROSS BORDERS - /* - for(unsigned int patch = 0; patch < nexus.index.size(); patch++) { - for(unsigned int i = 0; i < dst_border.Size(); i++) { - Link &link = dst_border[i]; - //we just make the mean... - } - } - */ + //TODO this is ok only if we have faces still! + if(add_normals) { + cerr << "Computing normals" << endl; + ComputeNormals(out); + } + + if(add_colors) { + //source of color: + cerr << "Unsupported color\n"; + return -1; + } //fixing sphere. out.sphere = nexus.sphere; diff --git a/apps/nexus/patch.h b/apps/nexus/patch.h index d4b0e7be..57cec6dd 100644 --- a/apps/nexus/patch.h +++ b/apps/nexus/patch.h @@ -5,8 +5,7 @@ #include namespace nxs { -enum Signature { NXS_DEFAULT = 0x00000000, - NXS_FACES = 0x00000001, +enum Signature { NXS_FACES = 0x00000001, NXS_STRIP = 0x00000002, NXS_COLORS = 0x00000010, NXS_NORMALS_SHORT = 0x00000100, @@ -41,6 +40,8 @@ class Patch { inline unsigned int *ColorBegin(); inline short *Norm16Begin(); inline short *Norm16(unsigned short v); + inline vcg::Point3f *Norm32Begin(); + inline vcg::Point3f &Norm32(unsigned short v); static unsigned int ChunkSize(Signature signature, unsigned short nvert, @@ -90,6 +91,13 @@ inline short *Patch::Norm16(unsigned short v) { return Norm16Begin() + 4 * v; } + inline vcg::Point3f *Patch::Norm32Begin() { + return (vcg::Point3f *)(((char *)vstart) + nstart); + } + inline vcg::Point3f &Patch::Norm32(unsigned short v) { + return Norm32Begin()[v]; + } + } //namespace #endif diff --git a/apps/nexus/vfile.h b/apps/nexus/vfile.h index d1245e33..c9650f3d 100644 --- a/apps/nexus/vfile.h +++ b/apps/nexus/vfile.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.9 2004/07/20 14:04:32 ponchio +Improved efficience in operator[] + Revision 1.8 2004/07/15 14:32:49 ponchio Debug. @@ -294,7 +297,7 @@ template class VFile { 1)region must be Chunk aligned. 2)you get impredictable results if regions overlap or mix with operator[] */ - T *GetRegion(unsigned int start, unsigned int size) { + T *GetRegion(unsigned int start, unsigned int size, bool flush = true) { assert(start + size <= n_elements); assert((size % chunk_size) == 0); assert((start % chunk_size) == 0); @@ -305,7 +308,7 @@ template class VFile { if(index.count(chunk)) return ((*(index[chunk])).data); - if(buffers.size() > queue_size) { + while(flush && buffers.size() > queue_size) { Buffer &buffer= buffers.back(); FlushBuffer(buffer); index.erase(buffer.key);