1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2015, assimp team
6 All rights reserved.
7 
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
11 
12 * Redistributions of source code must retain the above
13   copyright notice, this list of conditions and the
14   following disclaimer.
15 
16 * Redistributions in binary form must reproduce the above
17   copyright notice, this list of conditions and the
18   following disclaimer in the documentation and/or other
19   materials provided with the distribution.
20 
21 * Neither the name of the assimp team, nor the names of its
22   contributors may be used to endorse or promote products
23   derived from this software without specific prior
24   written permission of the assimp team.
25 
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 
38 ----------------------------------------------------------------------
39 */
40 
41 /** @file  BlenderScene.h
42  *  @brief Intermediate representation of a BLEND scene.
43  */
44 #ifndef INCLUDED_AI_BLEND_SCENE_H
45 #define INCLUDED_AI_BLEND_SCENE_H
46 
47 #include "BlenderDNA.h"
48 
49 namespace Assimp    {
50     namespace Blender {
51 
52 // Minor parts of this file are extracts from blender data structures,
53 // declared in the ./source/blender/makesdna directory.
54 // Stuff that is not used by Assimp is commented.
55 
56 
57 // NOTE
58 // this file serves as input data to the `./scripts/genblenddna.py`
59 // script. This script generates the actual binding code to read a
60 // blender file with a possibly different DNA into our structures.
61 // Only `struct` declarations are considered and the following
62 // rules must be obeyed in order for the script to work properly:
63 //
64 // * C++ style comments only
65 //
66 // * Structures may include the primitive types char, int, short,
67 //   float, double. Signedness specifiers are not allowed on
68 //   integers. Enum types are allowed, but they must have been
69 //   defined in this header.
70 //
71 // * Structures may aggregate other structures, unless not defined
72 //   in this header.
73 //
74 // * Pointers to other structures or primitive types are allowed.
75 //   No references or double pointers or arrays of pointers.
76 //   A pointer to a T is normally written as boost::shared_ptr, while a
77 //   pointer to an array of elements is written as boost::
78 //   shared_array. To avoid cyclic pointers, use raw pointers in
79 //   one direction.
80 //
81 // * Arrays can have maximally two-dimensions. Any non-pointer
82 //   type can form them.
83 //
84 // * Multiple fields can be declare in a single line (i.e `int a,b;`)
85 //   provided they are neither pointers nor arrays.
86 //
87 // * One of WARN, FAIL can be appended to the declaration (
88 //   prior to the semiolon to specifiy the error handling policy if
89 //   this field is missing in the input DNA). If none of those
90 //   is specified the default policy is to subtitute a default
91 //   value for the field.
92 //
93 
94 #define WARN // warn if field is missing, substitute default value
95 #define FAIL // fail the import if the field does not exist
96 
97 struct Object;
98 struct MTex;
99 struct Image;
100 
101 #define AI_BLEND_MESH_MAX_VERTS 2000000000L
102 
103 // -------------------------------------------------------------------------------
104 struct ID : ElemBase {
105 
106     char name[1024] WARN;
107     short flag;
108 };
109 
110 // -------------------------------------------------------------------------------
111 struct ListBase : ElemBase {
112 
113     boost::shared_ptr<ElemBase> first;
114     boost::shared_ptr<ElemBase> last;
115 };
116 
117 
118 // -------------------------------------------------------------------------------
119 struct PackedFile : ElemBase {
120      int size WARN;
121      int seek WARN;
122      boost::shared_ptr< FileOffset > data WARN;
123 };
124 
125 // -------------------------------------------------------------------------------
126 struct GroupObject : ElemBase {
127 
128     boost::shared_ptr<GroupObject> prev,next FAIL;
129     boost::shared_ptr<Object> ob;
130 };
131 
132 // -------------------------------------------------------------------------------
133 struct Group : ElemBase {
134     ID id FAIL;
135     int layer;
136 
137     boost::shared_ptr<GroupObject> gobject;
138 };
139 
140 // -------------------------------------------------------------------------------
141 struct World : ElemBase {
142     ID id FAIL;
143 
144 };
145 
146 // -------------------------------------------------------------------------------
147 struct MVert : ElemBase {
148     float co[3] FAIL;
149     float no[3] FAIL;
150     char flag;
151     int mat_nr WARN;
152     int bweight;
153 };
154 
155 // -------------------------------------------------------------------------------
156 struct MEdge : ElemBase {
157       int v1, v2 FAIL;
158       char crease, bweight;
159       short flag;
160 };
161 
162 // -------------------------------------------------------------------------------
163 struct MLoop : ElemBase {
164     int v, e;
165 };
166 
167 // -------------------------------------------------------------------------------
168 struct MLoopUV : ElemBase {
169     float uv[2];
170     int flag;
171 };
172 
173 // -------------------------------------------------------------------------------
174 // Note that red and blue are not swapped, as with MCol
175 struct MLoopCol : ElemBase {
176     char r, g, b, a;
177 };
178 
179 // -------------------------------------------------------------------------------
180 struct MPoly : ElemBase {
181     int loopstart;
182     int totloop;
183     short mat_nr;
184     char flag;
185 };
186 
187 // -------------------------------------------------------------------------------
188 struct MTexPoly : ElemBase {
189     Image* tpage;
190     char flag, transp;
191     short mode, tile, pad;
192 };
193 
194 // -------------------------------------------------------------------------------
195 struct MCol : ElemBase {
196     char r,g,b,a FAIL;
197 };
198 
199 // -------------------------------------------------------------------------------
200 struct MFace : ElemBase {
201     int v1,v2,v3,v4 FAIL;
202     int mat_nr FAIL;
203     char flag;
204 };
205 
206 // -------------------------------------------------------------------------------
207 struct TFace : ElemBase {
208     float uv[4][2] FAIL;
209     int col[4] FAIL;
210     char flag;
211     short mode;
212     short tile;
213     short unwrap;
214 };
215 
216 // -------------------------------------------------------------------------------
217 struct MTFace : ElemBase {
218 
219     float uv[4][2] FAIL;
220     char flag;
221     short mode;
222     short tile;
223     short unwrap;
224 
225     // boost::shared_ptr<Image> tpage;
226 };
227 
228 // -------------------------------------------------------------------------------
229 struct MDeformWeight : ElemBase  {
230       int    def_nr FAIL;
231       float  weight FAIL;
232 };
233 
234 // -------------------------------------------------------------------------------
235 struct MDeformVert : ElemBase  {
236 
237     vector<MDeformWeight> dw WARN;
238     int totweight;
239 };
240 
241 // -------------------------------------------------------------------------------
242 struct Material : ElemBase {
243     ID id FAIL;
244 
245     float r,g,b WARN;
246     float specr,specg,specb WARN;
247     short har;
248     float ambr,ambg,ambb WARN;
249     float mirr,mirg,mirb;
250     float emit WARN;
251     float alpha WARN;
252     float ref;
253     float translucency;
254     float roughness;
255     float darkness;
256     float refrac;
257 
258     boost::shared_ptr<Group> group;
259 
260     short diff_shader WARN;
261     short spec_shader WARN;
262 
263     boost::shared_ptr<MTex> mtex[18];
264 };
265 
266 // -------------------------------------------------------------------------------
267 struct Mesh : ElemBase {
268     ID id FAIL;
269 
270     int totface FAIL;
271     int totedge FAIL;
272     int totvert FAIL;
273     int totloop;
274     int totpoly;
275 
276     short subdiv;
277     short subdivr;
278     short subsurftype;
279     short smoothresh;
280 
281     vector<MFace> mface FAIL;
282     vector<MTFace> mtface;
283     vector<TFace> tface;
284     vector<MVert> mvert FAIL;
285     vector<MEdge> medge WARN;
286     vector<MLoop> mloop;
287     vector<MLoopUV> mloopuv;
288     vector<MLoopCol> mloopcol;
289     vector<MPoly> mpoly;
290     vector<MTexPoly> mtpoly;
291     vector<MDeformVert> dvert;
292     vector<MCol> mcol;
293 
294     vector< boost::shared_ptr<Material> > mat FAIL;
295 };
296 
297 // -------------------------------------------------------------------------------
298 struct Library : ElemBase {
299     ID id FAIL;
300 
301     char name[240] WARN;
302     char filename[240] FAIL;
303     boost::shared_ptr<Library> parent WARN;
304 };
305 
306 // -------------------------------------------------------------------------------
307 struct Camera : ElemBase {
308     enum Type {
309           Type_PERSP    =   0
310          ,Type_ORTHO    =   1
311     };
312 
313     ID id FAIL;
314 
315     // struct AnimData *adt;
316 
317     Type type,flag WARN;
318     float angle WARN;
319     //float passepartalpha, angle;
320     //float clipsta, clipend;
321     //float lens, ortho_scale, drawsize;
322     //float shiftx, shifty;
323 
324     //float YF_dofdist, YF_aperture;
325     //short YF_bkhtype, YF_bkhbias;
326     //float YF_bkhrot;
327 };
328 
329 
330 // -------------------------------------------------------------------------------
331 struct Lamp : ElemBase {
332 
333     enum FalloffType {
334          FalloffType_Constant   = 0x0
335         ,FalloffType_InvLinear  = 0x1
336         ,FalloffType_InvSquare  = 0x2
337         //,FalloffType_Curve    = 0x3
338         //,FalloffType_Sliders  = 0x4
339     };
340 
341     enum Type {
342          Type_Local         = 0x0
343         ,Type_Sun           = 0x1
344         ,Type_Spot          = 0x2
345         ,Type_Hemi          = 0x3
346         ,Type_Area          = 0x4
347         //,Type_YFPhoton    = 0x5
348     };
349 
350       ID id FAIL;
351       //AnimData *adt;
352 
353       Type type FAIL;
354       short flags;
355 
356       //int mode;
357 
358       short colormodel, totex;
359       float r,g,b,k WARN;
360       //float shdwr, shdwg, shdwb;
361 
362       float energy, dist, spotsize, spotblend;
363       //float haint;
364 
365       float att1, att2;
366       //struct CurveMapping *curfalloff;
367       FalloffType falloff_type;
368 
369       //float clipsta, clipend, shadspotsize;
370       //float bias, soft, compressthresh;
371       //short bufsize, samp, buffers, filtertype;
372       //char bufflag, buftype;
373 
374       //short ray_samp, ray_sampy, ray_sampz;
375       //short ray_samp_type;
376       //short area_shape;
377       //float area_size, area_sizey, area_sizez;
378       //float adapt_thresh;
379       //short ray_samp_method;
380 
381       //short texact, shadhalostep;
382 
383       //short sun_effect_type;
384       //short skyblendtype;
385       //float horizon_brightness;
386       //float spread;
387       float sun_brightness;
388       //float sun_size;
389       //float backscattered_light;
390       //float sun_intensity;
391       //float atm_turbidity;
392       //float atm_inscattering_factor;
393       //float atm_extinction_factor;
394       //float atm_distance_factor;
395       //float skyblendfac;
396       //float sky_exposure;
397       //short sky_colorspace;
398 
399       // int YF_numphotons, YF_numsearch;
400       // short YF_phdepth, YF_useqmc, YF_bufsize, YF_pad;
401       // float YF_causticblur, YF_ltradius;
402 
403       // float YF_glowint, YF_glowofs;
404       // short YF_glowtype, YF_pad2;
405 
406       //struct Ipo *ipo;
407       //struct MTex *mtex[18];
408       // short pr_texture;
409 
410       //struct PreviewImage *preview;
411 };
412 
413 // -------------------------------------------------------------------------------
414 struct ModifierData : ElemBase  {
415     enum ModifierType {
416       eModifierType_None = 0,
417       eModifierType_Subsurf,
418       eModifierType_Lattice,
419       eModifierType_Curve,
420       eModifierType_Build,
421       eModifierType_Mirror,
422       eModifierType_Decimate,
423       eModifierType_Wave,
424       eModifierType_Armature,
425       eModifierType_Hook,
426       eModifierType_Softbody,
427       eModifierType_Boolean,
428       eModifierType_Array,
429       eModifierType_EdgeSplit,
430       eModifierType_Displace,
431       eModifierType_UVProject,
432       eModifierType_Smooth,
433       eModifierType_Cast,
434       eModifierType_MeshDeform,
435       eModifierType_ParticleSystem,
436       eModifierType_ParticleInstance,
437       eModifierType_Explode,
438       eModifierType_Cloth,
439       eModifierType_Collision,
440       eModifierType_Bevel,
441       eModifierType_Shrinkwrap,
442       eModifierType_Fluidsim,
443       eModifierType_Mask,
444       eModifierType_SimpleDeform,
445       eModifierType_Multires,
446       eModifierType_Surface,
447       eModifierType_Smoke,
448       eModifierType_ShapeKey
449     };
450 
451     boost::shared_ptr<ElemBase> next WARN;
452     boost::shared_ptr<ElemBase> prev WARN;
453 
454     int type, mode;
455     char name[32];
456 };
457 
458 // -------------------------------------------------------------------------------
459 struct SubsurfModifierData : ElemBase  {
460 
461     enum Type {
462 
463         TYPE_CatmullClarke = 0x0,
464         TYPE_Simple = 0x1
465     };
466 
467     enum Flags {
468         // some omitted
469         FLAGS_SubsurfUV     =1<<3
470     };
471 
472     ModifierData modifier FAIL;
473     short subdivType WARN;
474     short levels FAIL;
475     short renderLevels ;
476     short flags;
477 };
478 
479 // -------------------------------------------------------------------------------
480 struct MirrorModifierData : ElemBase {
481 
482     enum Flags {
483         Flags_CLIPPING      =1<<0,
484         Flags_MIRROR_U      =1<<1,
485         Flags_MIRROR_V      =1<<2,
486         Flags_AXIS_X        =1<<3,
487         Flags_AXIS_Y        =1<<4,
488         Flags_AXIS_Z        =1<<5,
489         Flags_VGROUP        =1<<6
490     };
491 
492     ModifierData modifier FAIL;
493 
494     short axis, flag;
495     float tolerance;
496     boost::shared_ptr<Object> mirror_ob;
497 };
498 
499 // -------------------------------------------------------------------------------
500 struct Object : ElemBase  {
501     ID id FAIL;
502 
503     enum Type {
504          Type_EMPTY     =   0
505         ,Type_MESH      =   1
506         ,Type_CURVE     =   2
507         ,Type_SURF      =   3
508         ,Type_FONT      =   4
509         ,Type_MBALL     =   5
510 
511         ,Type_LAMP      =   10
512         ,Type_CAMERA    =   11
513 
514         ,Type_WAVE      =   21
515         ,Type_LATTICE   =   22
516     };
517 
518     Type type FAIL;
519     float obmat[4][4] WARN;
520     float parentinv[4][4] WARN;
521     char parsubstr[32] WARN;
522 
523     Object* parent WARN;
524     boost::shared_ptr<Object> track WARN;
525 
526     boost::shared_ptr<Object> proxy,proxy_from,proxy_group WARN;
527     boost::shared_ptr<Group> dup_group WARN;
528     boost::shared_ptr<ElemBase> data FAIL;
529 
530     ListBase modifiers;
531 };
532 
533 
534 // -------------------------------------------------------------------------------
535 struct Base : ElemBase {
536     Base* prev WARN;
537     boost::shared_ptr<Base> next WARN;
538     boost::shared_ptr<Object> object WARN;
539 };
540 
541 // -------------------------------------------------------------------------------
542 struct Scene : ElemBase {
543     ID id FAIL;
544 
545     boost::shared_ptr<Object> camera WARN;
546     boost::shared_ptr<World> world WARN;
547     boost::shared_ptr<Base> basact WARN;
548 
549     ListBase base;
550 };
551 
552 
553 // -------------------------------------------------------------------------------
554 struct Image : ElemBase {
555     ID id FAIL;
556 
557     char name[240] WARN;
558 
559     //struct anim *anim;
560 
561     short ok, flag;
562     short source, type, pad, pad1;
563     int lastframe;
564 
565     short tpageflag, totbind;
566     short xrep, yrep;
567     short twsta, twend;
568     //unsigned int bindcode;
569     //unsigned int *repbind;
570 
571     boost::shared_ptr<PackedFile> packedfile;
572     //struct PreviewImage * preview;
573 
574     float lastupdate;
575     int lastused;
576     short animspeed;
577 
578     short gen_x, gen_y, gen_type;
579 };
580 
581 // -------------------------------------------------------------------------------
582 struct Tex : ElemBase {
583 
584     // actually, the only texture type we support is Type_IMAGE
585     enum Type {
586          Type_CLOUDS        = 1
587         ,Type_WOOD          = 2
588         ,Type_MARBLE        = 3
589         ,Type_MAGIC         = 4
590         ,Type_BLEND         = 5
591         ,Type_STUCCI        = 6
592         ,Type_NOISE         = 7
593         ,Type_IMAGE         = 8
594         ,Type_PLUGIN        = 9
595         ,Type_ENVMAP        = 10
596         ,Type_MUSGRAVE      = 11
597         ,Type_VORONOI       = 12
598         ,Type_DISTNOISE     = 13
599         ,Type_POINTDENSITY  = 14
600         ,Type_VOXELDATA     = 15
601     };
602 
603     enum ImageFlags {
604          ImageFlags_INTERPOL         = 1
605         ,ImageFlags_USEALPHA         = 2
606         ,ImageFlags_MIPMAP           = 4
607         ,ImageFlags_IMAROT           = 16
608         ,ImageFlags_CALCALPHA        = 32
609         ,ImageFlags_NORMALMAP        = 2048
610         ,ImageFlags_GAUSS_MIP        = 4096
611         ,ImageFlags_FILTER_MIN       = 8192
612         ,ImageFlags_DERIVATIVEMAP   = 16384
613     };
614 
615     ID id FAIL;
616     // AnimData *adt;
617 
618     //float noisesize, turbul;
619     //float bright, contrast, rfac, gfac, bfac;
620     //float filtersize;
621 
622     //float mg_H, mg_lacunarity, mg_octaves, mg_offset, mg_gain;
623     //float dist_amount, ns_outscale;
624 
625     //float vn_w1;
626     //float vn_w2;
627     //float vn_w3;
628     //float vn_w4;
629     //float vn_mexp;
630     //short vn_distm, vn_coltype;
631 
632     //short noisedepth, noisetype;
633     //short noisebasis, noisebasis2;
634 
635     //short flag;
636     ImageFlags imaflag;
637     Type type FAIL;
638     //short stype;
639 
640     //float cropxmin, cropymin, cropxmax, cropymax;
641     //int texfilter;
642     //int afmax;
643     //short xrepeat, yrepeat;
644     //short extend;
645 
646     //short fie_ima;
647     //int len;
648     //int frames, offset, sfra;
649 
650     //float checkerdist, nabla;
651     //float norfac;
652 
653     //ImageUser iuser;
654 
655     //bNodeTree *nodetree;
656     //Ipo *ipo;
657     boost::shared_ptr<Image> ima WARN;
658     //PluginTex *plugin;
659     //ColorBand *coba;
660     //EnvMap *env;
661     //PreviewImage * preview;
662     //PointDensity *pd;
663     //VoxelData *vd;
664 
665     //char use_nodes;
666 };
667 
668 // -------------------------------------------------------------------------------
669 struct MTex : ElemBase {
670 
671     enum Projection {
672          Proj_N = 0
673         ,Proj_X = 1
674         ,Proj_Y = 2
675         ,Proj_Z = 3
676     };
677 
678     enum Flag {
679          Flag_RGBTOINT      = 0x1
680         ,Flag_STENCIL       = 0x2
681         ,Flag_NEGATIVE      = 0x4
682         ,Flag_ALPHAMIX      = 0x8
683         ,Flag_VIEWSPACE     = 0x10
684     };
685 
686     enum BlendType {
687          BlendType_BLEND            = 0
688         ,BlendType_MUL              = 1
689         ,BlendType_ADD              = 2
690         ,BlendType_SUB              = 3
691         ,BlendType_DIV              = 4
692         ,BlendType_DARK             = 5
693         ,BlendType_DIFF             = 6
694         ,BlendType_LIGHT            = 7
695         ,BlendType_SCREEN           = 8
696         ,BlendType_OVERLAY          = 9
697         ,BlendType_BLEND_HUE        = 10
698         ,BlendType_BLEND_SAT        = 11
699         ,BlendType_BLEND_VAL        = 12
700         ,BlendType_BLEND_COLOR      = 13
701     };
702 
703     enum MapType {
704          MapType_COL         = 1
705         ,MapType_NORM        = 2
706         ,MapType_COLSPEC     = 4
707         ,MapType_COLMIR      = 8
708         ,MapType_REF         = 16
709         ,MapType_SPEC        = 32
710         ,MapType_EMIT        = 64
711         ,MapType_ALPHA       = 128
712         ,MapType_HAR         = 256
713         ,MapType_RAYMIRR     = 512
714         ,MapType_TRANSLU     = 1024
715         ,MapType_AMB         = 2048
716         ,MapType_DISPLACE    = 4096
717         ,MapType_WARP        = 8192
718     };
719 
720     // short texco, maptoneg;
721     MapType mapto;
722 
723     BlendType blendtype;
724     boost::shared_ptr<Object> object;
725     boost::shared_ptr<Tex> tex;
726     char uvname[32];
727 
728     Projection projx,projy,projz;
729     char mapping;
730     float ofs[3], size[3], rot;
731 
732     int texflag;
733     short colormodel, pmapto, pmaptoneg;
734     //short normapspace, which_output;
735     //char brush_map_mode;
736     float r,g,b,k WARN;
737     //float def_var, rt;
738 
739     //float colfac, varfac;
740 
741     float norfac;
742     //float dispfac, warpfac;
743     float colspecfac, mirrfac, alphafac;
744     float difffac, specfac, emitfac, hardfac;
745     //float raymirrfac, translfac, ambfac;
746     //float colemitfac, colreflfac, coltransfac;
747     //float densfac, scatterfac, reflfac;
748 
749     //float timefac, lengthfac, clumpfac;
750     //float kinkfac, roughfac, padensfac;
751     //float lifefac, sizefac, ivelfac, pvelfac;
752     //float shadowfac;
753     //float zenupfac, zendownfac, blendfac;
754 };
755 
756 
757     }
758 }
759 #endif
760