diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2011-11-13 16:17:27 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2011-11-13 16:17:27 +0400 |
commit | 11c83d843206648a33bcc8b4d754577ec0a51d2a (patch) | |
tree | 58af33c372ba5d77f68d6ed7b37e5aecd6e6c678 /source/blender/makesrna | |
parent | b1019a56b54294fc91293c5c43ef46d54950ae84 (diff) |
Ocean Sim modifier patch
by Matt Ebb, Hamed Zaghaghi
This adds a new Modifier "Ocean" to simulate large-scale wave motion.
Details can be found in the wiki documentation [1], the project homepage [2] and the patch tracker [3]
The modifier is disabled by default for now. To enable it, the WITH_OCEANSIM (cmake) / WITH_BF_OCEANSIM (scons) flags have to be set. The code depends on fftw3, so this also has to be enabled.
[1]
http://wiki.blender.org/index.php/Doc:2.6/Manual/Modifiers/Simulation/Ocean
[2]
http://www.savetheoceansim.com
[3]
http://projects.blender.org/tracker/?group_id=9&atid=127&func=detail&aid=28338
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/SConscript | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/CMakeLists.txt | 4 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_modifier.c | 230 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_texture.c | 52 |
5 files changed, 292 insertions, 0 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index c9dadce0a5e..08e3d1a72a2 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -348,6 +348,9 @@ extern StructRNA RNA_NorController; extern StructRNA RNA_Object; extern StructRNA RNA_ObjectBase; extern StructRNA RNA_ObstacleFluidSettings; +extern StructRNA RNA_OceanModifier; +extern StructRNA RNA_OceanTexData; +extern StructRNA RNA_OceanTexture; extern StructRNA RNA_Operator; extern StructRNA RNA_OperatorFileListElement; extern StructRNA RNA_OperatorMousePath; diff --git a/source/blender/makesrna/SConscript b/source/blender/makesrna/SConscript index 769ec880a65..9eea6d83cb9 100644 --- a/source/blender/makesrna/SConscript +++ b/source/blender/makesrna/SConscript @@ -55,6 +55,9 @@ if env['WITH_BF_PYTHON']: if env['WITH_BF_COLLADA']: defs.append('WITH_COLLADA') +if env['WITH_BF_OCEANSIM']: + defs.append('WITH_OCEANSIM') + if env['OURPLATFORM'] == 'linux': cflags='-pthread' incs += ' ../../../extern/binreloc/include' diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index 9bc532afa11..e50617f220c 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -206,6 +206,10 @@ if(WITH_FFTW3) add_definitions(-DWITH_FFTW3) endif() +if(WITH_OCEANSIM) + add_definitions(-DWITH_OCEANSIM) +endif() + if(WITH_SDL) add_definitions(-DWITH_SDL) endif() diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 32665bef065..aed5ba8840b 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -96,6 +96,7 @@ EnumPropertyItem modifier_type_items[] ={ {eModifierType_Softbody, "SOFT_BODY", ICON_MOD_SOFT, "Soft Body", ""}, {eModifierType_Surface, "SURFACE", ICON_MOD_PHYSICS, "Surface", ""}, {eModifierType_DynamicPaint, "DYNAMIC_PAINT", ICON_MOD_DYNAMICPAINT, "Dynamic Paint", ""}, + {eModifierType_Ocean, "OCEAN", ICON_MOD_WAVE, "Ocean", ""}, {0, NULL, 0, NULL, NULL}}; #ifdef RNA_RUNTIME @@ -186,6 +187,8 @@ static StructRNA* rna_Modifier_refine(struct PointerRNA *ptr) return &RNA_SolidifyModifier; case eModifierType_Screw: return &RNA_ScrewModifier; + case eModifierType_Ocean: + return &RNA_OceanModifier; case eModifierType_Warp: return &RNA_WarpModifier; case eModifierType_WeightVGEdit: @@ -649,6 +652,57 @@ static void rna_UVProjectModifier_num_projectors_set(PointerRNA *ptr, int value) md->projectors[a]= NULL; } +static int rna_OceanModifier_build_enabled_get(PointerRNA *UNUSED(ptr)) +{ + #ifdef WITH_OCEANSIM + return 1; + #else // WITH_OCEANSIM + return 0; + #endif // WITH_OCEANSIM +} + +static void rna_OceanModifier_init_update(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + OceanModifierData *omd= (OceanModifierData*)ptr->data; + + omd->refresh |= (MOD_OCEAN_REFRESH_RESET|MOD_OCEAN_REFRESH_SIM|MOD_OCEAN_REFRESH_CLEAR_CACHE); + + rna_Modifier_update(bmain, scene, ptr); +} + +static void rna_OceanModifier_sim_update(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + OceanModifierData *omd= (OceanModifierData*)ptr->data; + + omd->refresh |= MOD_OCEAN_REFRESH_SIM; + + rna_Modifier_update(bmain, scene, ptr); +} + +static void rna_OceanModifier_topology_update(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + OceanModifierData *omd= (OceanModifierData*)ptr->data; + + omd->refresh |= MOD_OCEAN_REFRESH_TOPOLOGY; + + rna_Modifier_update(bmain, scene, ptr); +} + +static void rna_OceanModifier_ocean_chop_set(PointerRNA *ptr, float value) +{ + OceanModifierData *omd= (OceanModifierData*)ptr->data; + float old_value = omd->chop_amount; + + omd->chop_amount = value; + + if ((old_value == 0.0 && value > 0.0) || + (old_value > 0.0 && value == 0.0)) + { + omd->refresh |= MOD_OCEAN_REFRESH_RESET; + omd->refresh |= MOD_OCEAN_REFRESH_CLEAR_CACHE; + } +} + static float rna_EdgeSplitModifier_split_angle_get(PointerRNA *ptr) { EdgeSplitModifierData *md= (EdgeSplitModifierData*)ptr->data; @@ -2809,6 +2863,181 @@ static void rna_def_modifier_weightvgproximity(BlenderRNA *brna) rna_def_modifier_weightvg_mask(brna, srna); } +static void rna_def_modifier_ocean(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + static EnumPropertyItem geometry_items[]= { + {MOD_OCEAN_GEOM_GENERATE, "GENERATE", 0, "Generate", "Generates ocean surface geometry at the specified resolution"}, + {MOD_OCEAN_GEOM_DISPLACE, "DISPLACE", 0, "Displace", "Displaces existing geometry according to simulation"}, + //{MOD_OCEAN_GEOM_SIM_ONLY, "SIM_ONLY", 0, "Sim Only", "Leaves geometry unchanged, but still runs simulation (to be used from texture)"}, + {0, NULL, 0, NULL, NULL}}; + + srna= RNA_def_struct(brna, "OceanModifier", "Modifier"); + RNA_def_struct_ui_text(srna, "Ocean Modifier", "Simulate an ocean surface"); + RNA_def_struct_sdna(srna, "OceanModifierData"); + RNA_def_struct_ui_icon(srna, ICON_MOD_FLUIDSIM); + + /* General check if OceanSim modifier code is enabled */ + prop= RNA_def_property(srna, "build_enabled", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_funcs(prop, "rna_OceanModifier_build_enabled_get", NULL); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Build Enabled", "True if the OceanSim modifier is enabled in this build"); + + prop= RNA_def_property(srna, "geometry_mode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "geometry_mode"); + RNA_def_property_enum_items(prop, geometry_items); + RNA_def_property_ui_text(prop, "Geometry", "Method of modifying geometry"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop= RNA_def_property(srna, "size", PROP_FLOAT, PROP_UNSIGNED); + RNA_def_property_float_sdna(prop, NULL, "size"); + RNA_def_property_ui_text(prop, "Size", ""); + RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 0); + RNA_def_property_update(prop, 0, "rna_OceanModifier_topology_update"); + + prop= RNA_def_property(srna, "repeat_x", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_sdna(prop, NULL, "repeat_x"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_range(prop, 1, 1024); + RNA_def_property_ui_range(prop, 1, 100, 1, 0); + RNA_def_property_ui_text(prop, "Repeat X", "Repetitions of the generated surface in X"); + RNA_def_property_update(prop, 0, "rna_OceanModifier_topology_update"); + + prop= RNA_def_property(srna, "repeat_y", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_sdna(prop, NULL, "repeat_y"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_range(prop, 1, 1024); + RNA_def_property_ui_range(prop, 1, 100, 1, 0); + RNA_def_property_ui_text(prop, "Repeat Y", "Repetitions of the generated surface in Y"); + RNA_def_property_update(prop, 0, "rna_OceanModifier_topology_update"); + + prop= RNA_def_property(srna, "generate_normals", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_OCEAN_GENERATE_NORMALS); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Generate Normals", "Outputs normals for bump mapping - disabling can speed up performance if its not needed"); + RNA_def_property_update(prop, 0, "rna_OceanModifier_init_update"); + + prop= RNA_def_property(srna, "generate_foam", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_OCEAN_GENERATE_FOAM); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Generate Foam", "Generates foam mask as a vertex color channel"); + RNA_def_property_update(prop, 0, "rna_OceanModifier_init_update"); + + prop= RNA_def_property(srna, "resolution", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_sdna(prop, NULL, "resolution"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_range(prop, 1, 1024); + RNA_def_property_ui_range(prop, 1, 32, 1, 0); + RNA_def_property_ui_text(prop, "Resolution", "Resolution of the generated surface"); + RNA_def_property_update(prop, 0, "rna_OceanModifier_init_update"); + + prop= RNA_def_property(srna, "spatial_size", PROP_INT, PROP_DISTANCE); + RNA_def_property_int_sdna(prop, NULL, "spatial_size"); + RNA_def_property_ui_range(prop, 1, 512, 2, 0); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Spatial Size", "Physical size of the simulation domain (m)"); + RNA_def_property_update(prop, 0, "rna_OceanModifier_init_update"); + + prop= RNA_def_property(srna, "wind_velocity", PROP_FLOAT, PROP_VELOCITY); + RNA_def_property_float_sdna(prop, NULL, "wind_velocity"); + RNA_def_property_ui_text(prop, "Wind Velocity", "Wind speed (m/s)"); + RNA_def_property_update(prop, 0, "rna_OceanModifier_init_update"); + + prop= RNA_def_property(srna, "damp", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_float_sdna(prop, NULL, "damp"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Damping", "Damp reflected waves going in opposite direction to the wind"); + RNA_def_property_update(prop, 0, "rna_OceanModifier_init_update"); + + prop= RNA_def_property(srna, "smallest_wave", PROP_FLOAT, PROP_DISTANCE); + RNA_def_property_float_sdna(prop, NULL, "smallest_wave"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_range(prop, 0.0, FLT_MAX); + RNA_def_property_ui_text(prop, "Smallest Wave", "Shortest allowed wavelength (m)"); + RNA_def_property_update(prop, 0, "rna_OceanModifier_init_update"); + + prop= RNA_def_property(srna, "wave_alignment", PROP_FLOAT, PROP_UNSIGNED); + RNA_def_property_float_sdna(prop, NULL, "wave_alignment"); + RNA_def_property_range(prop, 0.0, 10.0); + RNA_def_property_ui_text(prop, "Wave Alignment", ""); + RNA_def_property_update(prop, 0, "rna_OceanModifier_init_update"); + + prop= RNA_def_property(srna, "wave_direction", PROP_FLOAT, PROP_ANGLE); + RNA_def_property_float_sdna(prop, NULL, "wave_direction"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Wave Direction", ""); + RNA_def_property_update(prop, 0, "rna_OceanModifier_init_update"); + + prop= RNA_def_property(srna, "wave_scale", PROP_FLOAT, PROP_UNSIGNED); + RNA_def_property_float_sdna(prop, NULL, "wave_scale"); + RNA_def_property_ui_text(prop, "Wave Scale", ""); + RNA_def_property_update(prop, 0, "rna_OceanModifier_sim_update"); + + prop= RNA_def_property(srna, "depth", PROP_FLOAT, PROP_UNSIGNED); + RNA_def_property_float_sdna(prop, NULL, "depth"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Depth", ""); + RNA_def_property_ui_range(prop, 0, 250, 1, 0); + RNA_def_property_update(prop, 0, "rna_OceanModifier_init_update"); + + prop= RNA_def_property(srna, "foam_coverage", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "foam_coverage"); + RNA_def_property_ui_text(prop, "Foam Coverage", ""); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + + prop= RNA_def_property(srna, "bake_foam_fade", PROP_FLOAT, PROP_UNSIGNED); + RNA_def_property_float_sdna(prop, NULL, "foam_fade"); + RNA_def_property_ui_text(prop, "Foam Fade", ""); + RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 0); + RNA_def_property_update(prop, 0, NULL); + + prop= RNA_def_property(srna, "choppiness", PROP_FLOAT, PROP_UNSIGNED); + RNA_def_property_float_sdna(prop, NULL, "chop_amount"); + RNA_def_property_ui_text(prop, "Choppiness", ""); + RNA_def_property_ui_range(prop, 0.0, 4.0, 3, 0); + RNA_def_property_float_funcs(prop, NULL, "rna_OceanModifier_ocean_chop_set", NULL); + RNA_def_property_update(prop, 0, "rna_OceanModifier_sim_update"); + + prop= RNA_def_property(srna, "time", PROP_FLOAT, PROP_UNSIGNED); + RNA_def_property_float_sdna(prop, NULL, "time"); + RNA_def_property_ui_text(prop, "Time", ""); + RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 0); + RNA_def_property_update(prop, 0, "rna_OceanModifier_sim_update"); + + prop= RNA_def_property(srna, "random_seed", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_sdna(prop, NULL, "seed"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Random Seed", ""); + RNA_def_property_update(prop, 0, "rna_OceanModifier_init_update"); + + prop= RNA_def_property(srna, "bake_start", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_sdna(prop, NULL, "bakestart"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Bake Start", ""); + RNA_def_property_update(prop, 0, "rna_OceanModifier_init_update"); + + prop= RNA_def_property(srna, "bake_end", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_sdna(prop, NULL, "bakeend"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Bake End", ""); + RNA_def_property_update(prop, 0, "rna_OceanModifier_init_update"); + + prop= RNA_def_property(srna, "is_cached", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "cached", 1); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Ocean is Cached", "Whether the ocean is useing cached data or simulating"); + + + prop= RNA_def_property(srna, "cachepath", PROP_STRING, PROP_DIRPATH); + RNA_def_property_string_sdna(prop, NULL, "cachepath"); + RNA_def_property_ui_text(prop, "Cache Path", "Path to a folder to store external baked images"); + //RNA_def_property_update(prop, 0, "rna_Modifier_update"); + // XXX how to update? +} + + void RNA_def_modifier(BlenderRNA *brna) { StructRNA *srna; @@ -2910,6 +3139,7 @@ void RNA_def_modifier(BlenderRNA *brna) rna_def_modifier_weightvgmix(brna); rna_def_modifier_weightvgproximity(brna); rna_def_modifier_dynamic_paint(brna); + rna_def_modifier_ocean(brna); } #endif diff --git a/source/blender/makesrna/intern/rna_texture.c b/source/blender/makesrna/intern/rna_texture.c index aac4da9e6f6..249bdb4a366 100644 --- a/source/blender/makesrna/intern/rna_texture.c +++ b/source/blender/makesrna/intern/rna_texture.c @@ -73,6 +73,7 @@ EnumPropertyItem texture_type_items[] = { {TEX_VORONOI, "VORONOI", ICON_TEXTURE, "Voronoi", "Procedural - Create cell-like patterns based on Worley noise"}, {TEX_VOXELDATA, "VOXEL_DATA", ICON_TEXTURE, "Voxel Data", "Create a 3d texture based on volumetric data"}, {TEX_WOOD, "WOOD", ICON_TEXTURE, "Wood", "Procedural - Wave generated bands or rings, with optional noise"}, + {TEX_OCEAN, "OCEAN", ICON_TEXTURE, "Ocean", ""}, {0, NULL, 0, NULL, NULL}}; EnumPropertyItem blend_type_items[] = { @@ -145,6 +146,8 @@ static StructRNA *rna_Texture_refine(struct PointerRNA *ptr) return &RNA_VoxelDataTexture; case TEX_WOOD: return &RNA_WoodTexture; + case TEX_OCEAN: + return &RNA_OceanTexture; default: return &RNA_Texture; } @@ -435,6 +438,11 @@ static char *rna_VoxelData_path(PointerRNA *UNUSED(ptr)) return BLI_sprintfN("voxel_data"); } +static char *rna_OceanTex_path(PointerRNA *ptr) +{ + return BLI_sprintfN("ocean"); +} + #else static void rna_def_texmapping(BlenderRNA *brna) @@ -1860,6 +1868,49 @@ static void rna_def_texture_voxeldata(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Texture_voxeldata_update"); } +static void rna_def_texture_ocean(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + static EnumPropertyItem ocean_output_items[] = { + {TEX_OCN_DISPLACEMENT, "DISPLACEMENT", 0, "Displacement", "Outputs XYZ displacement in RGB channels"}, + //{TEX_OCN_NORMALS, "NORMALS", 0, "Normals", "Outputs wave normals"}, // these are in nor channel now + {TEX_OCN_FOAM, "FOAM", 0, "Foam", "Outputs Foam (wave overlap) amount in single channel"}, + {TEX_OCN_JPLUS, "JPLUS", 0, "Eigenvalues", "Positive Eigenvalues"}, + {TEX_OCN_EMINUS, "EMINUS", 0, "Eigenvectors (-)", "Negative Eigenvectors"}, + {TEX_OCN_EPLUS, "EPLUS", 0, "Eigenvectors (+)", "Positive Eigenvectors"}, + {0, NULL, 0, NULL, NULL}}; + + srna= RNA_def_struct(brna, "OceanTexData", NULL); + RNA_def_struct_sdna(srna, "OceanTex"); + RNA_def_struct_ui_text(srna, "Ocean", "Ocean Texture settings"); + RNA_def_struct_path_func(srna, "rna_OceanTex_path"); + + prop= RNA_def_property(srna, "output", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "output"); + RNA_def_property_enum_items(prop, ocean_output_items); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Output", "The data that is output by the texture"); + RNA_def_property_update(prop, 0, "rna_Texture_update"); + + prop= RNA_def_property(srna, "ocean_object", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "object"); + RNA_def_property_ui_text(prop, "Modifier Object", "Object containing the ocean modifier"); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_update(prop, 0, "rna_Texture_update"); + + srna= RNA_def_struct(brna, "OceanTexture", "Texture"); + RNA_def_struct_sdna(srna, "Tex"); + RNA_def_struct_ui_text(srna, "Ocean", "Settings for the Ocean texture"); + + prop= RNA_def_property(srna, "ocean", PROP_POINTER, PROP_NONE); + RNA_def_property_pointer_sdna(prop, NULL, "ot"); + RNA_def_property_struct_type(prop, "OceanTexData"); + RNA_def_property_ui_text(prop, "Ocean", "The ocean data associated with this texture"); + RNA_def_property_update(prop, 0, "rna_Texture_update"); +} + static void rna_def_texture(BlenderRNA *brna) { StructRNA *srna; @@ -1962,6 +2013,7 @@ static void rna_def_texture(BlenderRNA *brna) rna_def_texture_distorted_noise(brna); rna_def_texture_pointdensity(brna); rna_def_texture_voxeldata(brna); + rna_def_texture_ocean(brna); /* XXX add more types here .. */ RNA_api_texture(srna); |