[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21208] branches/soc-2009-yukishiro/source /blender: fix crash after applying modifiers
Jingyuan Huang
jingyuan.huang at gmail.com
Sun Jun 28 05:01:13 CEST 2009
Revision: 21208
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21208
Author: yukishiro
Date: 2009-06-28 05:01:08 +0200 (Sun, 28 Jun 2009)
Log Message:
-----------
fix crash after applying modifiers
Modified Paths:
--------------
branches/soc-2009-yukishiro/source/blender/editors/interface/interface_templates.c
branches/soc-2009-yukishiro/source/blender/sh/SH_api.h
branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c
Modified: branches/soc-2009-yukishiro/source/blender/editors/interface/interface_templates.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/editors/interface/interface_templates.c 2009-06-28 02:47:49 UTC (rev 21207)
+++ branches/soc-2009-yukishiro/source/blender/editors/interface/interface_templates.c 2009-06-28 03:01:08 UTC (rev 21208)
@@ -406,6 +406,8 @@
BKE_reports_init(&reports, RPT_STORE);
if(ED_object_modifier_apply(&reports, scene, obv, mdv)) {
+ SH_computeMeshCoefficients(scene, ob);
+
WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
Modified: branches/soc-2009-yukishiro/source/blender/sh/SH_api.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/SH_api.h 2009-06-28 02:47:49 UTC (rev 21207)
+++ branches/soc-2009-yukishiro/source/blender/sh/SH_api.h 2009-06-28 03:01:08 UTC (rev 21208)
@@ -29,8 +29,8 @@
#ifndef _SH_API_H
#define _SH_API_H
+struct Object;
struct Scene;
-struct View3D;
struct LightEnv;
struct ImBuf;
@@ -39,6 +39,7 @@
void SH_computeSceneCoefficients(struct Scene *scene, unsigned int customdata_mask,
short compute_shadow, short recompute);
+void SH_computeMeshCoefficients(struct Object *ob, int compute_shadow);
void SH_computeLightCoefficients(struct LightEnv *env);
void SH_rotateLightEnv(struct LightEnv *env, float quat[4]);
Modified: branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c 2009-06-28 02:47:49 UTC (rev 21207)
+++ branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c 2009-06-28 03:01:08 UTC (rev 21208)
@@ -635,7 +635,46 @@
}
}
+void SH_computeMeshCoefficients(Scene *scene, Object *ob)
+{
+ Mesh *me= NULL;
+ MShCoeffs *coeffs= NULL;
+ MVert* verts= NULL;
+ LightEnv* env=scene->lightenv;
+ int i, k, m;
+ float N, *y_val;
+ int num_sh= (env->degree + 1) * (env->degree + 1);
+ float weight= 4.0f/(float)NUM_SAMPLES;
+
+ me = get_mesh(ob);
+ if (me == NULL) return;
+
+ coeffs= CustomData_get_layer(&me->vdata, CD_MSHCOEFFS);
+ if (coeffs == NULL) {
+ coeffs= MEM_callocN(sizeof(MShCoeffs) * me->totvert, "sh coeffs");
+ CustomData_add_layer(&me->vdata, CD_MSHCOEFFS, CD_ASSIGN, coeffs, me->totvert);
+ }
+
+ for (i = 0; i < me->totvert; i++) {
+ for (k = 0; k < NUM_SAMPLES; k++) {
+ N = (samples[k][0] * me->mvert[i].no[0] +
+ samples[k][1] * me->mvert[i].no[1] +
+ samples[k][2] * me->mvert[i].no[2]) / 32767.0;
+
+ if (N > 0) {
+ y_val = *(samples_Y[k]);
+ for (m = 0; m < num_sh; m++) {
+ coeffs[i].val[m] += N * y_val[m];
+ }
+ }
+ }
+ for (m = 0; m < num_sh; m++) {
+ coeffs[i].val[m] *= weight;
+ }
+ }
+}
+
void SH_computeLightCoefficients(LightEnv *env)
{
int k, m, i, j;
More information about the Bf-blender-cvs
mailing list