Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Genrich <daniel.genrich@gmx.net>2009-08-20 04:33:59 +0400
committerDaniel Genrich <daniel.genrich@gmx.net>2009-08-20 04:33:59 +0400
commit286c2ca80be4ae46dc220ada2fcc5bf636d5ff49 (patch)
tree91492852f1b0f8d6bc70d8b88113325e218e7f9d /source/blender/editors
parentc21627e31b0e82f28e35af51cec681897285ff78 (diff)
Smoke:
* cache for low res (deactivating high res for now) * new way of view3d rendering of smoke (no longer 3 axes) -using 3dtexture now (introduced into gpu/intern) * introducing LZO and LZMA libs into extern (makefiles missing for now) * reducing memory usage after simulating for the frame ended (freeing temporary buffers) * splitting smoke into 2 modifier for the cache-sake (it cannot handle more than 1 cache on the same modifier-index) * no color on gui anymore * fixing non-power-of-2 resolutions (hopefully) * fixing select-deselect of domain drawing bug * fixing drawobject.c coding style (making Ton happy) ;-) HINT #1: If scons doesn't work -> cmakefiles are up-to-date, couldn't test scons (but i tried to mantain them, too) CODERS HINT #1: we really need a way to disable adding all modifiers through "Add Modifiers" dropdown! WARNING #1: before applying this commit, deactivate your SMOKE DOMAIN in your old files and save them then. You can open them then savely after that. WARNING #2: File and cache format of smoke can be changed, this is not final!
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/object/object_modifier.c7
-rw-r--r--source/blender/editors/space_buttons/buttons_context.c12
-rw-r--r--source/blender/editors/space_view3d/drawobject.c362
-rw-r--r--source/blender/editors/space_view3d/drawvolume.c304
-rw-r--r--source/blender/editors/space_view3d/view3d_intern.h3
5 files changed, 338 insertions, 350 deletions
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index 9983e24f2c9..16900d6d894 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -161,6 +161,13 @@ int ED_object_modifier_remove(ReportList *reports, Scene *scene, Object *ob, Mod
DAG_scene_sort(scene);
}
+ else if(md->type == eModifierType_Smoke) {
+ ModifierData *tmd = modifiers_findByType(ob, eModifierType_SmokeHR);
+ if(tmd) {
+ BLI_remlink(&ob->modifiers, tmd);
+ modifier_free(tmd);
+ }
+ }
BLI_remlink(&ob->modifiers, md);
modifier_free(md);
diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c
index 530500cfafa..994bb0010d8 100644
--- a/source/blender/editors/space_buttons/buttons_context.c
+++ b/source/blender/editors/space_buttons/buttons_context.c
@@ -553,7 +553,7 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
"world", "object", "mesh", "armature", "lattice", "curve",
"meta_ball", "lamp", "camera", "material", "material_slot",
"texture", "texture_slot", "bone", "edit_bone", "particle_system",
- "cloth", "soft_body", "fluid", "smoke", "collision", "brush", NULL};
+ "cloth", "soft_body", "fluid", "smoke", "smoke_hr", "collision", "brush", NULL};
CTX_data_dir_set(result, dir);
return 1;
@@ -697,6 +697,16 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
return 1;
}
}
+ else if(CTX_data_equals(member, "smoke_hr")) {
+ PointerRNA *ptr= get_pointer_type(path, &RNA_Object);
+
+ if(ptr && ptr->data) {
+ Object *ob= ptr->data;
+ ModifierData *md= modifiers_findByType(ob, eModifierType_SmokeHR);
+ CTX_data_pointer_set(result, &ob->id, &RNA_SmokeHRModifier, md);
+ return 1;
+ }
+ }
else if(CTX_data_equals(member, "collision")) {
PointerRNA *ptr= get_pointer_type(path, &RNA_Object);
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 466b55ba862..55565c83f5e 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -5309,356 +5309,20 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
}
/* draw code for smoke */
- if((md = modifiers_findByType(ob, eModifierType_Smoke)))
- {
- SmokeModifierData *smd = (SmokeModifierData *)md;
-
- // draw collision objects
- if((smd->type & MOD_SMOKE_TYPE_COLL) && smd->coll)
- {
- /*SmokeCollSettings *scs = smd->coll;
- if(scs->points)
- {
- size_t i;
-
- wmLoadMatrix(rv3d->viewmat);
-
- if(col || (ob->flag & SELECT)) cpack(0xFFFFFF);
- glDepthMask(GL_FALSE);
- glEnable(GL_BLEND);
-
-
- // glPointSize(3.0);
- bglBegin(GL_POINTS);
-
- for(i = 0; i < scs->numpoints; i++)
- {
- bglVertex3fv(&scs->points[3*i]);
- }
-
- bglEnd();
- glPointSize(1.0);
-
- wmMultMatrix(ob->obmat);
- glDisable(GL_BLEND);
- glDepthMask(GL_TRUE);
- if(col) cpack(col);
-
- }
- */
- }
-
- // only draw domains
- if(smd->domain && smd->domain->fluid)
- {
- int x, y, z, i;
- float viewnormal[3];
- int mainaxis[3] = {0,0,0};
- float align = 0, signed_align = 0;
- int max_textures = 0, counter_textures = 0;
- float *buffer = NULL;
- int res[3];
- float bigfactor = 1.0;
- int big = (smd->domain->flags & MOD_SMOKE_HIGHRES) && (smd->domain->viewsettings & MOD_SMOKE_VIEW_USEBIG);
- int new = 0;
- int have_lamp = 0;
-
- // GUI sent redraw event
- if(smd->domain->flags & MOD_SMOKE_VIEW_REDRAWNICE)
- {
- new = 1;
- smd->domain->flags &= ~MOD_SMOKE_VIEW_REDRAWNICE;
- }
-
- if(!big)
- {
- res[0] = smd->domain->res[0];
- res[1] = smd->domain->res[1];
- res[2] = smd->domain->res[2];
- }
- else
- {
- smoke_turbulence_get_res(smd->domain->wt, res);
- bigfactor = 1.0 / (smd->domain->amplify + 1);
- }
-
- wmLoadMatrix(rv3d->viewmat);
-
- if(col || (ob->flag & SELECT)) cpack(0xFFFFFF); /* for visibility, also while wpaint */
- glDepthMask(GL_FALSE);
- glEnable(GL_BLEND);
-
- // get view vector
- VECCOPY(viewnormal, rv3d->viewinv[2]);
- Normalize(viewnormal);
- for(i = 0; i < 3; i++)
- {
- if(ABS(viewnormal[i]) > align)
- {
- mainaxis[0] = i;
- align = ABS(viewnormal[i]);
- signed_align = viewnormal[i];
- }
- }
- mainaxis[1] = (mainaxis[0] + 1) % 3;
- mainaxis[2] = (mainaxis[0] + 2) % 3;
-
- if(!smd->domain->bind)
- {
- smd->domain->bind = MEM_callocN(sizeof(GLuint)*256, "Smoke_bind");
- if(big)
- smd->domain->viewsettings |= MOD_SMOKE_VIEW_CHANGETOBIG;
- new = 3;
- }
-
- // check if view axis / mode has been changed
- if(smd->domain->viewsettings)
- {
- if(big)
- {
- if(!(smd->domain->viewsettings & MOD_SMOKE_VIEW_BIG))
- new = 2;
- else if(!(smd->domain->viewsettings & MOD_SMOKE_VIEW_CHANGETOBIG))
- new = 1;
-
- smd->domain->viewsettings |= MOD_SMOKE_VIEW_CHANGETOBIG;
- }
- else
- {
- if(!(smd->domain->viewsettings & MOD_SMOKE_VIEW_SMALL))
- new = 2;
- else if(smd->domain->viewsettings & MOD_SMOKE_VIEW_CHANGETOBIG)
- new = 1;
-
- smd->domain->viewsettings &= ~MOD_SMOKE_VIEW_CHANGETOBIG;
- }
-
- if(!new)
- {
- if((mainaxis[0] == 0) && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_X))
- new = 1;
- else if((mainaxis[0] == 1) && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_Y))
- new = 1;
- else if((mainaxis[0] == 2) && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_Z))
- new = 1;
-
- // printf("check axis\n");
- }
- }
- else
- new = 3;
-
- if(new > 1)
- {
- float light[3] = {0.0,0.0,0.0}; // TODO: take real LAMP coordinates - dg
- Base *base_tmp = NULL;
-
- for(base_tmp = scene->base.first; base_tmp; base_tmp= base_tmp->next)
- {
- if(base_tmp->object->type == OB_LAMP)
- {
- Lamp *la = (Lamp *)base_tmp->object->data;
-
- if(la->type == LA_LOCAL)
- {
- VECCOPY(light, base_tmp->object->obmat[3]);
- have_lamp = 1;
- break;
- }
- }
- }
-
- if(!big && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_SMALL))
- {
- smoke_prepare_View(smd, light);
- // printf("prepared View!\n");
- }
- else if(big && !(smd->domain->viewsettings & MOD_SMOKE_VIEW_BIG))
- {
- smoke_prepare_bigView(smd, light);
- // printf("prepared bigView!\n");
- }
- }
-
- // printf("big: %d, new: %d\n", big, new);
-
- // only create buffer if we need to create new textures
- if(new)
- buffer = MEM_mallocN(sizeof(float)*res[mainaxis[1]]*res[mainaxis[2]]*4, "SmokeDrawBuffer");
-
- if(buffer || smd->domain->viewsettings)
- {
- int mod_texture = 0;
-
- // printf("if(buffer || smd->domain->viewsettings)\n");
-
- max_textures = (res[mainaxis[0]] > 256) ? 256 : res[mainaxis[0]];
-
- if(!smd->domain->viewsettings) // new frame or new start
- {
- smd->domain->max_textures = max_textures;
- glGenTextures(smd->domain->max_textures, (GLuint *)smd->domain->bind);
- new = 1;
- // printf("glGenTextures\n");
- }
- else
- {
- if(new)
- {
- // printf("glDeleteTextures\n");
- glDeleteTextures(smd->domain->max_textures, (GLuint *)smd->domain->bind);
- smd->domain->max_textures = max_textures;
- glGenTextures(smd->domain->max_textures, (GLuint *)smd->domain->bind);
- }
- }
-
- mod_texture = MAX3(1, smd->domain->visibility, (int)(res[mainaxis[0]] / smd->domain->max_textures ));
-
- // align order of billboards to be front or backview (e.g. +x or -x axis)
- if(signed_align < 0)
- {
- z = res[mainaxis[0]] - 1;
- }
- else
- {
- z = 0;
- }
-
- for (; signed_align > 0 ? (z < res[mainaxis[0]]) : (z >= 0); signed_align > 0 ? z++ : z--) // 2
- {
- float quad[4][3];
-
- if(new)
- {
- for (y = 0; y < res[mainaxis[1]]; y++) // 1
- {
- for (x = 0; x < res[mainaxis[2]]; x++) // 0
- {
- size_t index;
- size_t image_index;
- float tray, tvox;
-
- image_index = smoke_get_index2d(y, res[mainaxis[1]], x);
-
- if(mainaxis[0] == 0)
- {
- // mainaxis[1] == 1, mainaxis[2] == 2
- index = smoke_get_index(z, res[mainaxis[0]], y, res[mainaxis[1]], x);
- }
- else if(mainaxis[0] == 1)
- {
- // mainaxis[1] == 2, mainaxis[2] == 0
- index = smoke_get_index(x, res[mainaxis[2]], z, res[mainaxis[0]], y);
- }
- else // mainaxis[0] == 2
- {
- // mainaxis[1] == 0, mainaxis[2] == 1
- index = smoke_get_index(y, res[mainaxis[1]], x, res[mainaxis[2]], z);
- }
-
- if(!big)
- {
- tvox = smoke_get_tvox(smd, index);
- tray = smoke_get_tray(smd, index);
- }
- else
- {
- tvox = smoke_get_bigtvox(smd, index);
- tray = smoke_get_bigtray(smd, index);
- }
-
- if(!have_lamp)
- tray = 1.0;
-
- // fill buffer with luminance and alpha
- // 1 - T_vox
- buffer[image_index*4 + 3] = 1.0 - tvox; // 0 = transparent => d.h. tvox = 1
-
- // L_vox = Omega * L_light * (1 - T_vox) * T_ray
- buffer[image_index*4] = buffer[image_index*4 + 1] = buffer[image_index*4 + 2] = smd->domain->omega * 1.0 * tvox * tray;
- }
- }
- }
- glBindTexture(GL_TEXTURE_2D, smd->domain->bind[counter_textures]);
- glEnable(GL_TEXTURE_2D);
-
- if(new)
- {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, res[mainaxis[1]], res[mainaxis[2]], 0, GL_RGBA, GL_FLOAT, buffer);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering
- }
-
- if((z % mod_texture) == 0 )
- {
- // botttom left
- quad[3][mainaxis[0]] = smd->domain->p0[mainaxis[0]] + z * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
- quad[3][mainaxis[1]] = smd->domain->p0[mainaxis[1]] + smd->domain->dx * bigfactor * 0.5;
- quad[3][mainaxis[2]] = smd->domain->p0[mainaxis[2]] + smd->domain->dx * bigfactor * 0.5;
-
- // top right
- quad[1][mainaxis[0]] = smd->domain->p0[mainaxis[0]] + z * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
- quad[1][mainaxis[1]] = smd->domain->p0[mainaxis[1]] + (res[mainaxis[1]] - 1) * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
- quad[1][mainaxis[2]] = smd->domain->p0[mainaxis[2]] + (res[mainaxis[2]] - 1) * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
-
- // top left
- quad[2][mainaxis[0]] = smd->domain->p0[mainaxis[0]] + z * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
- quad[2][mainaxis[1]] = smd->domain->p0[mainaxis[1]] + smd->domain->dx * bigfactor * 0.5;
- quad[2][mainaxis[2]] = smd->domain->p0[mainaxis[2]] + (res[mainaxis[2]] - 1) * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
-
- // bottom right
- quad[0][mainaxis[0]] = smd->domain->p0[mainaxis[0]] + z * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
- quad[0][mainaxis[1]] = smd->domain->p0[mainaxis[1]] + (res[mainaxis[1]] - 1) * smd->domain->dx * bigfactor + smd->domain->dx * bigfactor * 0.5;
- quad[0][mainaxis[2]] = smd->domain->p0[mainaxis[2]] + smd->domain->dx * bigfactor * 0.5;
-
- glBegin(GL_QUADS); // Start Drawing Quads
-
- glTexCoord2f(1.0f, 0.0f);
- glVertex3fv(quad[0]); // Left And Up 1 Unit (Top Left)
- glTexCoord2f(1.0f, 1.0f);
- glVertex3fv(quad[1]); // Right And Up 1 Unit (Top Right)
- glTexCoord2f(0.0f, 1.0f);
- glVertex3fv(quad[2]); // Right And Down One Unit (Bottom Right)
- glTexCoord2f(0.0f, 0.0f);
- glVertex3fv(quad[3]); // Left And Down One Unit (Bottom Left)
-
- glEnd();
- }
- counter_textures++;
- }
- }
- if(buffer)
- {
- MEM_freeN(buffer);
- buffer = NULL;
- }
-
- // set correct flag for viewsettings
- if(1)
- {
- // do not clear BIG/SMALL flag
- smd->domain->viewsettings &= ~MOD_SMOKE_VIEW_X;
- smd->domain->viewsettings &= ~MOD_SMOKE_VIEW_Y;
- smd->domain->viewsettings &= ~MOD_SMOKE_VIEW_Z;
-
- // set what caches we have
- if(big)
- smd->domain->viewsettings |= MOD_SMOKE_VIEW_BIG;
- else
- smd->domain->viewsettings |= MOD_SMOKE_VIEW_SMALL;
-
- if(mainaxis[0] == 0)
- smd->domain->viewsettings |= MOD_SMOKE_VIEW_X;
- else if(mainaxis[0] == 1)
- smd->domain->viewsettings |= MOD_SMOKE_VIEW_Y;
- else if(mainaxis[0] == 2)
- smd->domain->viewsettings |= MOD_SMOKE_VIEW_Z;
+ if(((SmokeHRModifierData *)(md = modifiers_findByType(ob, eModifierType_SmokeHR)) && (((SmokeHRModifierData *)md)->flags & MOD_SMOKE_SHOWHIGHRES))) {
+ // GPU_create_smoke(smd);
+ // draw_volume(scene, ar, v3d, base, smd->domain->tex, smd->domain->res);
+ // GPU_free_smoke(smd);
+ }
+ else {
+ md = modifiers_findByType(ob, eModifierType_Smoke);
+ if (md) {
+ SmokeModifierData *smd = (SmokeModifierData *)md;
+ if(smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) {
+ GPU_create_smoke(smd);
+ draw_volume(scene, ar, v3d, base, smd->domain->tex, smd->domain->res);
+ GPU_free_smoke(smd);
}
-
- wmMultMatrix(ob->obmat);
- glDisable(GL_BLEND);
- glDepthMask(GL_TRUE);
- if(col) cpack(col);
}
}
diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c
new file mode 100644
index 00000000000..221003360f4
--- /dev/null
+++ b/source/blender/editors/space_view3d/drawvolume.c
@@ -0,0 +1,304 @@
+/**
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * Contributor(s): Daniel Genrich
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+
+#include <string.h>
+#include <math.h>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "MEM_guardedalloc.h"
+
+#include "IMB_imbuf.h"
+
+
+#include "MTC_matrixops.h"
+
+#include "DNA_armature_types.h"
+#include "DNA_boid_types.h"
+#include "DNA_camera_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_constraint_types.h" // for drawing constraint
+#include "DNA_effect_types.h"
+#include "DNA_lamp_types.h"
+#include "DNA_lattice_types.h"
+#include "DNA_material_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_meta_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
+#include "DNA_object_force.h"
+#include "DNA_object_fluidsim.h"
+#include "DNA_particle_types.h"
+#include "DNA_space_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_smoke_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_world_types.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_arithb.h"
+#include "BLI_editVert.h"
+#include "BLI_edgehash.h"
+#include "BLI_rand.h"
+
+#include "BKE_anim.h" //for the where_on_path function
+#include "BKE_curve.h"
+#include "BKE_constraint.h" // for the get_constraint_target function
+#include "BKE_DerivedMesh.h"
+#include "BKE_deform.h"
+#include "BKE_displist.h"
+#include "BKE_effect.h"
+#include "BKE_font.h"
+#include "BKE_global.h"
+#include "BKE_image.h"
+#include "BKE_key.h"
+#include "BKE_lattice.h"
+#include "BKE_mesh.h"
+#include "BKE_material.h"
+#include "BKE_mball.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+#include "BKE_paint.h"
+#include "BKE_particle.h"
+#include "BKE_property.h"
+#include "BKE_smoke.h"
+#include "BKE_unit.h"
+#include "BKE_utildefines.h"
+#include "smoke_API.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "GPU_draw.h"
+#include "GPU_material.h"
+#include "GPU_extensions.h"
+
+#include "ED_mesh.h"
+#include "ED_particle.h"
+#include "ED_screen.h"
+#include "ED_types.h"
+#include "ED_util.h"
+
+#include "UI_resources.h"
+#include "UI_interface_icons.h"
+
+#include "WM_api.h"
+#include "BLF_api.h"
+
+#include "GPU_extensions.h"
+
+#include "view3d_intern.h" // own include
+
+struct GPUTexture;
+
+/* draw slices of smoke is adapted from c++ code authored by: Johannes Schmid and Ingemar Rask, 2006, johnny@grob.org */
+static float cv[][3] = {
+ {1.0f, 1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {1.0f, -1.0f, 1.0f},
+ {1.0f, 1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {1.0f, -1.0f, -1.0f}
+};
+
+// edges have the form edges[n][0][xyz] + t*edges[n][1][xyz]
+static float edges[12][2][3] = {
+ {{1.0f, 1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}},
+ {{-1.0f, 1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}},
+ {{-1.0f, -1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}},
+ {{1.0f, -1.0f, -1.0f}, {0.0f, 0.0f, 1.0f}},
+
+ {{1.0f, -1.0f, 1.0f}, {0.0f, 1.0f, 0.0f}},
+ {{-1.0f, -1.0f, 1.0f}, {0.0f, 1.0f, 0.0f}},
+ {{-1.0f, -1.0f, -1.0f}, {0.0f, 1.0f, 0.0f}},
+ {{1.0f, -1.0f, -1.0f}, {0.0f, 1.0f, 0.0f}},
+
+ {{-1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f}},
+ {{-1.0f, -1.0f, 1.0f}, {1.0f, 0.0f, 0.0f}},
+ {{-1.0f, -1.0f, -1.0f}, {1.0f, 0.0f, 0.0f}},
+ {{-1.0f, 1.0f, -1.0f}, {1.0f, 0.0f, 0.0f}}
+};
+
+int intersect_edges(float *points, float a, float b, float c, float d)
+{
+ int i;
+ float t;
+ int numpoints = 0;
+
+ for (i=0; i<12; i++) {
+ t = -(a*edges[i][0][0] + b*edges[i][0][1] + c*edges[i][0][2] + d)
+ / (a*edges[i][1][0] + b*edges[i][1][1] + c*edges[i][1][2]);
+ if ((t>0)&&(t<2)) {
+ points[numpoints * 3 + 0] = edges[i][0][0] + edges[i][1][0]*t;
+ points[numpoints * 3 + 1] = edges[i][0][1] + edges[i][1][1]*t;
+ points[numpoints * 3 + 2] = edges[i][0][2] + edges[i][1][2]*t;
+ numpoints++;
+ }
+ }
+ return numpoints;
+}
+
+static int convex(float *p0, float *up, float *a, float *b)
+{
+ // Vec3 va = a-p0, vb = b-p0;
+ float va[3], vb[3], tmp[3];
+ VECSUB(va, a, p0);
+ VECSUB(vb, b, p0);
+ Crossf(tmp, va, vb);
+ return INPR(up, tmp) >= 0;
+}
+
+// copied from gpu_extension.c
+static int is_pow2(int n)
+{
+ return ((n)&(n-1))==0;
+}
+
+static int larger_pow2(int n)
+{
+ if (is_pow2(n))
+ return n;
+
+ while(!is_pow2(n))
+ n= n&(n-1);
+
+ return n*2;
+}
+
+void draw_volume(Scene *scene, ARegion *ar, View3D *v3d, Base *base, GPUTexture *tex, int res[3])
+{
+ Object *ob = base->object;
+ RegionView3D *rv3d= ar->regiondata;
+
+ float viewnormal[3];
+ // int res[3];
+ int i, j, n;
+ float d, d0, dd;
+ float *points = NULL;
+ int numpoints = 0;
+ float cor[3] = {1.,1.,1.};
+
+ /*
+ res[0] = smd->domain->res[0];
+ res[1] = smd->domain->res[1];
+ res[2] = smd->domain->res[2];
+ */
+
+ wmLoadMatrix(rv3d->viewmat);
+
+ glDepthMask(GL_FALSE);
+ glEnable(GL_TEXTURE_3D);
+ glDisable(GL_DEPTH_TEST);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ // get view vector
+ VECCOPY(viewnormal, rv3d->viewinv[2]);
+ Normalize(viewnormal);
+
+ // find cube vertex that is closest to the viewer
+ for (i=0; i<8; i++) {
+ float x,y,z;
+
+ x = cv[i][0] + viewnormal[0];
+ y = cv[i][1] + viewnormal[1];
+ z = cv[i][2] + viewnormal[2];
+
+ if ((x>=-1.0f)&&(x<=1.0f)
+ &&(y>=-1.0f)&&(y<=1.0f)
+ &&(z>=-1.0f)&&(z<=1.0f)) {
+ break;
+ }
+ }
+
+ GPU_texture_bind(tex, 0);
+
+ cor[0] = (float)res[0]/(float)larger_pow2(res[0]);
+ cor[1] = (float)res[1]/(float)larger_pow2(res[1]);
+ cor[2] = (float)res[2]/(float)larger_pow2(res[2]);
+
+ // our slices are defined by the plane equation a*x + b*y +c*z + d = 0
+ // (a,b,c), the plane normal, are given by viewdir
+ // d is the parameter along the view direction. the first d is given by
+ // inserting previously found vertex into the plane equation
+ d0 = -(viewnormal[0]*cv[i][0] + viewnormal[1]*cv[i][1] + viewnormal[2]*cv[i][2]);
+ dd = 2.0*d0/64.0f;
+ n = 0;
+
+ // printf("d0: %f, dd: %f\n", d0, dd);
+
+ points = MEM_callocN(sizeof(float)*12*3, "smoke_points_preview");
+
+ for (d = d0; d > -d0; d -= dd) {
+ float p0[3];
+ // intersect_edges returns the intersection points of all cube edges with
+ // the given plane that lie within the cube
+ numpoints = intersect_edges(points, viewnormal[0], viewnormal[1], viewnormal[2], d);
+
+ if (numpoints > 2) {
+ VECCOPY(p0, points);
+
+ // sort points to get a convex polygon
+ for(i = 1; i < numpoints - 1; i++)
+ {
+ for(j = i + 1; j < numpoints; j++)
+ {
+ if(convex(p0, viewnormal, &points[j * 3], &points[i * 3]))
+ {
+ float tmp2[3];
+ VECCOPY(tmp2, &points[i * 3]);
+ VECCOPY(&points[i * 3], &points[j * 3]);
+ VECCOPY(&points[j * 3], tmp2);
+ }
+ }
+ }
+
+ glBegin(GL_POLYGON);
+ for (i = 0; i < numpoints; i++) {
+ glColor3f(1.0, 1.0, 1.0);
+ glTexCoord3d((points[i * 3 + 0] + 1.0)*cor[0]/2.0, (points[i * 3 + 1] + 1)*cor[1]/2.0, (points[i * 3 + 2] + 1.0)*cor[2]/2.0);
+ glVertex3f(points[i * 3 + 0], points[i * 3 + 1], points[i * 3 + 2]);
+ }
+ glEnd();
+ }
+ n++;
+ }
+
+ GPU_texture_unbind(tex);
+
+ MEM_freeN(points);
+
+ wmMultMatrix(ob->obmat);
+
+ glDisable(GL_TEXTURE_3D);
+ glDisable(GL_BLEND);
+ glEnable(GL_DEPTH_TEST);
+ glDepthMask(GL_TRUE);
+}
+
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index acd1c62bc17..e5e85cf9d16 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -156,6 +156,9 @@ void VIEW3D_OT_snap_menu(struct wmOperatorType *ot);
ARegion *view3d_has_buttons_region(ScrArea *sa);
ARegion *view3d_has_tools_region(ScrArea *sa);
+/* draw_volume.c */
+void draw_volume(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct Base *base, struct GPUTexture *tex, int res[3]);
+
#endif /* ED_VIEW3D_INTERN_H */