~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/yafray/intern/yafray_Render.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//----------------------------------------------------------------------------------------------------
2
 
// YafRay XML export
 
2
// YafRay export
3
3
//
4
4
// For anyone else looking at this, this was designed for a tabspacing of 2 (YafRay/Jandro standard :)
5
5
//----------------------------------------------------------------------------------------------------
18
18
        dupliMtx_list.clear();
19
19
        dup_srcob.clear();
20
20
        objectData.clear();
 
21
        imagetex.clear();
 
22
        imgtex_shader.clear();
21
23
}
22
24
 
23
25
bool yafrayRender_t::exportScene()
30
32
        mainCamLens = 35.0;
31
33
        if (maincam_obj->type==OB_CAMERA) mainCamLens=((Camera*)maincam_obj->data)->lens;
32
34
 
33
 
        maxraydepth = 5;        // will be set to maximum depth used in blender materials
34
 
 
35
35
        // recreate the scene as object data, as well as sorting the material & textures, ignoring duplicates
36
36
        if (!getAllMatTexObs())
37
37
        {
40
40
                return false;
41
41
        }
42
42
 
43
 
        if(!initExport())
 
43
        if (!initExport())
44
44
        {
 
45
                G.afbreek = 1;
45
46
                clearAll();
46
47
                return false;
47
48
        }
58
59
        // clear for next call, before render to free some memory
59
60
        clearAll();
60
61
 
61
 
        if(!finishExport())
 
62
        if (!finishExport())
62
63
        {
63
64
                G.afbreek = 1;  //stop render and anim if doing so
64
65
                return false;
67
68
}
68
69
 
69
70
 
70
 
// find object by name in global scene (+'OB'!)
71
 
Object* yafrayRender_t::findObject(const char* name)
72
 
{
73
 
        Base* bs = (Base*)G.scene->base.first;
74
 
        while (bs) {
75
 
          Object* obj = bs->object;
76
 
                if (!strcmp(name, obj->id.name)) return obj;
77
 
                bs = bs->next;
78
 
        }
79
 
        return NULL;
80
 
}
81
 
 
82
71
// gets all unique face materials & textures,
83
72
// and sorts the facelist rejecting anything that is not a quad or tri,
84
73
// as well as associating them again with the original Object.
87
76
 
88
77
        VlakRen* vlr;
89
78
 
 
79
        // Blender does not include object which have total 0 alpha materials,
 
80
        // however, the objects might have been included in the dupliMtx list,
 
81
        // so this will cause a 'Duplilist non-empty...'  error after going through the renderlist.
 
82
        // To solve this, keep track of all render objects included sofar,
 
83
        // and remove from dupliMtx_list if object not found.
 
84
        // This should also help to solve some other yet undetected 'dupli..' errors,
 
85
        // but on the other hand that could also hide the real problem of course...
 
86
        map<string, Object*> renderobs;
 
87
 
