26#define MAGICNUMBER 0xB3D0
29#define CHUNKMAIN 0x4D4D
30#define CHUNKMAINVERSION 0x0002
32#define CHUNK3DVERSION 0x3D3E
33#define CHUNK3DOBJECT 0x4000
34#define CHUNK3DOBJECTMESH 0x4100
35#define CHUNK3DOBJECTMESHVERTICES 0x4110
36#define CHUNK3DOBJECTMESHFACES 0x4120
37#define CHUNK3DOBJECTMESHMATGROUP 0x4130
38#define CHUNK3DOBJECTMESHMAPPING 0x4140
40#define CHUNK3DMATERIAL 0xAFFF
43#define MATDIFFUSE 0xA020
44#define MATSPECULAR 0xA030
45#define MATTRANSPARENCY 0xA050
48#define COLOR_24 0x0011
49#define LIN_COLOR_24 0x0012
50#define LIN_COLOR_F 0x0013
51#define INT_PERCENTAGE 0x0030
52#define FLOAT_PERCENTAGE 0x0031
65 color[0] = color[1] = color[2] = 0;
73typedef struct _Chunk {
79typedef struct _Vertex {
103 numverts = numfaces = 0;
106 if (vlist != 0)
delete [] vlist;
107 if (flist != 0)
delete [] flist;
112Int_t ReadChunk(FILE*, Chunk*);
115Int_t ReadMainChunk(FILE*);
119Int_t ReadVerticesChunk(FILE*);
120Int_t ReadFacesChunk(FILE*);
121Int_t ReadMappingChunk(FILE*);
122Int_t ReadASCIIZ(FILE*,
char*);
126Int_t ReadObjectMaterial(FILE *);
133Int_t nummaterials = 0;
134Material *material[1024];
137Int_t Read3DSFile(
const char *fname)
143 infile = fopen(fname,
"rb");
145 printf(
"Error : Input File Could Not Be Opened!\n");
149 if (ReadMainChunk(infile) != 0) {
150 printf(
"Error : Input File Could Not Be Read!\n");
157Int_t ReadChunk(FILE *
f, Chunk *
c)
161 if (feof(
f))
return(-1);
163 c->offset =
c->len = 0;
166 fread(&
c->len,
sizeof(
UInt_t), 1,
f);
167 c->endoffset =
c->offset +
c->len;
172Int_t ReadMainChunk(FILE *
f)
178 ReadChunk(
f, &chunk);
179 if (chunk.idnum != CHUNKMAIN)
return(-1);
180 while ((ReadChunk(
f, &chunk) == 0) && (!feof(
f))) {
181 if (chunk.idnum == CHUNK3D) {
182 Read3DChunk(
f, chunk.endoffset);
186 fseek(
f, chunk.offset + chunk.len, SEEK_SET);
199 while ((ReadChunk(
f, &chunk) == 0) && (!feof(
f))) {
200 if (chunk.idnum == CHUNK3DOBJECT) {
201 ReadObjectChunk(
f, chunk.endoffset);
202 fseek(
f, chunk.endoffset, SEEK_SET);
204 else if (chunk.idnum == CHUNK3DMATERIAL) {
205 ReadMaterialChunk(
f, chunk.endoffset);
206 fseek(
f, chunk.endoffset, SEEK_SET);
209 if (chunk.endoffset <
len) {
211 fseek(
f, chunk.endoffset, SEEK_SET);
228 material[nummaterials] =
new Material();
229 while ((ReadChunk(
f, &chunk) == 0) && (!feof(
f))) {
230 if (chunk.idnum == MATNAME) {
232 strcpy(material[nummaterials]->
name,
name);
233 fseek(
f, chunk.endoffset, SEEK_SET);
235 else if (chunk.idnum == MATDIFFUSE) {
236 ReadColor(
f, chunk.endoffset);
237 fseek(
f, chunk.endoffset, SEEK_SET);
239 else if (chunk.idnum == MATTRANSPARENCY) {
240 ReadTransparency(
f, chunk.endoffset);
241 fseek(
f, chunk.endoffset, SEEK_SET);
244 if (chunk.endoffset <
len) {
246 fseek(
f, chunk.endoffset, SEEK_SET);
264 while ((ReadChunk(
f, &chunk) == 0) && (!feof(
f))) {
265 if (chunk.idnum == LIN_COLOR_24) {
266 fread(&material[nummaterials]->color[0],
sizeof(
UChar_t), 1,
f);
267 fread(&material[nummaterials]->color[1],
sizeof(
UChar_t), 1,
f);
268 fread(&material[nummaterials]->color[2],
sizeof(
UChar_t), 1,
f);
269 fseek(
f, chunk.endoffset, SEEK_SET);
271 else if (chunk.idnum == COLOR_24) {
272 fread(&material[nummaterials]->color[0],
sizeof(
UChar_t), 1,
f);
273 fread(&material[nummaterials]->color[1],
sizeof(
UChar_t), 1,
f);
274 fread(&material[nummaterials]->color[2],
sizeof(
UChar_t), 1,
f);
275 fseek(
f, chunk.endoffset, SEEK_SET);
277 else if (chunk.idnum == LIN_COLOR_F) {
281 fseek(
f, chunk.endoffset, SEEK_SET);
283 else if (chunk.idnum == COLOR_F) {
287 fseek(
f, chunk.endoffset, SEEK_SET);
290 if (chunk.endoffset <
len) {
292 fseek(
f, chunk.endoffset, SEEK_SET);
310 while ((ReadChunk(
f, &chunk) == 0) && (!feof(
f))) {
311 if (chunk.idnum == INT_PERCENTAGE) {
313 material[nummaterials]->transparency = stransp;
314 fseek(
f, chunk.endoffset, SEEK_SET);
316 else if (chunk.idnum == FLOAT_PERCENTAGE) {
317 fread(&ftransp,
sizeof(
float), 1,
f);
318 fseek(
f, chunk.endoffset, SEEK_SET);
321 if (chunk.endoffset <
len) {
323 fseek(
f, chunk.endoffset, SEEK_SET);
334Int_t ReadObjectMaterial(FILE *
f)
338 ReadASCIIZ(
f, model.matname);
350 while ((ReadChunk(
f, &chunk) == 0) && (!feof(
f))) {
351 if (chunk.idnum == CHUNK3DOBJECTMESH) {
352 ReadMeshChunk(
f, chunk.endoffset,
name);
355 if (chunk.endoffset <
len) {
357 fseek(
f, chunk.endoffset, SEEK_SET);
375 model.numverts = model.numfaces = 0;
376 sprintf(model.name,
"%s", objname);
377 printf(
"Reading Mesh : %s\n", objname);
378 while ((ReadChunk(
f, &chunk) == 0) && (!feof(
f))) {
379 if (chunk.idnum == CHUNK3DOBJECTMESHVERTICES) {
380 ReadVerticesChunk(
f);
382 else if (chunk.idnum == CHUNK3DOBJECTMESHFACES) {
385 else if (chunk.idnum == CHUNK3DOBJECTMESHMAPPING) {
388 else if (chunk.idnum == CHUNK3DOBJECTMESHMATGROUP) {
389 ReadObjectMaterial(
f);
392 if (chunk.endoffset <
len) {
394 fseek(
f, chunk.endoffset, SEEK_SET);
402 if (model.vlist != 0)
delete [] model.vlist;
403 if (model.flist != 0)
delete [] model.flist;
406 model.numverts = model.numfaces = 0;
407 sprintf(model.name,
"");
413Int_t ReadVerticesChunk(FILE *
f)
422 printf(
"Reading %i Vertices...", numv);
423 model.vlist =
new Vertex[numv];
424 if (model.vlist == 0) {
425 for (i = 0; i < numv; i++) {
430 printf(
"\nWarning : Insufficient Memory to Load Vertices!\n");
433 for (i = 0; i < numv; i++) {
434 fread(&model.vlist[i].x,
sizeof(
Float_t), 1,
f);
435 fread(&model.vlist[i].y,
sizeof(
Float_t), 1,
f);
436 fread(&model.vlist[i].z,
sizeof(
Float_t), 1,
f);
438 model.numverts = (
UInt_t) numv;
444Int_t ReadFacesChunk(FILE *
f)
452 printf(
"Reading %i Faces...", numf);
453 model.flist =
new Face[numf];
454 if (model.flist == 0) {
455 for (i = 0; i < numf; i++) {
461 printf(
"\nWarning : Insufficient Memory to Load Faces!\n");
464 for (i = 0; i < numf; i++) {
473 model.numfaces = (
UInt_t)(numf);
479Int_t ReadMappingChunk(FILE *
f)
487 printf(
"Reading %i Texture Coordinates...", numuv);
488 if (numuv != model.numverts) {
489 for (i = 0; i < numuv; i++) {
493 printf(
"\nWarning : Number of Vertices and Mapping Data do not match!\n");
496 for (i = 0; i < numuv; i++) {
497 fread(&model.vlist[i].u,
sizeof(
Float_t), 1,
f);
498 fread(&model.vlist[i].v,
sizeof(
Float_t), 1,
f);
513 fread(&
c,
sizeof(
char), 1,
f);
520 }
while ((
c != 0) && (!feof(
f)));
532 if (ts[nummodels] == 0)
534 for (i=0; i<model.numverts; ++i) {
535 ts[nummodels]->
SetVertex(i, model.vlist[i].x, model.vlist[i].y,
538 for (i=0; i<model.numfaces; ++i) {
539 ts[nummodels]->
SetTriangle(i, model.flist[i].v1, model.flist[i].v2,
542 ts[nummodels]->
SetName(model.name);
545 for (i = 0; i < nummaterials; i++) {
546 if (strcmp(model.matname, material[i]->name) == 0) {
549 material[i]->color[1],
550 material[i]->color[2]);
558void view3ds(
const char *fname =
"nasashuttle.3ds")
565 for (i=0;i<2048;i++) ts[i] = 0;
566 for (i=0;i<1024;i++) material[i] = 0;
570 if (Read3DSFile(fname) == 0) {
574 for (i=0;i<nummodels;i++) {
583 for (i = 0; i < nummaterials; i++)
584 if (material[i] != 0)
delete material[i];
R__EXTERN TEveManager * gEve
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
virtual void AddElement(TEveElement *el)
Add el to the list of children.
virtual void SetMainTransparency(Char_t t)
Set main-transparency.
virtual TEveTrans & RefMainTrans()
Return reference to main transformation.
virtual void SetMainColor(Color_t color)
Set main color of the element.
void SetMainColorRGB(UChar_t r, UChar_t g, UChar_t b)
Convert RGB values to Color_t and call SetMainColor.
void AddElement(TEveElement *element, TEveElement *parent=nullptr)
Add an element.
static TEveManager * Create(Bool_t map_window=kTRUE, Option_t *opt="FIV")
If global TEveManager* gEve is not set initialize it.
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
void RotateLF(Int_t i1, Int_t i2, Double_t amount)
Rotate in local frame. Does optimised version of MultRight.
Made from a list of vertices and a list of triangles (triplets of vertex indices).
void SetTriangle(Int_t i, Int_t v0, Int_t v1, Int_t v2)
void SetVertex(Int_t i, Float_t x, Float_t y, Float_t z)
void GenerateTriangleNormals()
Generate triangle normals via cross product of triangle edges.
virtual void SetName(const char *name)
Set the name of the TNamed.
void Vertex(const Double_t *v)