View3D: disable LOD when game engine is disabled or ifdef'd

This commit is contained in:
Campbell Barton 2014-04-09 11:48:04 +10:00
parent b1f97a0cdb
commit 9de24c82ba
10 changed files with 67 additions and 20 deletions

View File

@ -92,7 +92,7 @@ void *BKE_object_obdata_add_from_type(struct Main *bmain, int type);
void BKE_object_lod_add(struct Object *ob);
void BKE_object_lod_sort(struct Object *ob);
bool BKE_object_lod_remove(struct Object *ob, int level);
bool BKE_object_lod_update(struct Object *ob, float camera_position[3]);
void BKE_object_lod_update(struct Object *ob, const float camera_position[3]);
bool BKE_object_lod_is_usable(struct Object *ob, struct Scene *scene);
struct Object *BKE_object_lod_meshob_get(struct Object *ob, struct Scene *scene);
struct Object *BKE_object_lod_matob_get(struct Object *ob, struct Scene *scene);

View File

@ -1049,6 +1049,9 @@ Object *BKE_object_add(Main *bmain, Scene *scene, int type)
return ob;
}
#ifdef WITH_GAMEENGINE
void BKE_object_lod_add(Object *ob)
{
LodLevel *lod = MEM_callocN(sizeof(LodLevel), "LoD Level");
@ -1110,21 +1113,19 @@ bool BKE_object_lod_remove(Object *ob, int level)
return true;
}
static LodLevel *lod_level_select(Object *ob, const float cam_loc[3])
static LodLevel *lod_level_select(Object *ob, const float camera_position[3])
{
LodLevel *current = ob->currentlod;
float ob_loc[3], delta[3];
float dist_sq;
float dist_sq, dist_sq_curr;
if (!current) return NULL;
copy_v3_v3(ob_loc, ob->obmat[3]);
sub_v3_v3v3(delta, ob_loc, cam_loc);
dist_sq = len_squared_v3(delta);
dist_sq = len_squared_v3v3(ob->obmat[3], camera_position);
dist_sq_curr = current->distance * current->distance;
if (dist_sq < current->distance * current->distance) {
if (dist_sq < dist_sq_curr) {
/* check for higher LoD */
while (current->prev && dist_sq < (current->distance * current->distance)) {
while (current->prev && dist_sq < dist_sq_curr) {
current = current->prev;
}
}
@ -1144,17 +1145,14 @@ bool BKE_object_lod_is_usable(Object *ob, Scene *scene)
return (ob->mode == OB_MODE_OBJECT || !active);
}
bool BKE_object_lod_update(Object *ob, float camera_position[3])
void BKE_object_lod_update(Object *ob, const float camera_position[3])
{
LodLevel *cur_level = ob->currentlod;
LodLevel *new_level = lod_level_select(ob, camera_position);
if (new_level != cur_level) {
ob->currentlod = new_level;
return true;
}
return false;
}
static Object *lod_ob_get(Object *ob, Scene *scene, int flag)
@ -1181,6 +1179,9 @@ struct Object *BKE_object_lod_matob_get(Object *ob, Scene *scene)
return lod_ob_get(ob, scene, OB_LOD_USE_MAT);
}
#endif /* WITH_GAMEENGINE */
SoftBody *copy_softbody(SoftBody *sb, bool copy_caches)
{
SoftBody *sbn;

View File

@ -51,7 +51,13 @@
static int object_lod_add_exec(bContext *C, wmOperator *UNUSED(op))
{
Object *ob = ED_object_context(C);
#ifdef WITH_GAMEENGINE
BKE_object_lod_add(ob);
#else
(void)ob;
#endif
return OPERATOR_FINISHED;
}
@ -75,8 +81,13 @@ static int object_lod_remove_exec(bContext *C, wmOperator *op)
Object *ob = ED_object_context(C);
int index = RNA_int_get(op->ptr, "index");
#ifdef WITH_GAMEENGINE
if (!BKE_object_lod_remove(ob, index))
return OPERATOR_CANCELLED;
#else
(void)ob;
(void)index;
#endif
WM_event_add_notifier(C, NC_OBJECT | ND_LOD, CTX_wm_view3d(C));
return OPERATOR_FINISHED;

View File

@ -3406,7 +3406,11 @@ static void draw_mesh_object_outline(View3D *v3d, Object *ob, DerivedMesh *dm)
static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, Base *base,
const char dt, const unsigned char ob_wire_col[4], const short dflag)
{
Object *ob = BKE_object_lod_meshob_get(base->object, scene);
#ifdef WITH_GAMEENGINE
Object *ob = (rv3d->rflag & RV3D_IS_GAME_ENGINE) ? BKE_object_lod_meshob_get(base->object, scene) : base->object;
#else
Object *ob = base->object;
#endif
Mesh *me = ob->data;
Material *ma = give_current_material(ob, 1);
const bool hasHaloMat = (ma && (ma->material_type == MA_TYPE_HALO) && !BKE_scene_use_new_shading_nodes(scene));

View File

@ -1992,8 +1992,12 @@ static void draw_dupli_objects_color(Scene *scene, ARegion *ar, View3D *v3d, Bas
copy_m4_m4(savedobmat, dob->ob->obmat);
copy_m4_m4(dob->ob->obmat, dob->mat);
savedlod = dob->ob->currentlod;
BKE_object_lod_update(dob->ob, rv3d->viewinv[3]);
#ifdef WITH_GAMEENGINE
if (rv3d->rflag & RV3D_IS_GAME_ENGINE) {
BKE_object_lod_update(dob->ob, rv3d->viewinv[3]);
}
#endif
/* extra service: draw the duplicator in drawtype of parent, minimum taken
* to allow e.g. boundbox box objects in groups for LOD */
@ -3208,6 +3212,8 @@ static void view3d_main_area_clear(Scene *scene, View3D *v3d, ARegion *ar)
}
}
#ifdef WITH_GAMEENGINE
static void update_lods(Scene *scene, float camera_pos[3])
{
Scene *sce_iter;
@ -3219,6 +3225,8 @@ static void update_lods(Scene *scene, float camera_pos[3])
BKE_object_lod_update(ob, camera_pos);
}
}
#endif
/* warning: this function has duplicate drawing in ED_view3d_draw_offscreen() */
static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const char **grid_unit)
@ -3242,8 +3250,15 @@ static void view3d_main_area_draw_objects(const bContext *C, ARegion *ar, const
/* setup view matrices */
view3d_main_area_setup_view(scene, v3d, ar, NULL, NULL);
/* Make sure LoDs are up to date */
update_lods(scene, rv3d->viewinv[3]);
rv3d->rflag &= ~RV3D_IS_GAME_ENGINE;
#ifdef WITH_GAMEENGINE
if (STREQ(scene->r.engine, "BLENDER_GAME")) {
rv3d->rflag |= RV3D_IS_GAME_ENGINE;
/* Make sure LoDs are up to date */
update_lods(scene, rv3d->viewinv[3]);
}
#endif
/* clear the background */
view3d_main_area_clear(scene, v3d, ar);

View File

@ -69,6 +69,10 @@ data_to_c_simple(shaders/gpu_shader_vertex.glsl SRC)
data_to_c_simple(shaders/gpu_shader_vsm_store_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_vsm_store_vert.glsl SRC)
if(WITH_GAMEENGINE)
add_definitions(-DWITH_GAMEENGINE)
endif()
if(WITH_MOD_SMOKE)
add_definitions(-DWITH_SMOKE)
endif()

View File

@ -49,6 +49,8 @@ incs = [
env['BF_OPENGL_INC'],
]
if env['WITH_BF_GAMEENGINE']:
defs.append('WITH_GAMEENGINE')
if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc', 'win64-mingw'):
incs.append(env['BF_PTHREADS_INC'])

View File

@ -1403,8 +1403,12 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O
const bool new_shading_nodes = BKE_scene_use_new_shading_nodes(scene);
const bool use_matcap = (v3d->flag2 & V3D_SHOW_SOLID_MATCAP) != 0; /* assumes v3d->defmaterial->preview is set */
ob = BKE_object_lod_matob_get(ob, scene);
#ifdef WITH_GAMEENGINE
if (rv3d->rflag & RV3D_IS_GAME_ENGINE) {
ob = BKE_object_lod_matob_get(ob, scene);
}
#endif
/* initialize state */
memset(&GMS, 0, sizeof(GMS));
GMS.lastmatnr = -1;

View File

@ -247,6 +247,7 @@ typedef struct View3D {
#define RV3D_CLIPPING 4
#define RV3D_NAVIGATING 8
#define RV3D_GPULIGHT_UPDATE 16
#define RV3D_IS_GAME_ENGINE 32 /* runtime flag, used to check if LoD's should be used */
/* RegionView3d->viewlock */
#define RV3D_LOCKED (1 << 0)

View File

@ -1482,7 +1482,12 @@ int rna_Object_use_dynamic_topology_sculpting_get(PointerRNA *ptr)
static void rna_Object_lod_distance_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
Object *ob = (Object *)ptr->id.data;
#ifdef WITH_GAMEENGINE
BKE_object_lod_sort(ob);
#else
(void)ob;
#endif
}
#else