90
88
        for (int i=0;i<R.totvlak;i++) {
91
89
 
92
90
                if ((i & 255)==0) vlr=R.blovl[i>>8]; else vlr++;
101
99
                        if (strlen(matr->id.name)==0)
102
100
                                used_materials["blender_default"] = matr;
103
101
                        else
104
 
                                used_materials[matr->id.name] = matr; // <-- full name to avoid name collision in yafray
105
 
                                //used_materials[matr->id.name+2] = matr;       // skip 'MA' id
 
102
                                used_materials[matr->id.name] = matr;
106
103
                        // textures, all active channels
107
 
                        for (int m=0;m<8;m++) {
 
104
                        for (int m=0;m<MAX_MTEX;m++) {
108
105
                                if (matr->septex & (1<<m)) continue;    // only active channels
109
106
                                MTex* mx = matr->mtex[m];
110
107
                                // if no mtex, ignore
114
111
                                if (tx==NULL) continue;
115
112
                                short txtp = tx->type;
116
113
                                // if texture type not available in yafray, ignore
117
 
                                if ((txtp!=TEX_STUCCI) &&
118
 
                                                (txtp!=TEX_CLOUDS) &&
119
 
                                                (txtp!=TEX_WOOD) &&
120
 
                                                (txtp!=TEX_MARBLE) &&
121
 
                                                (txtp!=TEX_IMAGE)) continue;
122
 
                                // in the case of an image texture, check that there is an actual image, otherwise ignore
123
 
                                if ((txtp & TEX_IMAGE) && (!tx->ima)) continue;
124
 
                                used_textures[tx->id.name] = make_pair(matr, mx); // <-- full name to avoid name collision in yafray
125
 
                                //used_textures[tx->id.name+2] = make_pair(matr, mx);
 
114
                                if ((txtp==0) ||
 
115
                                                (txtp==TEX_MAGIC) ||
 
116
                                                (txtp==TEX_PLUGIN) ||
 
117
                                                (txtp==TEX_ENVMAP)) continue;
 
118
                                // if texture is stucci, only export if 'nor' enabled
 
119
                                if ((txtp==TEX_STUCCI) && !((mx->mapto & MAP_NORM) || (mx->maptoneg & MAP_NORM))) continue;
 
120
                                // In the case of an image texture, check that there is an actual image, otherwise ignore.
 
121
                                // Stupid error was here (...if (txtp & TEX_IMAGE)...),
 
122
                                // which happened to work sofar, but not anymore with the extended texture support..
 
123
                                if ((txtp==TEX_IMAGE) && (!tx->ima)) continue;
 
124
                                used_textures[tx->id.name] = mx;
126
125
                        }
127
126
                }
128
127
 
129
 
                // make list of faces per object, ignore <3 vert faces, duplicate vertex sorting done later
130
 
                // make sure null object pointers are ignored
 
128
                // Make list of faces per object, ignore <3 vert faces, duplicate vertex sorting done later.
 
129
                // ignore null object pointers.
 
130
                // Also make list of facetexture images (material 'TexFace').
131
131
                if (vlr->ob) {
132
132
                        int nv = 0;     // number of vertices
133
133
                        if (vlr->v4) nv=4; else if (vlr->v3) nv=3;
134
 
                        if (nv) all_objects[vlr->ob].push_back(vlr);
135
 
                }
136
 
                //else cout << "WARNING: VlakRen struct with null obj.ptr!\n";
137
 
 
 
134
                        if (nv) {
 
135
                                renderobs[vlr->ob->id.name] = vlr->ob;
 
136
                                all_objects[vlr->ob].push_back(vlr);
 
137
                                if (vlr->tface) {
 
138
                                        Image* fc_img = (Image*)vlr->tface->tpage;
 
139
                                        if (fc_img) {
 
140
                                                Material* fmat = vlr->mat;
 
141
                                                // only save if TexFace enabled
 
142
                                                if (fmat && (fmat->mode & MA_FACETEXTURE)) imagetex[fc_img].insert(fmat);
 
143
                                        }
 
144
                                }
 
145
                        }
 
146
                }
 
147
 
 
148
        }
 
149
 
 
150
        // now remove any objects from dupliMtx_list which are not in the renderlist
 
151
        for (map<string, vector<float> >::iterator dL=dupliMtx_list.begin();
 
152
                                dL!=dupliMtx_list.end();++dL)
 
153
        {
 
154
                string ro_name = dL->first;
 
155
                if (renderobs.find(ro_name)==renderobs.end()) {
 
156
                        cout << "Object " << ro_name << " not in renderlist, removing from dupliMtx_list" << endl;
 
157
                        dL->second.clear();
 
158
                        dupliMtx_list.erase(ro_name);
 
159
                }
138
160
        }
139
161
 
140
162
        // in case dupliMtx_list not empty, make sure that there is at least one source object
151
173
 
152
174
                // if the name reference list is empty, return now, something was seriously wrong
153
175
                if (dup_srcob.empty()) {
154
 
                  // error() doesn't work to well, when switching from Blender to console at least, so use stdout instead
 
176
                        // error() doesn't work to well, when switching from Blender to console at least, so use stdout instead
155
177
                        cout << "ERROR: Duplilist non_empty, but no srcobs\n";
156
178
                        return false;
157
179
                }
166
188
{
167
189
        for (int i=0;i<4;i++)
168
190
                for (int j=0;j<4;j++)
169
 
                        dupliMtx_list[string(obj->id.name)].push_back(obj->obmat[i][j]);
 
191
                        dupliMtx_list[obj->id.name].push_back(obj->obmat[i][j]);
170
192
}
171
193
 
172
194
 
183
205
                // then save matrix of linked object in dupliMtx_list, using name of ORIGINAL object
184
206
                for (int i=0;i<4;i++)
185
207
                        for (int j=0;j<4;j++)
186
 
                                dupliMtx_list[string(orgob->id.name)].push_back(obj->obmat[i][j]);
 
208
                                dupliMtx_list[orgob->id.name].push_back(obj->obmat[i][j]);
187
209
                return true;
188
210
        }
189
211
        // object not known yet