vcglib/apps/nexus/patch.h

105 lines
2.5 KiB
C
Raw Normal View History

2004-07-02 15:00:02 +02:00
#ifndef NXS_PATCH_H
#define NXS_PATCH_H
#include <vcg/space/point3.h>
2004-10-08 17:12:04 +02:00
#include <vcg/space/sphere3.h>
2004-07-02 15:00:02 +02:00
namespace nxs {
2004-10-01 01:56:33 +02:00
enum Signature { NXS_FACES = 0x00000001,
2004-09-30 02:27:42 +02:00
NXS_STRIP = 0x00000002,
NXS_COLORS = 0x00000010,
NXS_NORMALS_SHORT = 0x00000100,
NXS_NORMALS_FLOAT = 0x00000200,
NXS_TEXTURES_SHORT = 0x00001000,
NXS_TEXTURES_FLOAT = 0x00002000,
NXS_DATA8 = 0x00010000,
NXS_DATA16 = 0x00020000,
NXS_DATA32 = 0x00040000,
NXS_DATA64 = 0x00080000,
NXS_COMPRESSED = 0x10000000};
2004-09-17 17:25:59 +02:00
2004-07-02 15:00:02 +02:00
2004-09-17 17:25:59 +02:00
2004-07-02 15:00:02 +02:00
class Patch {
public:
2004-09-16 16:25:16 +02:00
2004-10-08 17:12:04 +02:00
Patch(Signature signature, char *s,
2004-09-17 17:25:59 +02:00
unsigned short nv, unsigned short nf);
2004-07-02 19:42:43 +02:00
2004-09-17 17:25:59 +02:00
void Init(Signature signature, unsigned short nv, unsigned short nf);
2004-07-02 15:00:02 +02:00
2004-09-17 17:25:59 +02:00
inline vcg::Point3f *VertBegin();
inline unsigned short *FaceBegin();
inline vcg::Point3f &Vert(unsigned short v);
inline unsigned short *Face(unsigned short f);
2004-09-30 02:27:42 +02:00
inline unsigned int *ColorBegin();
inline short *Norm16Begin();
inline short *Norm16(unsigned short v);
2004-10-01 01:56:33 +02:00
inline vcg::Point3f *Norm32Begin();
inline vcg::Point3f &Norm32(unsigned short v);
2004-09-17 17:25:59 +02:00
2004-09-16 16:25:16 +02:00
static unsigned int ChunkSize(Signature signature,
2004-09-17 17:25:59 +02:00
unsigned short nvert,
2004-10-08 17:12:04 +02:00
unsigned short nface,
unsigned int chunk_size);
2004-07-02 15:00:02 +02:00
2004-09-16 16:25:16 +02:00
static unsigned int ByteSize(Signature signature,
2004-09-17 17:25:59 +02:00
unsigned short nvert,
unsigned short nface);
2004-10-10 19:19:42 +02:00
char *Compress(unsigned int ram_size, unsigned int &size);
void Decompress(unsigned int ram_size, void *src, unsigned int src_sz);
2004-07-02 15:00:02 +02:00
2004-09-17 17:25:59 +02:00
unsigned short nv;
unsigned short nf;
2004-10-10 19:19:42 +02:00
char *start;
2004-09-17 17:25:59 +02:00
float *vstart;
2004-09-30 02:27:42 +02:00
//these offset are from vstart!
2004-09-17 17:25:59 +02:00
unsigned short cstart;
unsigned short nstart;
unsigned short tstart;
unsigned short dstart;
2004-07-02 15:00:02 +02:00
};
2004-09-17 17:25:59 +02:00
inline vcg::Point3f *Patch::VertBegin() {
return (vcg::Point3f *)vstart;
}
inline unsigned short *Patch::FaceBegin() {
return (unsigned short *)start;
}
inline vcg::Point3f &Patch::Vert(unsigned short v) {
return VertBegin()[v];
}
inline unsigned short *Patch::Face(unsigned short f) {
return FaceBegin() + f * 3;
}
2004-09-30 02:27:42 +02:00
inline unsigned int *Patch::ColorBegin() {
2004-10-01 18:54:57 +02:00
return (unsigned int *)(vstart + cstart);
2004-09-30 02:27:42 +02:00
}
inline short *Patch::Norm16Begin() {
2004-10-01 18:54:57 +02:00
return (short *)(vstart + nstart);
2004-09-30 02:27:42 +02:00
}
inline short *Patch::Norm16(unsigned short v) {
return Norm16Begin() + 4 * v;
}
2004-10-01 01:56:33 +02:00
inline vcg::Point3f *Patch::Norm32Begin() {
2004-10-01 18:54:57 +02:00
return (vcg::Point3f *)(vstart + nstart);
2004-10-01 01:56:33 +02:00
}
inline vcg::Point3f &Patch::Norm32(unsigned short v) {
return Norm32Begin()[v];
}
2004-09-17 17:25:59 +02:00
} //namespace
2004-07-02 15:00:02 +02:00
#endif